From 4a5f6a64b3e06f11a8c80c82c35da1313347c0f8 Mon Sep 17 00:00:00 2001 From: Johannes Huster <66320475+JohannesHuster@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:48:11 +0200 Subject: [PATCH] refactor(shim-opentracing): Use tree-shakeable string constants for semconv (#4746) * refactor(shim-opentracing): Use tree-shakeable string constants for semconv * Update changelog --------- Co-authored-by: Marc Pichler --- CHANGELOG.md | 2 +- .../src/shim.ts | 12 ++++++---- .../test/Shim.test.ts | 22 +++++++++++-------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b81c918117..c28822cbda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,11 +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(shim-opentracing): Use tree-shakeable string constants for semconv [#4746](https://github.com/open-telemetry/opentelemetry-js/pull/4746) @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-shim-opentracing/src/shim.ts b/packages/opentelemetry-shim-opentracing/src/shim.ts index 8b4ecd1bf6..8c4b209c12 100644 --- a/packages/opentelemetry-shim-opentracing/src/shim.ts +++ b/packages/opentelemetry-shim-opentracing/src/shim.ts @@ -22,7 +22,11 @@ import { TextMapPropagator, } from '@opentelemetry/api'; import * as opentracing from 'opentracing'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_EXCEPTION_MESSAGE, + SEMATTRS_EXCEPTION_STACKTRACE, + SEMATTRS_EXCEPTION_TYPE, +} from '@opentelemetry/semantic-conventions'; function translateReferences(references: opentracing.Reference[]): api.Link[] { const links: api.Link[] = []; @@ -325,15 +329,15 @@ export class SpanShim extends opentracing.Span { for (const [k, v] of entries) { switch (k) { case 'error.kind': { - mappedAttributes[SemanticAttributes.EXCEPTION_TYPE] = v; + mappedAttributes[SEMATTRS_EXCEPTION_TYPE] = v; break; } case 'message': { - mappedAttributes[SemanticAttributes.EXCEPTION_MESSAGE] = v; + mappedAttributes[SEMATTRS_EXCEPTION_MESSAGE] = v; break; } case 'stack': { - mappedAttributes[SemanticAttributes.EXCEPTION_STACKTRACE] = v; + mappedAttributes[SEMATTRS_EXCEPTION_STACKTRACE] = v; break; } default: { diff --git a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts index 2da2f80003..fb65e63acb 100644 --- a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts +++ b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts @@ -36,7 +36,11 @@ import { import { performance } from 'perf_hooks'; import { B3Propagator } from '@opentelemetry/propagator-b3'; import { JaegerPropagator } from '@opentelemetry/propagator-jaeger'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_EXCEPTION_MESSAGE, + SEMATTRS_EXCEPTION_STACKTRACE, + SEMATTRS_EXCEPTION_TYPE, +} from '@opentelemetry/semantic-conventions'; describe('OpenTracing Shim', () => { const compositePropagator = new CompositePropagator({ @@ -378,7 +382,7 @@ describe('OpenTracing Shim', () => { span.logEvent('error', payload); assert.strictEqual(otSpan.events[0].name, 'exception'); const expectedAttributes = { - [SemanticAttributes.EXCEPTION_MESSAGE]: 'boom', + [SEMATTRS_EXCEPTION_MESSAGE]: 'boom', }; assert.deepStrictEqual( otSpan.events[0].attributes, @@ -397,9 +401,9 @@ describe('OpenTracing Shim', () => { assert.strictEqual(otSpan.events[0].name, 'exception'); const expectedAttributes = { fault: 'meow', - [SemanticAttributes.EXCEPTION_TYPE]: 'boom', - [SemanticAttributes.EXCEPTION_MESSAGE]: 'oh no!', - [SemanticAttributes.EXCEPTION_STACKTRACE]: 'pancakes', + [SEMATTRS_EXCEPTION_TYPE]: 'boom', + [SEMATTRS_EXCEPTION_MESSAGE]: 'oh no!', + [SEMATTRS_EXCEPTION_STACKTRACE]: 'pancakes', }; assert.deepStrictEqual( otSpan.events[0].attributes, @@ -446,7 +450,7 @@ describe('OpenTracing Shim', () => { Math.trunc(tomorrow / 1000) ); const expectedAttributes = { - [SemanticAttributes.EXCEPTION_MESSAGE]: 'boom', + [SEMATTRS_EXCEPTION_MESSAGE]: 'boom', }; assert.deepStrictEqual( otSpan.events[0].attributes, @@ -471,9 +475,9 @@ describe('OpenTracing Shim', () => { const expectedAttributes = { event: 'error', fault: 'meow', - [SemanticAttributes.EXCEPTION_TYPE]: 'boom', - [SemanticAttributes.EXCEPTION_MESSAGE]: 'oh no!', - [SemanticAttributes.EXCEPTION_STACKTRACE]: 'pancakes', + [SEMATTRS_EXCEPTION_TYPE]: 'boom', + [SEMATTRS_EXCEPTION_MESSAGE]: 'oh no!', + [SEMATTRS_EXCEPTION_STACKTRACE]: 'pancakes', }; assert.deepStrictEqual( otSpan.events[0].attributes,