Skip to content

Commit 956052e

Browse files
committed
fix(native-spans): keep OTLP export when a custom lookup is configured
The custom-`lookup` guard did not exclude OTLP, so `OTEL_TRACES_EXPORTER=otlp` plus a configured `lookup` selected the JS pipeline, which builds an `AgentExporter`. The OTLP endpoint was never configured and every span went to the Datadog agent instead of the collector. OTLP export lives in libdatadog, so the JS pipeline cannot do it at all. Give OTLP precedence, exactly as the Lambda pipeline already does, and warn that the `lookup` cannot be honoured rather than dropping it in silence. Reported by Codex review as P1, against the commit that added the guard.
1 parent 3786df7 commit 956052e

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

packages/dd-trace/src/opentracing/tracer.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,22 @@ class DatadogTracer {
121121
//
122122
// CI Visibility and electron pick their own exporters below and neither goes
123123
// through the native transport, so they are unaffected by this.
124+
//
125+
// OTLP is excluded for a harder reason: OTLP export lives in libdatadog, so
126+
// the JS pipeline cannot do it at all. Routing there would quietly ship every
127+
// span to the agent instead of the configured collector, which is a worse
128+
// failure than resolving the collector with the system resolver. OTLP keeps
129+
// precedence exactly as it does for the Lambda pipeline above, and the
130+
// unhonoured `lookup` is announced rather than dropped in silence.
124131
const lookupOrigin = typeof config.getOrigin === 'function' ? config.getOrigin('lookup') : 'default'
125-
const useCustomLookup = typeof config.lookup === 'function' &&
126-
lookupOrigin !== 'default' &&
132+
const hasCustomLookup = typeof config.lookup === 'function' && lookupOrigin !== 'default'
133+
if (hasCustomLookup && useOtlpExporter) {
134+
log.warn('OTLP trace export cannot honour a custom `lookup`; resolving the collector with the system resolver')
135+
}
136+
const useCustomLookup = hasCustomLookup &&
127137
!config.isCiVisibility &&
128-
!useElectronExporter
138+
!useElectronExporter &&
139+
!useOtlpExporter
129140
const unsupportedApmExporter = configuredExporter &&
130141
configuredExporter !== exporters.AGENT &&
131142
!useElectronExporter &&

packages/dd-trace/test/opentracing/tracer.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,29 @@ describe('Tracer', () => {
376376
sinon.assert.calledOnce(NativeSpansInterface)
377377
})
378378

379+
it('keeps OTLP export when a custom DNS lookup is also configured', () => {
380+
// OTLP export lives in libdatadog, so the JS pipeline cannot do it at all.
381+
// Routing there for the sake of `lookup` would quietly ship every span to the
382+
// agent instead of the configured collector - a worse failure than resolving
383+
// the collector with the system resolver.
384+
config.OTEL_TRACES_EXPORTER = 'otlp'
385+
config.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = 'http://collector.example:4318/v1/traces'
386+
config.lookup = (hostname, options, callback) => callback(null, '127.0.0.1', 4)
387+
config.getOrigin = sinon.stub().withArgs('lookup').returns('code')
388+
Tracer = loadTracer()
389+
390+
tracer = new Tracer(config)
391+
392+
assert.strictEqual(tracer._useJsSpans, false)
393+
sinon.assert.notCalled(AgentExporter)
394+
sinon.assert.calledWith(NativeExporter, config, prioritySampler, nativeSpansInstance)
395+
// The dropped `lookup` must be announced, not silently ignored.
396+
sinon.assert.calledWith(
397+
log.warn,
398+
'OTLP trace export cannot honour a custom `lookup`; resolving the collector with the system resolver'
399+
)
400+
})
401+
379402
it('writes traces to stdout when OTLP is requested in a Lambda with no local agent', () => {
380403
// useLambdaJsPipeline excludes OTLP, so this path is reached through the
381404
// missing-libdatadog degrade branch — it must still honour the no-local-agent

0 commit comments

Comments
 (0)