Skip to content

Commit d5086a5

Browse files
authored
feat(startup-log): report OTLP export status (#9517)
Add three boolean fields to the DATADOG TRACER CONFIGURATION startup log indicating whether the tracer exports each telemetry signal over OTLP: - otlp_traces_export_enabled (OTEL_TRACES_EXPORTER === 'otlp', excluding Test Optimization mode, which keeps test spans on the citestcycle endpoint) - otlp_metrics_export_enabled (DD_METRICS_OTEL_ENABLED) - otlp_logs_export_enabled (DD_LOGS_OTEL_ENABLED) The snake_case keys are chosen for cross-language startup-log consistency.
1 parent 1887905 commit d5086a5

2 files changed

Lines changed: 77 additions & 1 deletion

File tree

packages/dd-trace/src/startup-log.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ function configInfo () {
108108
profiling_enabled: profilingEnabled === 'true' || profilingEnabled === 'auto',
109109
appsec_enabled: config.appsec.enabled,
110110
data_streams_enabled: !!config.dsmEnabled,
111+
otlp_traces_export_enabled: config.OTEL_TRACES_EXPORTER === 'otlp' && !config.isCiVisibility,
112+
otlp_metrics_export_enabled: !!config.DD_METRICS_OTEL_ENABLED,
113+
otlp_logs_export_enabled: !!config.DD_LOGS_OTEL_ENABLED,
111114
}
112115
}
113116

packages/dd-trace/test/startup-log.spec.js

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const assert = require('node:assert')
44
const os = require('node:os')
55

6-
const { describe, it, before, afterEach } = require('mocha')
6+
const { describe, it, before, beforeEach, afterEach } = require('mocha')
77
const sinon = require('sinon')
88

99
require('./setup/core')
@@ -80,6 +80,9 @@ describe('startup logging', () => {
8080
assert.strictEqual(logObj.debug, true)
8181
assert.strictEqual(logObj.appsec_enabled, true)
8282
assert.strictEqual(logObj.data_streams_enabled, true)
83+
assert.strictEqual('otlp_traces_export_enabled' in logObj, true)
84+
assert.strictEqual('otlp_metrics_export_enabled' in logObj, true)
85+
assert.strictEqual('otlp_logs_export_enabled' in logObj, true)
8386
})
8487

8588
it('logIntegrations should output loaded integrations', () => {
@@ -121,6 +124,9 @@ describe('startup logging', () => {
121124
integrations_loaded: ['http', 'fs', 'semver'],
122125
appsec_enabled: true,
123126
data_streams_enabled: true,
127+
otlp_traces_export_enabled: false,
128+
otlp_metrics_export_enabled: false,
129+
otlp_logs_export_enabled: false,
124130
})
125131
})
126132
})
@@ -314,3 +320,70 @@ describe('profiling_enabled', () => {
314320
})
315321
})
316322
})
323+
324+
describe('otlp export flags', () => {
325+
function clearOtlpEnv () {
326+
delete process.env.OTEL_TRACES_EXPORTER
327+
delete process.env.OTEL_METRICS_EXPORTER
328+
delete process.env.OTEL_LOGS_EXPORTER
329+
delete process.env.DD_METRICS_OTEL_ENABLED
330+
delete process.env.DD_LOGS_OTEL_ENABLED
331+
}
332+
333+
// Datadog-instrumented dev shells export the OTEL_*_EXPORTER selectors: a leaked
334+
// OTEL_TRACES_EXPORTER=otlp corrupts the default-state assertion, and OTEL_METRICS_EXPORTER=none
335+
// makes config force DD_METRICS_OTEL_ENABLED back to false, breaking the metrics positive case.
336+
beforeEach(clearOtlpEnv)
337+
afterEach(clearOtlpEnv)
338+
339+
function startupLogObj (configOptions) {
340+
sinon.stub(console, 'warn')
341+
delete require.cache[require.resolve('../src/startup-log')]
342+
const {
343+
setStartupLogConfig,
344+
startupLog,
345+
} = require('../src/startup-log')
346+
process.env.DD_TRACE_STARTUP_LOGS = 'true'
347+
setStartupLogConfig(getConfigFresh(configOptions))
348+
startupLog()
349+
/* eslint-disable-next-line no-console */
350+
const warnStub = /** @type {sinon.SinonStub} */ (console.warn)
351+
const logObj = JSON.parse(warnStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', ''))
352+
warnStub.restore()
353+
return logObj
354+
}
355+
356+
it('should default to false when no OTLP env vars are set', () => {
357+
const logObj = startupLogObj()
358+
assert.strictEqual(logObj.otlp_traces_export_enabled, false)
359+
assert.strictEqual(logObj.otlp_metrics_export_enabled, false)
360+
assert.strictEqual(logObj.otlp_logs_export_enabled, false)
361+
})
362+
363+
it('otlp_traces_export_enabled should be true when OTEL_TRACES_EXPORTER is otlp', () => {
364+
process.env.OTEL_TRACES_EXPORTER = 'otlp'
365+
assert.strictEqual(startupLogObj().otlp_traces_export_enabled, true)
366+
})
367+
368+
it('otlp_traces_export_enabled should be false when OTEL_TRACES_EXPORTER is none', () => {
369+
process.env.OTEL_TRACES_EXPORTER = 'none'
370+
assert.strictEqual(startupLogObj().otlp_traces_export_enabled, false)
371+
})
372+
373+
it('otlp_traces_export_enabled should be false in Test Optimization mode even when exporter is otlp', () => {
374+
// Test Optimization keeps test spans on the citestcycle endpoint, so the OTLP
375+
// trace exporter is not used regardless of OTEL_TRACES_EXPORTER (see opentracing/tracer.js).
376+
process.env.OTEL_TRACES_EXPORTER = 'otlp'
377+
assert.strictEqual(startupLogObj({ isCiVisibility: true }).otlp_traces_export_enabled, false)
378+
})
379+
380+
it('otlp_metrics_export_enabled should be true when DD_METRICS_OTEL_ENABLED is true', () => {
381+
process.env.DD_METRICS_OTEL_ENABLED = 'true'
382+
assert.strictEqual(startupLogObj().otlp_metrics_export_enabled, true)
383+
})
384+
385+
it('otlp_logs_export_enabled should be true when DD_LOGS_OTEL_ENABLED is true', () => {
386+
process.env.DD_LOGS_OTEL_ENABLED = 'true'
387+
assert.strictEqual(startupLogObj().otlp_logs_export_enabled, true)
388+
})
389+
})

0 commit comments

Comments
 (0)