Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify span metrics from OpenTelemetry libraries with 'otel.library' tag #4724

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading