diff --git a/packages/opentelemetry-tracing/src/Span.ts b/packages/opentelemetry-tracing/src/Span.ts index ea6ebce1823..a24c1a77418 100644 --- a/packages/opentelemetry-tracing/src/Span.ts +++ b/packages/opentelemetry-tracing/src/Span.ts @@ -193,7 +193,7 @@ export class Span implements api.Span, ReadableSpan { attributes[ExceptionAttribute.MESSAGE] = exception; } else if (exception) { if (exception.code) { - attributes[ExceptionAttribute.TYPE] = exception.code; + attributes[ExceptionAttribute.TYPE] = exception.code.toString(); } else if (exception.name) { attributes[ExceptionAttribute.TYPE] = exception.name; } diff --git a/packages/opentelemetry-tracing/test/Span.test.ts b/packages/opentelemetry-tracing/test/Span.test.ts index 5597223e026..46d4a3f17bb 100644 --- a/packages/opentelemetry-tracing/test/Span.test.ts +++ b/packages/opentelemetry-tracing/test/Span.test.ts @@ -719,5 +719,23 @@ describe('Span', () => { assert.deepStrictEqual(event.time, [0, 123]); }); }); + + describe('when exception code is numeric', () => { + it('should record an exception with string value', () => { + const span = new Span( + tracer, + ROOT_CONTEXT, + name, + spanContext, + SpanKind.CLIENT + ); + assert.strictEqual(span.events.length, 0); + span.recordException({ code: 12 }); + const event = span.events[0]; + assert.deepStrictEqual(event.attributes, { + [ExceptionAttribute.TYPE]: '12', + }); + }); + }); }); });