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
  • Loading branch information
JohannesHuster committed Jun 1, 2024
1 parent ecc88a3 commit 7628083
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
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 7628083

Please sign in to comment.