Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk-trace-base)!: remove addSpanProcessor API #5134

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG_NEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* refactor(resources)!: replace `ResourceAttributes` with `Attributes` [#5016](https://github.com/open-telemetry/opentelemetry-js/pull/5016) @david-luna
* feat(sdk-metrics)!: drop `View` and `Aggregation` in favor of `ViewOptions` and `AggregationOption` [#4931](https://github.com/open-telemetry/opentelemetry-js/pull/4931) @pichlermarc
* refactor(sdk-trace-base)!: remove `new Span` constructor in favor of `Tracer.startSpan` API [#5048](https://github.com/open-telemetry/opentelemetry-js/pull/5048) @david-luna
* refactor(sdk-trace-base)!: remove `BasicTracerProvider.addSpanProcessor` API in favor of constructor options. [#5134](https://github.com/open-telemetry/opentelemetry-js/pull/5134) @david-luna

### :rocket: (Enhancement)

Expand Down
5 changes: 3 additions & 2 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ const { trace } = require("@opentelemetry/api");
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require("@opentelemetry/sdk-trace-base");

// Create and register an SDK
const provider = new BasicTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
const provider = new BasicTracerProvider({
spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())]
});
trace.setGlobalTracerProvider(provider);

// Acquire a tracer from the global tracer provider which will be used to trace the application
Expand Down
15 changes: 8 additions & 7 deletions examples/basic-tracer-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-convention
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');

// Configure span processor to send spans to the exporter
const exporter = new JaegerExporter({
endpoint: 'http://localhost:14268/api/traces',
});
const provider = new BasicTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: 'basic-service',
}),
spanProcessors: [
new SimpleSpanProcessor(exporter),
new SimpleSpanProcessor(new ConsoleSpanExporter()),
]
});

// Configure span processor to send spans to the exporter
const exporter = new JaegerExporter({
endpoint: 'http://localhost:14268/api/traces',
});
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));

/**
* Initialize the OpenTelemetry APIs to use the BasicTracerProvider bindings.
*
Expand Down
7 changes: 4 additions & 3 deletions examples/esm-http-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
import http from 'http';

diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
const exporter = new ConsoleSpanExporter();
const processor = new SimpleSpanProcessor(exporter);

const tracerProvider = new NodeTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: 'esm-http-ts-example',
}),
spanProcessors: [processor],
});
const exporter = new ConsoleSpanExporter();
const processor = new SimpleSpanProcessor(exporter);
tracerProvider.addSpanProcessor(processor);
tracerProvider.register();

registerInstrumentations({
Expand Down
12 changes: 3 additions & 9 deletions examples/grpc-js/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@ const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc');
const EXPORTER = process.env.EXPORTER || '';

module.exports = (serviceName) => {
const useZipkin = EXPORTER.toLowerCase().startsWith('z');
const exporter = useZipkin ? new ZipkinExporter() : new JaegerExporter();
const provider = new NodeTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: serviceName,
}),
spanProcessors: [new SimpleSpanProcessor(exporter)]
});

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new ZipkinExporter();
} else {
exporter = new JaegerExporter();
}

provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();

Expand Down
14 changes: 4 additions & 10 deletions examples/http/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@ const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const EXPORTER = process.env.EXPORTER || '';

module.exports = (serviceName) => {
const useZipkin = EXPORTER.toLowerCase().startsWith('z');
const exporter = useZipkin ? new ZipkinExporter() : new JaegerExporter();
const provider = new NodeTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: serviceName,
}),
spanProcessors: [new SimpleSpanProcessor(exporter)]
});

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new ZipkinExporter();
} else {
exporter = new JaegerExporter();
}

provider.addSpanProcessor(new SimpleSpanProcessor(exporter));


// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();

Expand Down
13 changes: 3 additions & 10 deletions examples/https/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ const EXPORTER = process.env.EXPORTER || '';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

module.exports = (serviceName) => {
let exporter;
const useZipkin = EXPORTER.toLowerCase().startsWith('z');
const exporter = useZipkin ? new ZipkinExporter() : new JaegerExporter();
const provider = new NodeTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: serviceName,
}),
spanProcessors: [new SimpleSpanProcessor(exporter)]
});

if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new ZipkinExporter();
} else {
exporter = new JaegerExporter();
}

provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();

Expand Down
17 changes: 8 additions & 9 deletions examples/opentelemetry-web/examples/fetch-proto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ const { SEMRESATTRS_SERVICE_NAME } = require("@opentelemetry/semantic-convention
const provider = new WebTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: 'fetch-proto-web-service'
})
}),
// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
spanProcessors: [
new SimpleSpanProcessor(new ConsoleSpanExporter()),
new SimpleSpanProcessor(new OTLPTraceExporterProto()),
]
});

// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(
new SimpleSpanProcessor(new OTLPTraceExporterProto())
);

provider.register({
contextManager: new ZoneContextManager(),
propagator: new B3Propagator(),
Expand Down
14 changes: 8 additions & 6 deletions examples/opentelemetry-web/examples/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-convention
const provider = new WebTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: 'fetch-web-service'
})
}),
// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
spanProcessors:[
new SimpleSpanProcessor(new ConsoleSpanExporter()),
new SimpleSpanProcessor(new OTLPTraceExporter()),
]
});

// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));
provider.register({
contextManager: new ZoneContextManager(),
propagator: new B3Propagator(),
Expand Down
14 changes: 8 additions & 6 deletions examples/opentelemetry-web/examples/fetchXhr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-convention
const provider = new WebTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: 'fetch-xhr-web-service'
})
}),
// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
spanProcessors: [
new SimpleSpanProcessor(new ConsoleSpanExporter()),
new SimpleSpanProcessor(new OTLPTraceExporter()),
]
});

// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));
provider.register({
contextManager: new ZoneContextManager(),
});
Expand Down
14 changes: 8 additions & 6 deletions examples/opentelemetry-web/examples/fetchXhrB3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-convention
const provider = new WebTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: 'fetch-xhr-b3-web-service'
})
}),
// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
spanProcessors: [
new SimpleSpanProcessor(new ConsoleSpanExporter()),
new SimpleSpanProcessor(new OTLPTraceExporter()),
]
});

// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));
provider.register({
contextManager: new ZoneContextManager(),
propagator: new B3Propagator(),
Expand Down
15 changes: 8 additions & 7 deletions examples/opentelemetry-web/examples/xml-http-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-convention
const providerWithZone = new WebTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: 'xml-http-web-service'
})
}),
// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
spanProcessors: [
new SimpleSpanProcessor(new ConsoleSpanExporter()),
new SimpleSpanProcessor(new OTLPTraceExporter()),
]
});

// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter()));

providerWithZone.register({
contextManager: new ZoneContextManager(),
propagator: new B3Propagator(),
Expand Down
26 changes: 15 additions & 11 deletions examples/opentelemetry-web/examples/zipkin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-convention
const provider = new WebTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: 'zipkin-web-service'
})
}),
// Note: For production consider using the "BatchSpanProcessor" to reduce the number of requests
// to your exporter. Using the SimpleSpanProcessor here as it sends the spans immediately to the
// exporter without delay
spanProcessors: [
new SimpleSpanProcessor(new ConsoleSpanExporter()),
new SimpleSpanProcessor(new ZipkinExporter({
// testing interceptor
// getExportRequestHeaders: () => {
// return {
// foo: 'bar',
// }
// }
})),
]
});

provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({
// testing interceptor
// getExportRequestHeaders: ()=> {
// return {
// foo: 'bar',
// }
// }
})));

provider.register();

const tracer = provider.getTracer('example-tracer-web');
Expand Down
2 changes: 1 addition & 1 deletion examples/opentracing-shim/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const { TracerShim } = require('@opentelemetry/shim-opentracing');
function shim(serviceName) {
const provider = new NodeTracerProvider({
resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: serviceName }),
spanProcessors: [new SimpleSpanProcessor(getExporter(serviceName))],
});

provider.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName)));
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();

Expand Down
6 changes: 4 additions & 2 deletions examples/otlp-exporter-node/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ const provider = new BasicTracerProvider({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: 'basic-service',
}),
spanProcessors: [
new SimpleSpanProcessor(exporter),
new SimpleSpanProcessor(new ConsoleSpanExporter()),
]
});
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();

const tracer = trace.getTracer('example-otlp-exporter-node');
Expand Down
14 changes: 8 additions & 6 deletions experimental/examples/opencensus-shim/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ module.exports = function setup(serviceName) {
const resource = new Resource({
[SEMRESATTRS_SERVICE_NAME]: serviceName,
});
const tracerProvider = new NodeTracerProvider({ resource });
tracerProvider.addSpanProcessor(
new BatchSpanProcessor(new OTLPTraceExporter(), {
scheduledDelayMillis: 5000,
})
);
const tracerProvider = new NodeTracerProvider({
resource,
spanProcessors: [
new BatchSpanProcessor(new OTLPTraceExporter(), {
scheduledDelayMillis: 5000,
})
]
});
tracerProvider.register();

const meterProvider = new MeterProvider({ resource });
Expand Down
15 changes: 9 additions & 6 deletions experimental/packages/exporter-trace-otlp-grpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ const collectorOptions = {
url: 'http://<collector-hostname>:<port>',
};

const provider = new BasicTracerProvider();
const exporter = new OTLPTraceExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
const provider = new BasicTracerProvider({
spanProcessors: [new SimpleSpanProcessor(exporter)]
});

provider.register();
['SIGINT', 'SIGTERM'].forEach(signal => {
Expand All @@ -59,9 +60,10 @@ const collectorOptions = {
credentials: grpc.credentials.createSsl(),
};

const provider = new BasicTracerProvider();
const exporter = new OTLPTraceExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
const provider = new BasicTracerProvider({
spanProcessors: [new SimpleSpanProcessor(exporter)]
});

provider.register();
['SIGINT', 'SIGTERM'].forEach(signal => {
Expand Down Expand Up @@ -100,9 +102,10 @@ const collectorOptions = {
metadata, // // an optional grpc.Metadata object to be sent with each request
};

const provider = new BasicTracerProvider();
const exporter = new OTLPTraceExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
const provider = new BasicTracerProvider({
spanProcessors: [new SimpleSpanProcessor(exporter)]
});

provider.register();
['SIGINT', 'SIGTERM'].forEach(signal => {
Expand Down
Loading
Loading