Skip to content

Commit 532cf7f

Browse files
mabdinurpiotrj
andauthored
fix: propagate otel span kind to span.kind tag (#6904)
Since opentelemetry tags always have span kinds defined (and if the host project doesn't specify it then it defaults to INTERNAL) then let's propagate that span kind to DD's `span.kind` tag so that it is properly visible in the UI. Otherwise we are forcing clients to add a redundant addAttribute if they want to retain the span kind after the trace is sent to datadog. Co-authored-by: Piotr Jakubowski <piotrj@gmail.com>
1 parent 5e2ed3d commit 532cf7f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/dd-trace/src/opentelemetry/span.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { timeInputToHrTime } = require('@opentelemetry/core')
1010
const tracer = require('../../')
1111
const DatadogSpan = require('../opentracing/span')
1212
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK, IGNORE_OTEL_ERROR } = require('../constants')
13-
const { SERVICE_NAME, RESOURCE_NAME } = require('../../../../ext/tags')
13+
const { SERVICE_NAME, RESOURCE_NAME, SPAN_KIND } = require('../../../../ext/tags')
1414
const kinds = require('../../../../ext/kinds')
1515

1616
const SpanContext = require('./span_context')
@@ -146,7 +146,8 @@ class Span {
146146
integrationName: parentTracer?._isOtelLibrary ? 'otel.library' : 'otel',
147147
tags: {
148148
[SERVICE_NAME]: _tracer._service,
149-
[RESOURCE_NAME]: spanName
149+
[RESOURCE_NAME]: spanName,
150+
[SPAN_KIND]: spanKindNames[kind]
150151
},
151152
links
152153
}, _tracer._debug)

packages/dd-trace/test/opentelemetry/span.spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const SpanContext = require('../../src/opentelemetry/span_context')
1717
const { NoopSpanProcessor } = require('../../src/opentelemetry/span_processor')
1818

1919
const { ERROR_MESSAGE, ERROR_STACK, ERROR_TYPE, IGNORE_OTEL_ERROR } = require('../../src/constants')
20-
const { SERVICE_NAME, RESOURCE_NAME } = require('../../../../ext/tags')
20+
const { SERVICE_NAME, RESOURCE_NAME, SPAN_KIND } = require('../../../../ext/tags')
2121
const kinds = require('../../../../ext/kinds')
2222
const format = require('../../src/format')
2323

@@ -235,6 +235,13 @@ describe('OTel Span', () => {
235235
expect(context._tags[RESOURCE_NAME]).to.equal('name')
236236
})
237237

238+
it('should copy span kind to span.kind', () => {
239+
const span = makeSpan('name', { kind: api.SpanKind.CONSUMER })
240+
241+
const context = span._ddSpan.context()
242+
expect(context._tags[SPAN_KIND]).to.equal(kinds.CONSUMER)
243+
})
244+
238245
it('should expose span context', () => {
239246
const span = makeSpan('name')
240247

0 commit comments

Comments
 (0)