Skip to content

Commit d07d630

Browse files
authored
refactor(sdk-trace-base): update semconv usage to ATTR_ exports (#5669)
1 parent bc8c94e commit d07d630

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
2828

2929
### :house: Internal
3030

31+
* refactor(sdk-trace-base): update semconv usage to ATTR_ exports [#5669](https://github.com/open-telemetry/opentelemetry-js/pull/5669) @trentm
3132
* refactor(sdk-trace-web): update semconv usage to ATTR_ exports [#5672](https://github.com/open-telemetry/opentelemetry-js/pull/5672) @trentm
3233
* refactor(resources): update semconv usage to ATTR_ exports [#5666](https://github.com/open-telemetry/opentelemetry-js/pull/5666) @trentm
3334
* test(sdk-metrics): fix multiple problematic assertRejects() calls [#5611](https://github.com/open-telemetry/opentelemetry-js/pull/5611) @cjihrig

packages/opentelemetry-sdk-trace-base/src/Span.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ import {
4444
} from '@opentelemetry/core';
4545
import { Resource } from '@opentelemetry/resources';
4646
import {
47-
SEMATTRS_EXCEPTION_MESSAGE,
48-
SEMATTRS_EXCEPTION_STACKTRACE,
49-
SEMATTRS_EXCEPTION_TYPE,
47+
ATTR_EXCEPTION_MESSAGE,
48+
ATTR_EXCEPTION_STACKTRACE,
49+
ATTR_EXCEPTION_TYPE,
5050
} from '@opentelemetry/semantic-conventions';
5151
import { ReadableSpan } from './export/ReadableSpan';
5252
import { ExceptionEventName } from './enums';
@@ -330,26 +330,23 @@ export class SpanImpl implements Span {
330330
recordException(exception: Exception, time?: TimeInput): void {
331331
const attributes: Attributes = {};
332332
if (typeof exception === 'string') {
333-
attributes[SEMATTRS_EXCEPTION_MESSAGE] = exception;
333+
attributes[ATTR_EXCEPTION_MESSAGE] = exception;
334334
} else if (exception) {
335335
if (exception.code) {
336-
attributes[SEMATTRS_EXCEPTION_TYPE] = exception.code.toString();
336+
attributes[ATTR_EXCEPTION_TYPE] = exception.code.toString();
337337
} else if (exception.name) {
338-
attributes[SEMATTRS_EXCEPTION_TYPE] = exception.name;
338+
attributes[ATTR_EXCEPTION_TYPE] = exception.name;
339339
}
340340
if (exception.message) {
341-
attributes[SEMATTRS_EXCEPTION_MESSAGE] = exception.message;
341+
attributes[ATTR_EXCEPTION_MESSAGE] = exception.message;
342342
}
343343
if (exception.stack) {
344-
attributes[SEMATTRS_EXCEPTION_STACKTRACE] = exception.stack;
344+
attributes[ATTR_EXCEPTION_STACKTRACE] = exception.stack;
345345
}
346346
}
347347

348348
// these are minimum requirements from spec
349-
if (
350-
attributes[SEMATTRS_EXCEPTION_TYPE] ||
351-
attributes[SEMATTRS_EXCEPTION_MESSAGE]
352-
) {
349+
if (attributes[ATTR_EXCEPTION_TYPE] || attributes[ATTR_EXCEPTION_MESSAGE]) {
353350
this.addEvent(ExceptionEventName, attributes, time);
354351
} else {
355352
diag.warn(`Failed to record an exception ${exception}`);

packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ import {
3333
otperformance as performance,
3434
} from '@opentelemetry/core';
3535
import {
36-
SEMATTRS_EXCEPTION_MESSAGE,
37-
SEMATTRS_EXCEPTION_STACKTRACE,
38-
SEMATTRS_EXCEPTION_TYPE,
36+
ATTR_EXCEPTION_MESSAGE,
37+
ATTR_EXCEPTION_STACKTRACE,
38+
ATTR_EXCEPTION_TYPE,
3939
} from '@opentelemetry/semantic-conventions';
4040
import * as assert from 'assert';
4141
import * as sinon from 'sinon';
@@ -1439,10 +1439,10 @@ describe('Span', () => {
14391439

14401440
assert.ok(event.attributes);
14411441

1442-
const type = event.attributes[SEMATTRS_EXCEPTION_TYPE];
1443-
const message = event.attributes[SEMATTRS_EXCEPTION_MESSAGE];
1442+
const type = event.attributes[ATTR_EXCEPTION_TYPE];
1443+
const message = event.attributes[ATTR_EXCEPTION_MESSAGE];
14441444
const stacktrace = String(
1445-
event.attributes[SEMATTRS_EXCEPTION_STACKTRACE]
1445+
event.attributes[ATTR_EXCEPTION_STACKTRACE]
14461446
);
14471447
assert.strictEqual(type, 'Error');
14481448
assert.strictEqual(message, 'boom');
@@ -1488,7 +1488,7 @@ describe('Span', () => {
14881488
span.recordException({ code: 12 });
14891489
const event = span.events[0];
14901490
assert.deepStrictEqual(event.attributes, {
1491-
[SEMATTRS_EXCEPTION_TYPE]: '12',
1491+
[ATTR_EXCEPTION_TYPE]: '12',
14921492
});
14931493
});
14941494
});

0 commit comments

Comments
 (0)