Skip to content

Commit

Permalink
Identify span metrics from OpenTelemetry libraries with 'otel.library…
Browse files Browse the repository at this point in the history
…' tag (#4724)

Use existing 'otel' tag for other sources of spans, such as manual tracing
  • Loading branch information
mcculls authored and rochdev committed Oct 30, 2024
1 parent 89fa535 commit a3ab583
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
46 changes: 46 additions & 0 deletions integration-tests/opentelemetry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,52 @@ describe('opentelemetry', () => {
}, true)
})

it('should capture auto-instrumentation telemetry', async () => {
const SERVER_PORT = 6666
proc = fork(join(cwd, 'opentelemetry/auto-instrumentation.js'), {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_TRACE_OTEL_ENABLED: 1,
SERVER_PORT,
DD_TRACE_DISABLED_INSTRUMENTATIONS: 'http,dns,express,net',
DD_TELEMETRY_HEARTBEAT_INTERVAL: 1
}
})
await new Promise(resolve => setTimeout(resolve, 1000)) // Adjust the delay as necessary
await axios.get(`http://localhost:${SERVER_PORT}/first-endpoint`)

return check(agent, proc, 10000, ({ payload }) => {
assert.strictEqual(payload.request_type, 'generate-metrics')

const metrics = payload.payload
assert.strictEqual(metrics.namespace, 'tracers')

const spanCreated = metrics.series.find(({ metric }) => metric === 'spans_created')
const spanFinished = metrics.series.find(({ metric }) => metric === 'spans_finished')

// Validate common fields between start and finish
for (const series of [spanCreated, spanFinished]) {
assert.ok(series)

assert.strictEqual(series.points.length, 1)
assert.strictEqual(series.points[0].length, 2)

const [ts, value] = series.points[0]
assert.ok(nearNow(ts, Date.now() / 1e3))
assert.strictEqual(value, 9)

assert.strictEqual(series.type, 'count')
assert.strictEqual(series.common, true)
assert.deepStrictEqual(series.tags, [
'integration_name:otel.library',
'otel_enabled:true',
`version:${process.version}`
])
}
}, true)
})

it('should work within existing datadog-traced http request', async () => {
proc = fork(join(cwd, 'opentelemetry/server.js'), {
cwd,
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/opentelemetry/span.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Span {
context: spanContext._ddContext,
startTime,
hostname: _tracer._hostname,
integrationName: 'otel',
integrationName: parentTracer?._isOtelLibrary ? 'otel.library' : 'otel',
tags: {
[SERVICE_NAME]: _tracer._service,
[RESOURCE_NAME]: spanName
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/opentelemetry/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Tracer {
this._tracerProvider = tracerProvider
// Is there a reason this is public?
this.instrumentationLibrary = library
this._isOtelLibrary = library?.name?.startsWith('@opentelemetry/instrumentation-')
this._spanLimits = {}
}

Expand Down

0 comments on commit a3ab583

Please sign in to comment.