Skip to content

Commit 48ee473

Browse files
committed
feat(native): export agentless traces through libdatadog
Agentless tracing previously stayed on the JS exporter, so libdatadog could not normalize or obfuscate the final payload. Native selection now requires an explicit binding capability, preserves the JS fallback for older packages, and fails closed when agentless configuration is invalid.
1 parent b9b623c commit 48ee473

14 files changed

Lines changed: 846 additions & 223 deletions

File tree

integration-tests/init.spec.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ const {
2424
} = require('./helpers')
2525
const supportedRange = engines.node
2626
const currentVersionIsSupported = semver.satisfies(NODE_VERSION, supportedRange)
27-
// On unsupported runtimes the tracer is stubbed (see stubTracerIfNeeded), so the
28-
// real native-init debug lines never print; on supported runtimes the forced
29-
// (DD_INJECT_FORCE) path loads the real tracer and emits them.
30-
const nativeInitDebugLines = currentVersionIsSupported
31-
? 'Native spans interface initialized\nNative spans mode enabled\n'
32-
: ''
27+
const nativeInitDebugLines = '(?:Native spans interface initialized\nNative spans mode enabled\n)?'
3328
// These are on by default in release tests, so we'll turn them off for
3429
// more fine-grained control of these variables in these tests.
3530
delete process.env.DD_INJECTION_ENABLED

packages/dd-trace/src/encode/0.4.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class AgentEncoder {
140140
#formatSpan
141141

142142
/**
143-
* @param {{ flush: Function }} writer
143+
* @param {{ flush: () => void, onError?: (error: unknown) => void }} writer
144144
* @param {number} [limit]
145145
* @param {boolean} [nativeSpanEvents]
146146
*/
@@ -173,7 +173,12 @@ class AgentEncoder {
173173
try {
174174
this._encode(bytes, trace)
175175
} catch (error) {
176-
if (error.code !== 'ERR_MSGPACK_CHUNK_OVERFLOW') throw error
176+
if (error?.code !== 'ERR_MSGPACK_CHUNK_OVERFLOW') {
177+
if (this.#writer.onError === undefined) throw error
178+
this.reset()
179+
this.#writer.onError(error)
180+
return
181+
}
177182
// The trace, or the queued payload it joined, hit the chunk cap.
178183
// Rolling back just the in-flight trace is unsafe: the string cache
179184
// may already hold subarrays / indices pointing at bytes we'd
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
const MAX_ACTIVE_BUFFER_SIZE = 64 * 1024 * 1024
4+
5+
module.exports = { MAX_ACTIVE_BUFFER_SIZE }

packages/dd-trace/src/exporters/common/request.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const log = require('../../log')
1313
const { isLoopbackHost, parseUrl } = require('./url')
1414
const docker = require('./docker')
1515
const { httpAgent, httpsAgent } = require('./agents')
16+
const { MAX_ACTIVE_BUFFER_SIZE } = require('./limits')
1617
const {
1718
getMaxAttempts,
1819
getRetryDelay,
@@ -22,8 +23,6 @@ const {
2223

2324
const legacyStorage = storage('legacy')
2425

25-
const maxActiveBufferSize = 1024 * 1024 * 64
26-
2726
let activeBufferSize = 0
2827

2928
/**
@@ -250,7 +249,7 @@ function byteLength (data) {
250249

251250
Object.defineProperty(request, 'writable', {
252251
get () {
253-
return activeBufferSize < maxActiveBufferSize
252+
return activeBufferSize < MAX_ACTIVE_BUFFER_SIZE
254253
},
255254
})
256255

0 commit comments

Comments
 (0)