Skip to content

Commit

Permalink
refactor(shim-opentracing): Use tree-shakeable string constants for s…
Browse files Browse the repository at this point in the history
…emconv (open-telemetry#4746)

* refactor(shim-opentracing): Use tree-shakeable string constants for semconv

* Update changelog

---------

Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
  • Loading branch information
2 people authored and Zirak committed Sep 14, 2024
1 parent 18449ee commit 4a5f6a6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions packages/opentelemetry-shim-opentracing/src/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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: {
Expand Down
22 changes: 13 additions & 9 deletions packages/opentelemetry-shim-opentracing/test/Shim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 4a5f6a6

Please sign in to comment.