From e9ba5076dd4468c076561f6bca408d3779b837a4 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Thu, 16 Jan 2025 15:59:53 -0800 Subject: [PATCH] doc(*): Migrate away from deprecated `addSpanProcessor` in READMEs This migrates from the deprecated `addSpanProcessor` method to the constructor option in preparation for the upcoming SDK 2.0 release. This commit migrates everything in the README.md of each package, other than that there are no runtime code changes. Technically this is a user-facing change for users that previously followed the examples. Ref #2645 --- metapackages/auto-instrumentations-node/README.md | 4 +++- metapackages/auto-instrumentations-web/README.md | 7 +++++-- plugins/node/instrumentation-undici/README.md | 7 +++++-- .../opentelemetry-instrumentation-generic-pool/README.md | 7 +++++-- plugins/node/opentelemetry-instrumentation-knex/README.md | 7 +++++-- .../node/opentelemetry-instrumentation-restify/README.md | 7 +++++-- .../node/opentelemetry-instrumentation-router/README.md | 7 +++++-- .../opentelemetry-instrumentation-document-load/README.md | 8 +++++--- .../web/opentelemetry-instrumentation-long-task/README.md | 8 +++++--- .../README.md | 6 ++++-- 10 files changed, 47 insertions(+), 21 deletions(-) diff --git a/metapackages/auto-instrumentations-node/README.md b/metapackages/auto-instrumentations-node/README.md index b41c31fa3c..60692e339c 100644 --- a/metapackages/auto-instrumentations-node/README.md +++ b/metapackages/auto-instrumentations-node/README.md @@ -138,8 +138,10 @@ const provider = new NodeTracerProvider({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'basic-service', }), + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], }); -provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); provider.register(); registerInstrumentations({ diff --git a/metapackages/auto-instrumentations-web/README.md b/metapackages/auto-instrumentations-web/README.md index 864e031709..e51b806e84 100644 --- a/metapackages/auto-instrumentations-web/README.md +++ b/metapackages/auto-instrumentations-web/README.md @@ -26,8 +26,11 @@ const exporter = new CollectorTraceExporter({ serviceName: 'auto-instrumentations-web', }); -const provider = new WebTracerProvider(); -provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); +const provider = new WebTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(exporter), + ], +}); provider.register({ contextManager: new ZoneContextManager(), propagator: new B3Propagator(), diff --git a/plugins/node/instrumentation-undici/README.md b/plugins/node/instrumentation-undici/README.md index e0d9f8d158..154a915b63 100644 --- a/plugins/node/instrumentation-undici/README.md +++ b/plugins/node/instrumentation-undici/README.md @@ -35,9 +35,12 @@ const { } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-generic-pool/README.md b/plugins/node/opentelemetry-instrumentation-generic-pool/README.md index 90404555dc..32b791d12c 100644 --- a/plugins/node/opentelemetry-instrumentation-generic-pool/README.md +++ b/plugins/node/opentelemetry-instrumentation-generic-pool/README.md @@ -27,9 +27,12 @@ const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { GenericPoolInstrumentation } = require('@opentelemetry/instrumentation-generic-pool'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-knex/README.md b/plugins/node/opentelemetry-instrumentation-knex/README.md index e467172648..596fdcc619 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/README.md +++ b/plugins/node/opentelemetry-instrumentation-knex/README.md @@ -27,9 +27,12 @@ const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-restify/README.md b/plugins/node/opentelemetry-instrumentation-restify/README.md index 1894864da5..3115cba564 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/README.md +++ b/plugins/node/opentelemetry-instrumentation-restify/README.md @@ -27,9 +27,12 @@ const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ] +}); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/node/opentelemetry-instrumentation-router/README.md b/plugins/node/opentelemetry-instrumentation-router/README.md index 7145d3b8a3..254541ae96 100644 --- a/plugins/node/opentelemetry-instrumentation-router/README.md +++ b/plugins/node/opentelemetry-instrumentation-router/README.md @@ -27,9 +27,12 @@ const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { RouterInstrumentation } = require('@opentelemetry/instrumentation-router'); -const provider = new NodeTracerProvider(); +const provider = new NodeTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({ diff --git a/plugins/web/opentelemetry-instrumentation-document-load/README.md b/plugins/web/opentelemetry-instrumentation-document-load/README.md index c672add7a5..d127ac0d51 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/README.md +++ b/plugins/web/opentelemetry-instrumentation-document-load/README.md @@ -26,9 +26,11 @@ import { registerInstrumentations } from '@opentelemetry/instrumentation'; import { B3Propagator } from '@opentelemetry/propagator-b3'; import { CompositePropagator, W3CTraceContextPropagator } from '@opentelemetry/core'; -const provider = new WebTracerProvider(); - -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); +const provider = new WebTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); provider.register({ propagator: new CompositePropagator({ diff --git a/plugins/web/opentelemetry-instrumentation-long-task/README.md b/plugins/web/opentelemetry-instrumentation-long-task/README.md index 5239e006b5..e14aff098b 100644 --- a/plugins/web/opentelemetry-instrumentation-long-task/README.md +++ b/plugins/web/opentelemetry-instrumentation-long-task/README.md @@ -23,9 +23,11 @@ import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'; import { LongTaskInstrumentation } from '@opentelemetry/instrumentation-long-task'; import { registerInstrumentations } from '@opentelemetry/instrumentation'; -const provider = new WebTracerProvider(); - -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); +const provider = new WebTracerProvider({ + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], +}); registerInstrumentations({ tracerProvider: provider, diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/README.md b/plugins/web/opentelemetry-instrumentation-user-interaction/README.md index 9d4f98bcb7..05f76a002b 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/README.md +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/README.md @@ -32,10 +32,12 @@ import { registerInstrumentations } from '@opentelemetry/instrumentation'; // import { ZoneContextManager } from '@opentelemetry/context-zone-peer-dep'; const provider = new WebTracerProvider({ - contextManager: new ZoneContextManager() + contextManager: new ZoneContextManager(), + spanProcessors: [ + new SimpleSpanProcessor(new ConsoleSpanExporter()), + ], }); -provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.register(); registerInstrumentations({