Skip to content

Commit

Permalink
Set error.type on OpenTelemetry spans
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshMock committed Jun 18, 2024
1 parent 46d33c9 commit 83742d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,10 @@ export default class Transport {
let response
try {
response = await _request()
} catch (err) {
} catch (err: any) {
otelSpan.recordException(err as Exception)
otelSpan.setStatus({ code: SpanStatusCode.ERROR })
otelSpan.setAttribute('error.type', err.name ?? 'Error')

throw err
} finally {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/transport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,7 @@ test('OpenTelemetry', t => {
})

t.test('span records error state', async t => {
t.plan(2)
t.plan(3)

const pool = new WeightedConnectionPool({ Connection: MockConnectionTimeout })
pool.addConnection('http://localhost:9200')
Expand All @@ -2351,6 +2351,7 @@ test('OpenTelemetry', t => {

const spans = exporter.getFinishedSpans()

t.equal(spans[0].attributes['error.type'], 'TimeoutError')
t.not(spans[0].status.code, 0)
})

Expand Down

0 comments on commit 83742d5

Please sign in to comment.