diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aa3f0afacc..b81c9181177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,9 +15,11 @@ 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 * refactor(sdk-trace-node): Use tree-shakeable string constants for semconv [#4748](https://github.com/open-telemetry/opentelemetry-js/pull/4748) @JohannesHuster * refactor(sdk-trace-base): Use tree-shakeable string constants for semconv [#4749](https://github.com/open-telemetry/opentelemetry-js/pull/4749) @JohannesHuster + ### :bug: (Bug Fix) ### :books: (Refine Doc) 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' ); });