Skip to content

Commit a457776

Browse files
authored
fix: exception.type should always be a string (#2086)
1 parent fec5e31 commit a457776

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/opentelemetry-tracing/src/Span.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class Span implements api.Span, ReadableSpan {
193193
attributes[ExceptionAttribute.MESSAGE] = exception;
194194
} else if (exception) {
195195
if (exception.code) {
196-
attributes[ExceptionAttribute.TYPE] = exception.code;
196+
attributes[ExceptionAttribute.TYPE] = exception.code.toString();
197197
} else if (exception.name) {
198198
attributes[ExceptionAttribute.TYPE] = exception.name;
199199
}

packages/opentelemetry-tracing/test/Span.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,5 +719,23 @@ describe('Span', () => {
719719
assert.deepStrictEqual(event.time, [0, 123]);
720720
});
721721
});
722+
723+
describe('when exception code is numeric', () => {
724+
it('should record an exception with string value', () => {
725+
const span = new Span(
726+
tracer,
727+
ROOT_CONTEXT,
728+
name,
729+
spanContext,
730+
SpanKind.CLIENT
731+
);
732+
assert.strictEqual(span.events.length, 0);
733+
span.recordException({ code: 12 });
734+
const event = span.events[0];
735+
assert.deepStrictEqual(event.attributes, {
736+
[ExceptionAttribute.TYPE]: '12',
737+
});
738+
});
739+
});
722740
});
723741
});

0 commit comments

Comments
 (0)