dd-trace 5.137.0 → 5.138.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +56 -0
- package/initialize.mjs +5 -3
- package/package.json +9 -8
- package/packages/datadog-instrumentations/src/ai.js +88 -127
- package/packages/datadog-instrumentations/src/aws-lambda.js +9 -0
- package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -1
- package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +4 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +2 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +5 -3
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +26 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +3 -1
- package/packages/datadog-instrumentations/src/path-to-regexp.js +11 -11
- package/packages/datadog-instrumentations/src/router.js +17 -1
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1 -1
- package/packages/datadog-plugin-aws-lambda/src/context/events.js +167 -0
- package/packages/datadog-plugin-aws-lambda/src/context/extractor.js +153 -0
- package/packages/datadog-plugin-aws-lambda/src/context/http.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/context/span-context.js +26 -0
- package/packages/datadog-plugin-aws-lambda/src/context/step-functions.js +142 -0
- package/packages/datadog-plugin-aws-lambda/src/context/types.d.ts +17 -0
- package/packages/datadog-plugin-aws-lambda/src/context/xray.js +67 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +52 -4
- package/packages/datadog-plugin-azure-functions/src/index.js +68 -12
- package/packages/datadog-plugin-fetch/src/index.js +7 -0
- package/packages/datadog-plugin-http/src/client.js +12 -0
- package/packages/datadog-plugin-http/src/server.js +18 -4
- package/packages/dd-trace/src/aiguard/client.js +7 -9
- package/packages/dd-trace/src/aiguard/evaluation.js +7 -2
- package/packages/dd-trace/src/aiguard/messages/utils.js +2 -2
- package/packages/dd-trace/src/aiguard/sdk.js +7 -2
- package/packages/dd-trace/src/appsec/api_security/normalized-route.js +273 -167
- package/packages/dd-trace/src/appsec/channels.js +1 -0
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +21 -14
- package/packages/dd-trace/src/appsec/index.js +3 -0
- package/packages/dd-trace/src/appsec/rasp/index.js +57 -3
- package/packages/dd-trace/src/appsec/rasp/utils.js +14 -0
- package/packages/dd-trace/src/carrier.js +7 -1
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +4 -2
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +31 -19
- package/packages/dd-trace/src/config/generated-config-types.d.ts +10 -3
- package/packages/dd-trace/src/config/index.js +28 -2
- package/packages/dd-trace/src/config/parsers.js +25 -0
- package/packages/dd-trace/src/config/supported-configurations.json +27 -7
- package/packages/dd-trace/src/datastreams/http.js +57 -0
- package/packages/dd-trace/src/datastreams/index.js +24 -0
- package/packages/dd-trace/src/datastreams/pathway.js +33 -4
- package/packages/dd-trace/src/datastreams/processor.js +22 -3
- package/packages/dd-trace/src/lambda/handler-paths.js +1 -1
- package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +33 -1
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +102 -1
- package/packages/dd-trace/src/llmobs/span_processor.js +3 -0
- package/packages/dd-trace/src/llmobs/tagger.js +9 -0
- package/packages/dd-trace/src/noop/span.js +0 -4
- package/packages/dd-trace/src/openfeature/flagging_provider.js +17 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +2 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +2 -1
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +16 -1
- package/packages/dd-trace/src/opentelemetry/trace/index.js +5 -4
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +10 -6
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +42 -26
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +4 -4
- package/packages/dd-trace/src/plugin_manager.js +2 -0
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +3 -5
- package/packages/dd-trace/src/plugins/util/url.js +1 -1
- package/packages/dd-trace/src/register-loader.js +43 -0
- package/register.js +10 -44
- package/register.mjs +27 -0
|
@@ -48,6 +48,12 @@ const UNHASHED_TAG_KEYS = new Set([
|
|
|
48
48
|
'has_routing_key',
|
|
49
49
|
])
|
|
50
50
|
|
|
51
|
+
// dd-trace-java aggregates stats per pathway hash and these tags (DataStreamsTags aggregation tags), so
|
|
52
|
+
// has_routing_key and partition variants of one pathway share a stats point.
|
|
53
|
+
const AGGREGATION_TAG_PREFIXES = ['ds.name:', 'ds.namespace:', 'manual_checkpoint:', 'group:', 'consumer_group:']
|
|
54
|
+
/** @type {WeakMap<Buffer, string>} */
|
|
55
|
+
const statsPointKeys = new WeakMap()
|
|
56
|
+
|
|
51
57
|
const PATHWAY_CONTEXT_BYTES = 20
|
|
52
58
|
|
|
53
59
|
// Reused across `encodePathwayContext` calls; the buffer is fully rewritten before each
|
|
@@ -119,10 +125,6 @@ function nodeHashSeed (service, env, processTags, containerTagsHash) {
|
|
|
119
125
|
/**
|
|
120
126
|
* Sorts `edgeTags` in place.
|
|
121
127
|
*
|
|
122
|
-
* Returns one Buffer instance per distinct set of arguments while it stays cached: StatsBucket keys
|
|
123
|
-
* stats points by that instance, which keeps tags left out of the hash, such as `group`, in separate
|
|
124
|
-
* stats points.
|
|
125
|
-
*
|
|
126
128
|
* @param {string} service
|
|
127
129
|
* @param {string | undefined} env
|
|
128
130
|
* @param {string[]} edgeTags
|
|
@@ -150,6 +152,32 @@ function computeHash (service, env, edgeTags, parentHash, processTags, container
|
|
|
150
152
|
return value
|
|
151
153
|
}
|
|
152
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Key of the stats point a checkpoint aggregates into, as dd-trace-java's aggregation hash.
|
|
157
|
+
*
|
|
158
|
+
* A hash Buffer from computeHash always stands for one tag set, because its cache key holds every tag, so the key
|
|
159
|
+
* is built once per Buffer.
|
|
160
|
+
*
|
|
161
|
+
* @param {Buffer} hash Pathway hash as uint64 little-endian.
|
|
162
|
+
* @param {string[]} edgeTags
|
|
163
|
+
*/
|
|
164
|
+
function statsPointKey (hash, edgeTags) {
|
|
165
|
+
let key = statsPointKeys.get(hash)
|
|
166
|
+
if (key !== undefined) return key
|
|
167
|
+
|
|
168
|
+
key = hash.toString('latin1')
|
|
169
|
+
for (const tag of edgeTags) {
|
|
170
|
+
for (const prefix of AGGREGATION_TAG_PREFIXES) {
|
|
171
|
+
if (tag.startsWith(prefix)) {
|
|
172
|
+
key += `\0${tag}`
|
|
173
|
+
break
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
statsPointKeys.set(hash, key)
|
|
178
|
+
return key
|
|
179
|
+
}
|
|
180
|
+
|
|
153
181
|
/**
|
|
154
182
|
* @param {object} dataStreamsContext
|
|
155
183
|
* @param {Buffer} dataStreamsContext.hash
|
|
@@ -274,4 +302,5 @@ module.exports = {
|
|
|
274
302
|
encodePathwayContextBase64,
|
|
275
303
|
decodePathwayContextBase64,
|
|
276
304
|
DsmPathwayCodec,
|
|
305
|
+
statsPointKey,
|
|
277
306
|
}
|
|
@@ -8,7 +8,8 @@ const { PATHWAY_HASH, DSM_TRANSACTION_ID, DSM_TRANSACTION_CHECKPOINT } = require
|
|
|
8
8
|
const log = require('../log')
|
|
9
9
|
const processTags = require('../process-tags')
|
|
10
10
|
const propagationHash = require('../propagation-hash')
|
|
11
|
-
const
|
|
11
|
+
const telemetryMetrics = require('../telemetry/metrics')
|
|
12
|
+
const { computePathwayHash, statsPointKey } = require('./pathway')
|
|
12
13
|
const { DataStreamsWriter } = require('./writer')
|
|
13
14
|
const { getAmqpMessageSize, getHeadersSize, getMessageSize, getSizeOrZero, PATHWAY_FIELD_BYTES } = require('./size')
|
|
14
15
|
const { SchemaBuilder } = require('./schemas/schema_builder')
|
|
@@ -16,6 +17,11 @@ const { SchemaSampler } = require('./schemas/schema_sampler')
|
|
|
16
17
|
|
|
17
18
|
const ENTRY_PARENT_HASH = Buffer.from('0000000000000000', 'hex')
|
|
18
19
|
|
|
20
|
+
// Parent hashes come from inbound headers, so without a bound a caller can grow a bucket without limit.
|
|
21
|
+
const MAX_CHECKPOINTS_PER_BUCKET = 2000
|
|
22
|
+
|
|
23
|
+
const tracerMetrics = telemetryMetrics.manager.namespace('tracers')
|
|
24
|
+
|
|
19
25
|
class StatsPoint {
|
|
20
26
|
constructor (hash, parentHash, edgeTags) {
|
|
21
27
|
this.hash = hash.readBigUInt64LE()
|
|
@@ -149,11 +155,20 @@ class StatsBucket {
|
|
|
149
155
|
return Buffer.concat(this._transactionChunks)
|
|
150
156
|
}
|
|
151
157
|
|
|
158
|
+
/**
|
|
159
|
+
* @param {object} checkpoint
|
|
160
|
+
* @param {Buffer} checkpoint.hash
|
|
161
|
+
* @param {Buffer} checkpoint.parentHash
|
|
162
|
+
* @param {string[]} checkpoint.edgeTags
|
|
163
|
+
* @returns {StatsPoint | undefined} `undefined` when the bucket already holds the maximum number of checkpoints.
|
|
164
|
+
*/
|
|
152
165
|
forCheckpoint ({ hash, parentHash, edgeTags }) {
|
|
153
|
-
|
|
166
|
+
const key = statsPointKey(hash, edgeTags)
|
|
167
|
+
let checkpoint = this._checkpoints.get(key)
|
|
154
168
|
if (!checkpoint) {
|
|
169
|
+
if (this._checkpoints.size >= MAX_CHECKPOINTS_PER_BUCKET) return
|
|
155
170
|
checkpoint = new StatsPoint(hash, parentHash, edgeTags)
|
|
156
|
-
this._checkpoints.set(
|
|
171
|
+
this._checkpoints.set(key, checkpoint)
|
|
157
172
|
}
|
|
158
173
|
|
|
159
174
|
return checkpoint
|
|
@@ -275,6 +290,10 @@ class DataStreamsProcessor {
|
|
|
275
290
|
recordCheckpoint (checkpoint, span = null) {
|
|
276
291
|
if (!this.enabled) return
|
|
277
292
|
const statsPoint = this.bucketFromTimestamp(checkpoint.currentTimestamp).forCheckpoint(checkpoint)
|
|
293
|
+
if (statsPoint === undefined) {
|
|
294
|
+
tracerMetrics.count('data_streams.checkpoints_dropped', ['reason:bucket_full']).inc()
|
|
295
|
+
return
|
|
296
|
+
}
|
|
278
297
|
statsPoint.addLatencies(checkpoint)
|
|
279
298
|
if (span) {
|
|
280
299
|
// StatsPoint already converted the 8-byte Buffer hash to a uint64 BigInt.
|
|
@@ -27,7 +27,7 @@ function extractModuleRootAndHandler (fullHandler) {
|
|
|
27
27
|
* @throws {Error} When the handler is not of the form `<module>.<path>`.
|
|
28
28
|
*/
|
|
29
29
|
function extractModuleNameAndHandlerPath (handler) {
|
|
30
|
-
const match =
|
|
30
|
+
const match = /^([^.]*)\.(.*)$/.exec(handler)
|
|
31
31
|
if (!match || match.length !== 3) {
|
|
32
32
|
throw new Error(`Malformed handler name: ${handler}`)
|
|
33
33
|
}
|
|
@@ -28,6 +28,7 @@ module.exports = {
|
|
|
28
28
|
AGENT_VERSION_TAG_KEY: 'agent_version',
|
|
29
29
|
METRICS: '_ml_obs.metrics',
|
|
30
30
|
TOOL_DEFINITIONS: '_ml_obs.meta.tool_definitions',
|
|
31
|
+
INTENT: '_ml_obs.meta.intent',
|
|
31
32
|
ML_APP: '_ml_obs.meta.ml_app',
|
|
32
33
|
PROPAGATED_PARENT_ID_KEY: '_dd.p.llmobs_parent_id',
|
|
33
34
|
PROPAGATED_ML_APP_KEY: '_dd.p.llmobs_ml_app',
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const LLMObsPlugin = require('../base')
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
formatInput,
|
|
6
|
+
formatOutput,
|
|
7
|
+
formatServerInput,
|
|
8
|
+
getClientInfoTags,
|
|
9
|
+
injectTelemetrySchema,
|
|
10
|
+
safeStringify,
|
|
11
|
+
stripTelemetry,
|
|
12
|
+
} = require('./utils')
|
|
5
13
|
|
|
6
14
|
class McpToolCallLLMObsPlugin extends LLMObsPlugin {
|
|
7
15
|
static id = 'llmobs_mcp_tool_call'
|
|
@@ -78,10 +86,34 @@ class McpServerRequestLLMObsPlugin extends LLMObsPlugin {
|
|
|
78
86
|
return { kind: 'task', name: `mcp.${request?.method ?? 'unknown'}` }
|
|
79
87
|
}
|
|
80
88
|
|
|
89
|
+
/**
|
|
90
|
+
* With intent capture, tools/list results ask the model for a `telemetry.intent` argument, and tools/call requests
|
|
91
|
+
* reach the tool without it. The instrumentation passes `ctx.request` to the handler and applies
|
|
92
|
+
* `ctx.transformResult` to its result.
|
|
93
|
+
*
|
|
94
|
+
* @param {object} ctx
|
|
95
|
+
*/
|
|
96
|
+
start (ctx) {
|
|
97
|
+
super.start(ctx)
|
|
98
|
+
if (!ctx.llmobs || !this._tracerConfig.mcp?.DD_MCP_CAPTURE_INTENT) return
|
|
99
|
+
|
|
100
|
+
const method = ctx.request?.method
|
|
101
|
+
if (method === 'tools/list') {
|
|
102
|
+
ctx.transformResult = injectTelemetrySchema
|
|
103
|
+
} else if (method === 'tools/call') {
|
|
104
|
+
const stripped = stripTelemetry(ctx.request)
|
|
105
|
+
if (!stripped) return
|
|
106
|
+
ctx.request = stripped.request
|
|
107
|
+
ctx.llmobs.intent = stripped.intent
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
81
111
|
setLLMObsTags (ctx) {
|
|
82
112
|
const span = ctx.currentStore?.span
|
|
83
113
|
if (!span) return
|
|
84
114
|
|
|
115
|
+
if (ctx.llmobs?.intent) this._tagger.tagIntent(span, ctx.llmobs.intent)
|
|
116
|
+
|
|
85
117
|
const { request, extra, server } = ctx
|
|
86
118
|
const spanTags = {
|
|
87
119
|
mcp_method: request?.method,
|
|
@@ -132,4 +132,105 @@ function getClientInfoTags (envelope, server) {
|
|
|
132
132
|
return tags
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
const TELEMETRY_KEY = 'telemetry'
|
|
136
|
+
const INTENT_KEY = 'intent'
|
|
137
|
+
// The client writes the intent, so a cap keeps the span event under the intake size limit.
|
|
138
|
+
const MAX_INTENT_LENGTH = 1024
|
|
139
|
+
const TELEMETRY_SCHEMA = {
|
|
140
|
+
type: 'object',
|
|
141
|
+
properties: {
|
|
142
|
+
[INTENT_KEY]: {
|
|
143
|
+
type: 'string',
|
|
144
|
+
description: 'Briefly describe the wider context task, and why this tool was chosen. Omit argument values, ' +
|
|
145
|
+
'PII/secrets. Use English.',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
required: [INTENT_KEY],
|
|
149
|
+
additionalProperties: false,
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @param {unknown} value
|
|
154
|
+
* @returns {value is Record<string, unknown>}
|
|
155
|
+
*/
|
|
156
|
+
function isObject (value) {
|
|
157
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* UI-only tools cannot be called by the model, so they get no telemetry parameter.
|
|
162
|
+
*
|
|
163
|
+
* @param {{ _meta?: { ui?: { visibility?: unknown } } }} tool
|
|
164
|
+
*/
|
|
165
|
+
function isModelCallable (tool) {
|
|
166
|
+
const visibility = tool._meta?.ui?.visibility
|
|
167
|
+
return !Array.isArray(visibility) || visibility.includes('model')
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Returns a copy of a tools/list result where each model-callable tool requires a `telemetry` argument with the
|
|
172
|
+
* caller's intent. The SDK's own tool objects are not changed, because it validates calls against them.
|
|
173
|
+
*
|
|
174
|
+
* @param {{ tools?: unknown }} result
|
|
175
|
+
*/
|
|
176
|
+
function injectTelemetrySchema (result) {
|
|
177
|
+
if (!isObject(result) || !Array.isArray(result.tools)) return result
|
|
178
|
+
|
|
179
|
+
const tools = result.tools.map(tool => {
|
|
180
|
+
if (!isObject(tool) || !isModelCallable(tool)) return tool
|
|
181
|
+
|
|
182
|
+
const inputSchema = isObject(tool.inputSchema) ? tool.inputSchema : {}
|
|
183
|
+
const properties = isObject(inputSchema.properties) ? inputSchema.properties : {}
|
|
184
|
+
if (Object.hasOwn(properties, TELEMETRY_KEY)) return tool
|
|
185
|
+
const required = Array.isArray(inputSchema.required) ? inputSchema.required : []
|
|
186
|
+
return {
|
|
187
|
+
...tool,
|
|
188
|
+
inputSchema: {
|
|
189
|
+
type: 'object',
|
|
190
|
+
...inputSchema,
|
|
191
|
+
properties: { ...properties, [TELEMETRY_KEY]: TELEMETRY_SCHEMA },
|
|
192
|
+
required: required.includes(TELEMETRY_KEY) ? required : [...required, TELEMETRY_KEY],
|
|
193
|
+
},
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
return { ...result, tools }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @param {unknown} telemetry
|
|
201
|
+
* @returns {telemetry is { intent?: unknown }}
|
|
202
|
+
*/
|
|
203
|
+
function isInjectedTelemetry (telemetry) {
|
|
204
|
+
if (!isObject(telemetry)) return false
|
|
205
|
+
for (const key of Object.keys(telemetry)) {
|
|
206
|
+
if (key !== INTENT_KEY) return false
|
|
207
|
+
}
|
|
208
|
+
return true
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Returns a copy of a tools/call request without the `telemetry` argument, and the intent it carried, or `undefined`
|
|
213
|
+
* when the request has no `telemetry` argument of the injected shape. Other values belong to the tool.
|
|
214
|
+
*
|
|
215
|
+
* @param {{ params?: { arguments?: unknown } }} request
|
|
216
|
+
* @returns {{ request: object, intent?: string } | undefined}
|
|
217
|
+
*/
|
|
218
|
+
function stripTelemetry (request) {
|
|
219
|
+
const args = request?.params?.arguments
|
|
220
|
+
if (!isObject(args) || !isInjectedTelemetry(args[TELEMETRY_KEY])) return
|
|
221
|
+
|
|
222
|
+
const { [TELEMETRY_KEY]: telemetry, ...rest } = args
|
|
223
|
+
const { intent } = telemetry
|
|
224
|
+
const capped = typeof intent === 'string' ? intent.slice(0, MAX_INTENT_LENGTH) || undefined : undefined
|
|
225
|
+
return { request: { ...request, params: { ...request.params, arguments: rest } }, intent: capped }
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
module.exports = {
|
|
229
|
+
formatInput,
|
|
230
|
+
formatOutput,
|
|
231
|
+
formatServerInput,
|
|
232
|
+
getClientInfoTags,
|
|
233
|
+
injectTelemetrySchema,
|
|
234
|
+
safeStringify,
|
|
235
|
+
stripTelemetry,
|
|
236
|
+
}
|
|
@@ -23,6 +23,7 @@ const {
|
|
|
23
23
|
AGENT_VERSION,
|
|
24
24
|
AGENT_VERSION_TAG_KEY,
|
|
25
25
|
TOOL_DEFINITIONS,
|
|
26
|
+
INTENT,
|
|
26
27
|
EXPERIMENT_INPUT,
|
|
27
28
|
EXPERIMENT_OUTPUT,
|
|
28
29
|
INPUT_MESSAGES,
|
|
@@ -250,6 +251,8 @@ class LLMObsSpanProcessor {
|
|
|
250
251
|
this.#addObject(mlObsTags[TOOL_DEFINITIONS], meta.tool_definitions)
|
|
251
252
|
}
|
|
252
253
|
|
|
254
|
+
if (mlObsTags[INTENT]) meta.intent = mlObsTags[INTENT]
|
|
255
|
+
|
|
253
256
|
// Surface the agent attribution resolved at registration, but only on spans that actually
|
|
254
257
|
// have an agent ancestor. The id is always present in that case; the name may be missing when
|
|
255
258
|
// it arrived id-only over distributed propagation (older/unsafe upstream). Emit the name as
|
|
@@ -25,6 +25,7 @@ const {
|
|
|
25
25
|
AGENT_VERSION,
|
|
26
26
|
METRICS,
|
|
27
27
|
TOOL_DEFINITIONS,
|
|
28
|
+
INTENT,
|
|
28
29
|
PARENT_ID_KEY,
|
|
29
30
|
INPUT_MESSAGES,
|
|
30
31
|
OUTPUT_MESSAGES,
|
|
@@ -379,6 +380,14 @@ class LLMObsTagger {
|
|
|
379
380
|
}
|
|
380
381
|
}
|
|
381
382
|
|
|
383
|
+
/**
|
|
384
|
+
* @param {import('../opentracing/span')} span
|
|
385
|
+
* @param {string} intent
|
|
386
|
+
*/
|
|
387
|
+
tagIntent (span, intent) {
|
|
388
|
+
this._setTag(span, INTENT, intent)
|
|
389
|
+
}
|
|
390
|
+
|
|
382
391
|
tagMetadata (span, metadata) {
|
|
383
392
|
const existingMetadata = registry.get(span)?.[METADATA]
|
|
384
393
|
if (existingMetadata) {
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const id = require('../id')
|
|
4
|
-
const { storage } = require('../../../datadog-core') // TODO: noop storage?
|
|
5
4
|
const NoopSpanContext = require('./span_context')
|
|
6
5
|
|
|
7
|
-
const legacyStorage = storage('legacy')
|
|
8
|
-
|
|
9
6
|
class NoopSpan {
|
|
10
7
|
constructor (tracer, parent) {
|
|
11
|
-
this._store = legacyStorage.getHandle()
|
|
12
8
|
this._noopTracer = tracer
|
|
13
9
|
this._noopContext = this._createContext(parent)
|
|
14
10
|
}
|
|
@@ -42,6 +42,9 @@ class FlaggingProvider extends DatadogNodeServerProvider {
|
|
|
42
42
|
/** @type {number} */
|
|
43
43
|
#initializationTimeoutMs
|
|
44
44
|
|
|
45
|
+
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
|
46
|
+
#initializationHold
|
|
47
|
+
|
|
45
48
|
/**
|
|
46
49
|
* @param {import('../tracer')} tracer - Datadog tracer instance
|
|
47
50
|
* @param {import('../config/config-base')} config - Tracer configuration object
|
|
@@ -117,6 +120,11 @@ class FlaggingProvider extends DatadogNodeServerProvider {
|
|
|
117
120
|
// No configuration can arrive, so fail now instead of waiting for the timeout.
|
|
118
121
|
this.setError(this.#configurationSourceError)
|
|
119
122
|
} else {
|
|
123
|
+
// The upstream initialization timer and every configuration source poll timer are unref'd. Without a ref'd
|
|
124
|
+
// handle, an otherwise idle process awaiting `setProviderAndWait` exits with code 0 while initialization is
|
|
125
|
+
// still pending. Hold the process until initialization settles, which the timeout bounds.
|
|
126
|
+
clearTimeout(this.#initializationHold)
|
|
127
|
+
this.#initializationHold = setTimeout(() => {}, this.#initializationTimeoutMs)
|
|
120
128
|
log.debug('Feature Flags: waiting for provider initialization (timeout %dms)...', this.#initializationTimeoutMs)
|
|
121
129
|
}
|
|
122
130
|
|
|
@@ -136,6 +144,7 @@ class FlaggingProvider extends DatadogNodeServerProvider {
|
|
|
136
144
|
// An empty update leaves upstream initialization pending until configuration arrives or it times out.
|
|
137
145
|
if (configuration == null) return
|
|
138
146
|
this.#waitingForConfiguration = false
|
|
147
|
+
this.#releaseInitializationHold()
|
|
139
148
|
|
|
140
149
|
if (wasWaiting) {
|
|
141
150
|
this.#logInitialConfiguration()
|
|
@@ -151,6 +160,7 @@ class FlaggingProvider extends DatadogNodeServerProvider {
|
|
|
151
160
|
const wasWaiting = this.#waitingForConfiguration
|
|
152
161
|
super.setError(error)
|
|
153
162
|
this.#waitingForConfiguration = false
|
|
163
|
+
this.#releaseInitializationHold()
|
|
154
164
|
if (!wasWaiting) return
|
|
155
165
|
|
|
156
166
|
try {
|
|
@@ -162,6 +172,11 @@ class FlaggingProvider extends DatadogNodeServerProvider {
|
|
|
162
172
|
} catch { /* logging failure must not affect initialization */ }
|
|
163
173
|
}
|
|
164
174
|
|
|
175
|
+
#releaseInitializationHold () {
|
|
176
|
+
clearTimeout(this.#initializationHold)
|
|
177
|
+
this.#initializationHold = undefined
|
|
178
|
+
}
|
|
179
|
+
|
|
165
180
|
#logInitialConfiguration () {
|
|
166
181
|
try {
|
|
167
182
|
log.debug('Feature Flags: initial configuration available')
|
|
@@ -181,6 +196,8 @@ class FlaggingProvider extends DatadogNodeServerProvider {
|
|
|
181
196
|
onClose () {
|
|
182
197
|
this.#configurationSource?.stop()
|
|
183
198
|
this.#configurationSource = undefined
|
|
199
|
+
// No configuration can arrive once the source stops, so a pending initialization must not hold the process.
|
|
200
|
+
this.#releaseInitializationHold()
|
|
184
201
|
this.#spanEnrichmentHook?.destroy()
|
|
185
202
|
this.#spanEnrichmentHook = undefined
|
|
186
203
|
this.#flagEvalEVPHook?.destroy()
|
|
@@ -4,6 +4,7 @@ const { SeverityNumber } = require('@opentelemetry/api-logs')
|
|
|
4
4
|
const { trace } = require('@opentelemetry/api')
|
|
5
5
|
|
|
6
6
|
const OtlpTransformerBase = require('../otlp/otlp_transformer_base')
|
|
7
|
+
const { isInt64 } = require('../otlp/otlp_transformer_base')
|
|
7
8
|
const { getProtobufTypes } = require('../otlp/protobuf_loader')
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -231,7 +232,7 @@ class OtlpTransformer extends OtlpTransformerBase {
|
|
|
231
232
|
if (typeof body === 'string') {
|
|
232
233
|
return { stringValue: body }
|
|
233
234
|
} else if (typeof body === 'number') {
|
|
234
|
-
if (
|
|
235
|
+
if (isInt64(body)) {
|
|
235
236
|
return { intValue: body }
|
|
236
237
|
}
|
|
237
238
|
return { doubleValue: body }
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const OtlpTransformerBase = require('../otlp/otlp_transformer_base')
|
|
4
|
+
const { isInt64 } = require('../otlp/otlp_transformer_base')
|
|
4
5
|
const { getProtobufTypes } = require('../otlp/protobuf_loader')
|
|
5
6
|
const { METRIC_TYPES, TEMPORALITY } = require('./constants')
|
|
6
7
|
|
|
@@ -239,7 +240,7 @@ class OtlpTransformer extends OtlpTransformerBase {
|
|
|
239
240
|
* @param {number} value - The value to assign
|
|
240
241
|
*/
|
|
241
242
|
#assignNumberValue (dataPoint, value) {
|
|
242
|
-
if (
|
|
243
|
+
if (isInt64(value)) {
|
|
243
244
|
dataPoint.asInt = value
|
|
244
245
|
} else {
|
|
245
246
|
dataPoint.asDouble = value
|
|
@@ -7,6 +7,20 @@ const log = require('../../log')
|
|
|
7
7
|
* @typedef {import('@opentelemetry/api').AttributeValue} AttributeValue
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
// OTLP integer fields are signed 64-bit. Larger integers wrap in protobuf and are rejected in JSON,
|
|
11
|
+
// so they are exported as doubles instead.
|
|
12
|
+
const INT64_MIN = -(2 ** 63)
|
|
13
|
+
const INT64_MAX_EXCLUSIVE = 2 ** 63
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether a number can be exported as an OTLP int64 (or sfixed64) value.
|
|
17
|
+
*
|
|
18
|
+
* @param {number} value
|
|
19
|
+
*/
|
|
20
|
+
function isInt64 (value) {
|
|
21
|
+
return Number.isInteger(value) && value >= INT64_MIN && value < INT64_MAX_EXCLUSIVE
|
|
22
|
+
}
|
|
23
|
+
|
|
10
24
|
/**
|
|
11
25
|
* Base class for OTLP transformers.
|
|
12
26
|
*
|
|
@@ -125,7 +139,7 @@ class OtlpTransformerBase {
|
|
|
125
139
|
if (typeof value === 'string') {
|
|
126
140
|
return { stringValue: value }
|
|
127
141
|
} else if (typeof value === 'number') {
|
|
128
|
-
if (
|
|
142
|
+
if (isInt64(value)) {
|
|
129
143
|
return { intValue: value }
|
|
130
144
|
}
|
|
131
145
|
return { doubleValue: value }
|
|
@@ -191,4 +205,5 @@ function stableStringify (attributes) {
|
|
|
191
205
|
}
|
|
192
206
|
|
|
193
207
|
module.exports = OtlpTransformerBase
|
|
208
|
+
module.exports.isInt64 = isInt64
|
|
194
209
|
module.exports.stableStringify = stableStringify
|
|
@@ -18,8 +18,8 @@ const OtlpHttpTraceExporter = require('./otlp_http_trace_exporter')
|
|
|
18
18
|
* replaces the default Datadog Agent exporter at tracer initialization time.
|
|
19
19
|
*
|
|
20
20
|
* Key Components:
|
|
21
|
-
* - OtlpHttpTraceExporter: Exports spans via OTLP over HTTP/JSON (port 4318)
|
|
22
|
-
* - OtlpTraceTransformer: Transforms DD-formatted spans to OTLP JSON format
|
|
21
|
+
* - OtlpHttpTraceExporter: Exports spans via OTLP over HTTP/JSON or HTTP/protobuf (port 4318)
|
|
22
|
+
* - OtlpTraceTransformer: Transforms DD-formatted spans to OTLP JSON or protobuf format
|
|
23
23
|
*
|
|
24
24
|
* When enabled, traces are exported exclusively via OTLP. The original
|
|
25
25
|
* Datadog Agent exporter is replaced.
|
|
@@ -59,16 +59,17 @@ function buildResourceAttributes (config) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Creates the OTLP HTTP
|
|
62
|
+
* Creates the OTLP HTTP trace exporter.
|
|
63
63
|
*
|
|
64
64
|
* @param {Config} config - Tracer configuration instance
|
|
65
|
-
* @returns {OtlpHttpTraceExporter} The OTLP HTTP
|
|
65
|
+
* @returns {OtlpHttpTraceExporter} The OTLP HTTP exporter
|
|
66
66
|
*/
|
|
67
67
|
function createOtlpTraceExporter (config) {
|
|
68
68
|
const exporter = new OtlpHttpTraceExporter(
|
|
69
69
|
config.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
|
|
70
70
|
config.OTEL_EXPORTER_OTLP_TRACES_HEADERS,
|
|
71
71
|
config.OTEL_EXPORTER_OTLP_TRACES_TIMEOUT,
|
|
72
|
+
config.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL,
|
|
72
73
|
buildResourceAttributes(config),
|
|
73
74
|
config.DD_TRACE_OTEL_SEMANTICS_ENABLED
|
|
74
75
|
)
|
|
@@ -6,13 +6,13 @@ const { AUTO_KEEP } = require('../../../../../ext/priority')
|
|
|
6
6
|
const OtlpTraceTransformer = require('./otlp_transformer')
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* OtlpHttpTraceExporter exports DD-formatted spans via OTLP over HTTP
|
|
9
|
+
* OtlpHttpTraceExporter exports DD-formatted spans via OTLP over HTTP (JSON or protobuf).
|
|
10
10
|
*
|
|
11
11
|
* This implementation follows the OTLP HTTP specification:
|
|
12
12
|
* https://opentelemetry.io/docs/specs/otlp/#otlphttp
|
|
13
13
|
*
|
|
14
14
|
* It receives DD-formatted spans (from span_format.js), transforms them
|
|
15
|
-
* to OTLP ExportTraceServiceRequest
|
|
15
|
+
* to an OTLP ExportTraceServiceRequest in the configured encoding, and sends them to the
|
|
16
16
|
* configured OTLP endpoint via HTTP POST.
|
|
17
17
|
*
|
|
18
18
|
* TODO: Add batch handling similar to the OpenTelemetry SDK Batch Processor
|
|
@@ -35,12 +35,16 @@ class OtlpHttpTraceExporter extends OtlpHttpExporterBase {
|
|
|
35
35
|
* @param {Record<string, string>|undefined} headers - Additional HTTP headers parsed from the
|
|
36
36
|
* corresponding `OTEL_EXPORTER_OTLP_*_HEADERS` env by the MAP parser.
|
|
37
37
|
* @param {number} timeout - Request timeout in milliseconds
|
|
38
|
+
* @param {string} protocol - OTLP protocol (http/protobuf or http/json)
|
|
38
39
|
* @param {import('@opentelemetry/api').Attributes} resourceAttributes - Resource attributes
|
|
39
|
-
* @param {boolean} otelTraceSemanticsEnabled - When true, do not emit Datadog-only attributes as span attributes
|
|
40
|
+
* @param {boolean} [otelTraceSemanticsEnabled] - When true, do not emit Datadog-only attributes as span attributes
|
|
40
41
|
*/
|
|
41
|
-
constructor (url, headers, timeout, resourceAttributes, otelTraceSemanticsEnabled) {
|
|
42
|
-
super(url, headers, timeout,
|
|
43
|
-
this.#transformer = new OtlpTraceTransformer(resourceAttributes, otelTraceSemanticsEnabled)
|
|
42
|
+
constructor (url, headers, timeout, protocol, resourceAttributes, otelTraceSemanticsEnabled) {
|
|
43
|
+
super(url, headers, timeout, protocol, 'traces', resourceAttributes)
|
|
44
|
+
this.#transformer = new OtlpTraceTransformer(resourceAttributes, protocol, otelTraceSemanticsEnabled)
|
|
45
|
+
// Expose the protocol actually used after transformer fallback (grpc -> http/protobuf) so
|
|
46
|
+
// startup reporting describes the exporter rather than the requested protocol.
|
|
47
|
+
this.protocol = this.#transformer.protocol
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
/**
|