diff --git a/examples/connect/tracing.js b/examples/connect/tracing.js index 7639af2925..bbc8994126 100644 --- a/examples/connect/tracing.js +++ b/examples/connect/tracing.js @@ -22,10 +22,14 @@ function log() { } module.exports = (serviceName) => { + const exporter = new CollectorTraceExporter(); const provider = new NodeTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: serviceName, }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], }); const connectInstrumentation = new ConnectInstrumentation(); registerInstrumentations({ @@ -37,10 +41,6 @@ module.exports = (serviceName) => { ], }); - const exporter = new CollectorTraceExporter(); - - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register({}); return { diff --git a/examples/dns/tracer.js b/examples/dns/tracer.js index a2cee3295c..1dbc49fc73 100644 --- a/examples/dns/tracer.js +++ b/examples/dns/tracer.js @@ -11,8 +11,6 @@ const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); - let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter({ @@ -24,7 +22,11 @@ module.exports = (serviceName) => { }); } - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/express/src/tracer.ts b/examples/express/src/tracer.ts index b86e92b712..d7122604cc 100644 --- a/examples/express/src/tracer.ts +++ b/examples/express/src/tracer.ts @@ -11,10 +11,14 @@ import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; export const setupTracing = (serviceName: string) => { + const exporter = new OTLPTraceExporter({}); const provider = new NodeTracerProvider({ resource: new Resource({ [ATTR_SERVICE_NAME]: serviceName, }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], sampler: filterSampler(ignoreHealthCheck, new AlwaysOnSampler()), }); registerInstrumentations({ @@ -26,10 +30,6 @@ export const setupTracing = (serviceName: string) => { ], }); - const exporter = new OTLPTraceExporter({}); - - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/graphql/tracer.js b/examples/graphql/tracer.js index 82a24edde8..c718f57532 100644 --- a/examples/graphql/tracer.js +++ b/examples/graphql/tracer.js @@ -14,10 +14,12 @@ const provider = new NodeTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'graphql-service', }), + spanProcessors: [ + new SimpleSpanProcessor(new OTLPTraceExporter()), + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], }); -provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/examples/grpc-census-prop/tracer.js b/examples/grpc-census-prop/tracer.js index b8241dc2b1..7fcb590fdc 100644 --- a/examples/grpc-census-prop/tracer.js +++ b/examples/grpc-census-prop/tracer.js @@ -13,11 +13,13 @@ const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc'); * requested propagator */ module.exports = (serviceName, binaryPropagator) => { - const provider = new NodeTracerProvider(); - - // It is recommended to use this `BatchSpanProcessor` for better performance - // and optimization, especially in production. - provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); + const provider = new NodeTracerProvider({ + spanProcessors: [ + // It is recommended to use `BatchSpanProcessor` for better performance + // and optimization, especially in production. + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], + }); if (binaryPropagator) { // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings diff --git a/examples/hapi/tracer.js b/examples/hapi/tracer.js index 9c335d108b..cf0993eda7 100644 --- a/examples/hapi/tracer.js +++ b/examples/hapi/tracer.js @@ -12,15 +12,18 @@ const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); - let exporter; if (EXPORTER === 'jaeger') { exporter = new JaegerExporter({ serviceName }); } else { exporter = new ZipkinExporter({ serviceName }); } - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + + const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/ioredis/tracer.js b/examples/ioredis/tracer.js index 6d18533d9a..1b0701cd76 100644 --- a/examples/ioredis/tracer.js +++ b/examples/ioredis/tracer.js @@ -7,11 +7,13 @@ const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { IORedisInstrumentation } = require('@opentelemetry/instrumentation-ioredis'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const provider = new NodeTracerProvider(); - const exporter = new JaegerExporter({ serviceName: 'ioredis-example' }); -provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], +}); // Initialize the OpenTelemetry APIs to use the BasicTracer bindings provider.register(); diff --git a/examples/koa/src/tracer.ts b/examples/koa/src/tracer.ts index d0a3321a68..1a06e748c4 100644 --- a/examples/koa/src/tracer.ts +++ b/examples/koa/src/tracer.ts @@ -15,19 +15,21 @@ import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions' const EXPORTER = process.env.EXPORTER || ''; export const setupTracing = (serviceName: string) => { - const provider = new NodeTracerProvider({ - resource: new Resource({ - [SEMRESATTRS_SERVICE_NAME]: serviceName - }) - }); - let exporter; if (EXPORTER === 'jaeger') { exporter = new JaegerExporter(); } else { exporter = new ZipkinExporter(); } - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + + const provider = new NodeTracerProvider({ + resource: new Resource({ + [SEMRESATTRS_SERVICE_NAME]: serviceName + }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); registerInstrumentations({ instrumentations: [ diff --git a/examples/memcached/tracer.js b/examples/memcached/tracer.js index 285233199a..aecd74956b 100644 --- a/examples/memcached/tracer.js +++ b/examples/memcached/tracer.js @@ -14,10 +14,14 @@ const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-convention const { MemcachedInstrumentation } = require('@opentelemetry/instrumentation-memcached'); module.exports = (serviceName) => { + const exporter = new ConsoleSpanExporter(); const provider = new NodeTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: serviceName, }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], }); registerInstrumentations({ tracerProvider: provider, @@ -26,10 +30,6 @@ module.exports = (serviceName) => { ], }); - const exporter = new ConsoleSpanExporter(); - - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/meta-node/tracer.js b/examples/meta-node/tracer.js index 4636e30392..50cbb957c6 100644 --- a/examples/meta-node/tracer.js +++ b/examples/meta-node/tracer.js @@ -17,8 +17,11 @@ module.exports = () => { serviceName: 'basic-service', }); - const provider = new NodeTracerProvider(); - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); provider.register(); registerInstrumentations({ diff --git a/examples/mongodb/src/tracer.ts b/examples/mongodb/src/tracer.ts index a9599dec35..f3d9acdc68 100644 --- a/examples/mongodb/src/tracer.ts +++ b/examples/mongodb/src/tracer.ts @@ -15,6 +15,10 @@ export const setupTracing = (serviceName: string): api.Tracer => { resource: new Resource({ [ATTR_SERVICE_NAME]: serviceName, }), + spanProcessors: [ + new SimpleSpanProcessor(new ZipkinExporter()), + new SimpleSpanProcessor(new OTLPTraceExporter()), + ], }); // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings @@ -30,8 +34,5 @@ export const setupTracing = (serviceName: string): api.Tracer => { tracerProvider: provider, }); - provider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter())); - provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); - return api.trace.getTracer('mongodb-example'); }; diff --git a/examples/mysql/src/tracer.ts b/examples/mysql/src/tracer.ts index 2ded0e2567..32ec30136f 100644 --- a/examples/mysql/src/tracer.ts +++ b/examples/mysql/src/tracer.ts @@ -2,7 +2,7 @@ import opentelemetry from '@opentelemetry/api'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; -import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'; +import { SimpleSpanProcessor, SpanProcessor } from '@opentelemetry/sdk-trace-base'; import { ZipkinExporter } from '@opentelemetry/exporter-zipkin'; import { registerInstrumentations } from '@opentelemetry/instrumentation'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; @@ -30,15 +30,19 @@ export const setupTracing = (serviceName: string) => { meterProvider.addMetricReader(metricReader); //traces: - const tracerProvider = new NodeTracerProvider({ - resource: new Resource({ - [SEMRESATTRS_SERVICE_NAME]: serviceName, - }),}); + const spanProcessors: SpanProcessor[] = []; if (EXPORTER.toLowerCase().startsWith('z')) { - tracerProvider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter())); + spanProcessors.push(new SimpleSpanProcessor(new ZipkinExporter())); } + const tracerProvider = new NodeTracerProvider({ + resource: new Resource({ + [SEMRESATTRS_SERVICE_NAME]: serviceName, + }), + spanProcessors, + }); + // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings tracerProvider.register(); diff --git a/examples/network/client.js b/examples/network/client.js index 5ce3523971..8aad8eb04e 100644 --- a/examples/network/client.js +++ b/examples/network/client.js @@ -9,13 +9,14 @@ const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); -const provider = new NodeTracerProvider(); - -provider.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter({ - serviceName: 'http-client', -}))); - -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new JaegerExporter({ + serviceName: 'http-client', + })), + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); provider.register(); diff --git a/examples/react-load/preact/src/web-tracer.js b/examples/react-load/preact/src/web-tracer.js index b52d436e0a..f974a91b96 100644 --- a/examples/react-load/preact/src/web-tracer.js +++ b/examples/react-load/preact/src/web-tracer.js @@ -7,13 +7,15 @@ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; export default (serviceName) => { diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); - const provider = new WebTracerProvider(); const exporter = new OTLPTraceExporter({ url: 'http://localhost:4318/v1/traces', }); - - provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + const provider = new WebTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + new SimpleSpanProcessor(exporter), + ], + }); provider.register({ contextManager: new ZoneContextManager(), diff --git a/examples/react-load/react/src/web-tracer.js b/examples/react-load/react/src/web-tracer.js index 80796da13e..d026455dff 100644 --- a/examples/react-load/react/src/web-tracer.js +++ b/examples/react-load/react/src/web-tracer.js @@ -8,19 +8,20 @@ import { Resource } from '@opentelemetry/resources'; import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions' export default (serviceName) => { + const exporter = new CollectorTraceExporter({ + url: 'http://localhost:55678/v1/trace', + }); + const provider = new WebTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: "react-load-example" }), + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + new SimpleSpanProcessor(exporter), + ], }); - const exporter = new CollectorTraceExporter({ - url: 'http://localhost:55678/v1/trace', - }); - - provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - provider.register({ contextManager: new ZoneContextManager(), }); diff --git a/examples/redis/src/tracer.ts b/examples/redis/src/tracer.ts index de70a60418..91eb03bec2 100644 --- a/examples/redis/src/tracer.ts +++ b/examples/redis/src/tracer.ts @@ -14,11 +14,6 @@ import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions'; const EXPORTER = process.env.EXPORTER || ''; export const setupTracing = (serviceName: string) => { - const provider = new NodeTracerProvider({ - resource: new Resource({ - [SEMRESATTRS_SERVICE_NAME]: serviceName, - }),}); - let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { exporter = new ZipkinExporter(); @@ -26,7 +21,14 @@ export const setupTracing = (serviceName: string) => { exporter = new JaegerExporter(); } - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); + const provider = new NodeTracerProvider({ + resource: new Resource({ + [SEMRESATTRS_SERVICE_NAME]: serviceName, + }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ] + }); // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/restify/tracer.js b/examples/restify/tracer.js index ddeecc3b8d..b2712adf03 100644 --- a/examples/restify/tracer.js +++ b/examples/restify/tracer.js @@ -28,7 +28,16 @@ const Exporter = ((exporterParam) => { })(process.env.EXPORTER); module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); + const exporter = new Exporter({ + serviceName, + }); + + const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); + registerInstrumentations({ tracerProvider: provider, instrumentations: [ @@ -37,12 +46,6 @@ module.exports = (serviceName) => { ], }); - const exporter = new Exporter({ - serviceName, - }); - - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/router/tracer.js b/examples/router/tracer.js index 63aaaaa0a5..73ee585060 100644 --- a/examples/router/tracer.js +++ b/examples/router/tracer.js @@ -28,7 +28,16 @@ const Exporter = ((exporterParam) => { })(process.env.EXPORTER); module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); + const exporter = new Exporter({ + serviceName, + }); + + const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], + }); + registerInstrumentations({ tracerProvider: provider, instrumentations: [ @@ -37,12 +46,6 @@ module.exports = (serviceName) => { ], }); - const exporter = new Exporter({ - serviceName, - }); - - provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); - // Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings provider.register(); diff --git a/examples/web/examples/document-load/index.js b/examples/web/examples/document-load/index.js index 65db02bba3..c09039b587 100644 --- a/examples/web/examples/document-load/index.js +++ b/examples/web/examples/document-load/index.js @@ -15,11 +15,12 @@ const provider = new WebTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'web-service-dl', }), + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + new SimpleSpanProcessor(new OTLPTraceExporter()), + ], }); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); -provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); - provider.register({ contextManager: new ZoneContextManager(), propagator: new CompositePropagator({ diff --git a/examples/web/examples/meta/index.js b/examples/web/examples/meta/index.js index 8b9cb5ad41..90e6e4ae73 100644 --- a/examples/web/examples/meta/index.js +++ b/examples/web/examples/meta/index.js @@ -12,11 +12,12 @@ const providerWithZone = new WebTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'web-service-meta', }), + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + new SimpleSpanProcessor(new OTLPTraceExporter()), + ], }); -providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); -providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); - providerWithZone.register({ contextManager: new ZoneContextManager(), propagator: new B3Propagator(), diff --git a/examples/web/examples/user-interaction/index.js b/examples/web/examples/user-interaction/index.js index b75cae65d5..0360f13577 100644 --- a/examples/web/examples/user-interaction/index.js +++ b/examples/web/examples/user-interaction/index.js @@ -13,11 +13,12 @@ const providerWithZone = new WebTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'web-service-ui', }), + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + new SimpleSpanProcessor(new OTLPTraceExporter()), + ], }); -providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); -providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter())); - providerWithZone.register({ contextManager: new ZoneContextManager(), propagator: new B3Propagator(),