From 96cca4e3499b6bc9e755240aa6e3b904994e3f75 Mon Sep 17 00:00:00 2001 From: Zen-cronic <83657429+Zen-cronic@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:01:08 -0400 Subject: [PATCH 1/3] refactor(examples/opentelemetry-web): use new exported string constants for semconv --- examples/opentelemetry-web/examples/fetch-proto/index.js | 8 +++++++- examples/opentelemetry-web/examples/fetch/index.js | 8 +++++++- examples/opentelemetry-web/examples/fetchXhr/index.js | 8 +++++++- examples/opentelemetry-web/examples/fetchXhrB3/index.js | 8 +++++++- .../opentelemetry-web/examples/xml-http-request/index.js | 8 +++++++- examples/opentelemetry-web/examples/zipkin/index.js | 9 ++++++++- 6 files changed, 43 insertions(+), 6 deletions(-) diff --git a/examples/opentelemetry-web/examples/fetch-proto/index.js b/examples/opentelemetry-web/examples/fetch-proto/index.js index 9a9e85184cd..0faaa0149aa 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 f2632b2e4c3..3326beb19b6 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 8e266f78a7b..1d93af4c49d 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 64afe58d48a..2923cccc6b7 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 ff2b173bcfc..7530528ed87 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 aa01c595c9d..d76de7e563b 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 From 3ced31ce3e994b449c7a7c32cba6c359d7c4f0c7 Mon Sep 17 00:00:00 2001 From: Zen-cronic <83657429+Zen-cronic@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:14:04 -0400 Subject: [PATCH 2/3] added changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6e31bc077a..26f785e2f16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :books: (Refine Doc) * refactor(examples): use new exported string constants for semconv in examples/http [#4750](https://github.com/open-telemetry/opentelemetry-js/pull/4750) @Zen-cronic +* 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) From 76f55a516513e8f13c6e375673feacfd634a4f86 Mon Sep 17 00:00:00 2001 From: Zen-cronic <83657429+Zen-cronic@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:43:43 -0400 Subject: [PATCH 3/3] deleted changelog extra line --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26f785e2f16..da2fb36977e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,6 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ * refactor(examples): use new exported string constants for semconv in examples/http [#4750](https://github.com/open-telemetry/opentelemetry-js/pull/4750) @Zen-cronic * 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) ## 1.24.1