diff --git a/CHANGELOG.md b/CHANGELOG.md index 517321a89d..2445bb96ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :books: (Refine Doc) +* refactor(examples): added usage of @opentelemetry/semantic-conventions and @opentelemetry/resources to the examples in examples/opentelemetry-web for maintaining consistency across all examples. [#4764](https://github.com/open-telemetry/opentelemetry-js/pull/4764) @Zen-cronic + ### :house: (Internal) * refactor(context-zone-peer-dep): use explicit exports [#4785](https://github.com/open-telemetry/opentelemetry-js/pull/4787) @pichlermarc diff --git a/examples/opentelemetry-web/examples/fetch-proto/index.js b/examples/opentelemetry-web/examples/fetch-proto/index.js index 9a9e85184c..0faaa0149a 100644 --- a/examples/opentelemetry-web/examples/fetch-proto/index.js +++ b/examples/opentelemetry-web/examples/fetch-proto/index.js @@ -6,8 +6,14 @@ const { ZoneContextManager } = require("@opentelemetry/context-zone"); const { B3Propagator } = require("@opentelemetry/propagator-b3"); const { registerInstrumentations } = require("@opentelemetry/instrumentation"); const { OTLPTraceExporter: OTLPTraceExporterProto } = require("@opentelemetry/exporter-trace-otlp-proto"); +const { Resource } = require("@opentelemetry/resources"); +const { SEMRESATTRS_SERVICE_NAME } = require("@opentelemetry/semantic-conventions"); -const provider = new WebTracerProvider(); +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 diff --git a/examples/opentelemetry-web/examples/fetch/index.js b/examples/opentelemetry-web/examples/fetch/index.js index f2632b2e4c..3326beb19b 100644 --- a/examples/opentelemetry-web/examples/fetch/index.js +++ b/examples/opentelemetry-web/examples/fetch/index.js @@ -6,8 +6,14 @@ const { FetchInstrumentation } = require( '@opentelemetry/instrumentation-fetch' const { ZoneContextManager } = require( '@opentelemetry/context-zone'); const { B3Propagator } = require( '@opentelemetry/propagator-b3'); const { registerInstrumentations } = require( '@opentelemetry/instrumentation'); +const { Resource } = require('@opentelemetry/resources'); +const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-conventions'); -const provider = new WebTracerProvider(); +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 diff --git a/examples/opentelemetry-web/examples/fetchXhr/index.js b/examples/opentelemetry-web/examples/fetchXhr/index.js index 8e266f78a7..1d93af4c49 100644 --- a/examples/opentelemetry-web/examples/fetchXhr/index.js +++ b/examples/opentelemetry-web/examples/fetchXhr/index.js @@ -6,8 +6,14 @@ const { FetchInstrumentation } = require('@opentelemetry/instrumentation-fetch') const { XMLHttpRequestInstrumentation } = require('@opentelemetry/instrumentation-xml-http-request'); const { ZoneContextManager } = require('@opentelemetry/context-zone'); const { registerInstrumentations } = require('@opentelemetry/instrumentation'); +const { Resource } = require('@opentelemetry/resources'); +const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-conventions'); -const provider = new WebTracerProvider(); +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 diff --git a/examples/opentelemetry-web/examples/fetchXhrB3/index.js b/examples/opentelemetry-web/examples/fetchXhrB3/index.js index 64afe58d48..2923cccc6b 100644 --- a/examples/opentelemetry-web/examples/fetchXhrB3/index.js +++ b/examples/opentelemetry-web/examples/fetchXhrB3/index.js @@ -7,8 +7,14 @@ const { XMLHttpRequestInstrumentation } = require( '@opentelemetry/instrumentati const { ZoneContextManager } = require( '@opentelemetry/context-zone'); const { B3Propagator } = require( '@opentelemetry/propagator-b3'); const { registerInstrumentations } = require( '@opentelemetry/instrumentation'); +const { Resource } = require('@opentelemetry/resources'); +const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-conventions'); -const provider = new WebTracerProvider(); +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 diff --git a/examples/opentelemetry-web/examples/xml-http-request/index.js b/examples/opentelemetry-web/examples/xml-http-request/index.js index ff2b173bcf..7530528ed8 100644 --- a/examples/opentelemetry-web/examples/xml-http-request/index.js +++ b/examples/opentelemetry-web/examples/xml-http-request/index.js @@ -6,8 +6,14 @@ const { ZoneContextManager } = require( '@opentelemetry/context-zone'); const { OTLPTraceExporter } = require( '@opentelemetry/exporter-trace-otlp-http'); const { B3Propagator } = require( '@opentelemetry/propagator-b3'); const { registerInstrumentations } = require( '@opentelemetry/instrumentation'); +const { Resource } = require('@opentelemetry/resources'); +const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-conventions'); -const providerWithZone = new WebTracerProvider(); +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 diff --git a/examples/opentelemetry-web/examples/zipkin/index.js b/examples/opentelemetry-web/examples/zipkin/index.js index aa01c595c9..d76de7e563 100644 --- a/examples/opentelemetry-web/examples/zipkin/index.js +++ b/examples/opentelemetry-web/examples/zipkin/index.js @@ -1,8 +1,15 @@ const { ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base'); const { WebTracerProvider } = require('@opentelemetry/sdk-trace-web'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); +const { Resource } = require('@opentelemetry/resources'); +const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-conventions'); + +const provider = new WebTracerProvider({ + resource: new Resource({ + [SEMRESATTRS_SERVICE_NAME]: 'zipkin-web-service' + }) +}); -const provider = new WebTracerProvider(); provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); provider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({ // testing interceptor