From 9b1b3570fdb71471609f4ff7035c37c497d309c7 Mon Sep 17 00:00:00 2001 From: Johannes Huster <66320475+JohannesHuster@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:24:35 +0200 Subject: [PATCH 1/2] refactor(sdk-trace-web): Use tree-shakeable string constants for semconv --- packages/opentelemetry-sdk-trace-web/src/utils.ts | 12 ++++++------ .../test/WebTracerProvider.test.ts | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/opentelemetry-sdk-trace-web/src/utils.ts b/packages/opentelemetry-sdk-trace-web/src/utils.ts index 833485017e8..5bcc57b72e9 100644 --- a/packages/opentelemetry-sdk-trace-web/src/utils.ts +++ b/packages/opentelemetry-sdk-trace-web/src/utils.ts @@ -26,7 +26,10 @@ import { timeInputToHrTime, urlMatches, } from '@opentelemetry/core'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH, + SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, +} from '@opentelemetry/semantic-conventions'; // Used to normalize relative URLs let urlNormalizingAnchor: HTMLAnchorElement | undefined; @@ -110,16 +113,13 @@ export function addSpanNetworkEvents( addSpanNetworkEvent(span, PTN.RESPONSE_END, resource); const encodedLength = resource[PTN.ENCODED_BODY_SIZE]; if (encodedLength !== undefined) { - span.setAttribute( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, - encodedLength - ); + span.setAttribute(SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH, encodedLength); } const decodedLength = resource[PTN.DECODED_BODY_SIZE]; // Spec: Not set if transport encoding not used (in which case encoded and decoded sizes match) if (decodedLength !== undefined && encodedLength !== decodedLength) { span.setAttribute( - SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, + SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED, decodedLength ); } diff --git a/packages/opentelemetry-sdk-trace-web/test/WebTracerProvider.test.ts b/packages/opentelemetry-sdk-trace-web/test/WebTracerProvider.test.ts index de63292a6a6..9ea2a1300da 100644 --- a/packages/opentelemetry-sdk-trace-web/test/WebTracerProvider.test.ts +++ b/packages/opentelemetry-sdk-trace-web/test/WebTracerProvider.test.ts @@ -18,7 +18,7 @@ import { context, ContextManager, trace } from '@opentelemetry/api'; import { ZoneContextManager } from '@opentelemetry/context-zone'; import { B3Propagator } from '@opentelemetry/propagator-b3'; import { Resource } from '@opentelemetry/resources'; -import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; +import { SEMRESATTRS_TELEMETRY_SDK_LANGUAGE } from '@opentelemetry/semantic-conventions'; import { Span, Tracer } from '@opentelemetry/sdk-trace-base'; import * as assert from 'assert'; import { WebTracerConfig } from '../src'; @@ -130,9 +130,7 @@ describe('WebTracerProvider', () => { assert.ok(span); assert.ok(span.resource instanceof Resource); assert.equal( - span.resource.attributes[ - SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE - ], + span.resource.attributes[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE], 'webjs' ); }); From 146939b7bb5e8f2c38fdfa7d70496a00f7708294 Mon Sep 17 00:00:00 2001 From: Johannes Huster <66320475+JohannesHuster@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:30:07 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 869e21f71a0..e3b3f834d93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ * feat: support node 22 [#4666](https://github.com/open-telemetry/opentelemetry-js/pull/4666) @dyladan * feat(context-zone*): support zone.js 0.12.x [#4376](https://github.com/open-telemetry/opentelemetry-js/pull/4736) @maldago * refactor(core): Use tree-shakeable string constants for semconv [#4739](https://github.com/open-telemetry/opentelemetry-js/pull/4739) @JohannesHuster +* refactor(sdk-trace-web): Use tree-shakeable string constants for semconv [#4747](https://github.com/open-telemetry/opentelemetry-js/pull/4747) @JohannesHuster ### :bug: (Bug Fix)