dd-trace 5.136.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/README.md +3 -0
- package/ci/cypress/support.js +2 -1
- package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-setup.mjs +729 -724
- package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
- package/index.d.ts +56 -0
- package/initialize.mjs +5 -3
- package/package.json +36 -32
- package/packages/datadog-esbuild/index.js +8 -15
- package/packages/datadog-esbuild/src/log.js +2 -29
- package/packages/datadog-instrumentations/src/ai.js +88 -122
- package/packages/datadog-instrumentations/src/aws-lambda.js +9 -0
- package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
- package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +23 -1
- package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +9 -6
- package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
- 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/index.js +6 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +12 -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/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +21 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +30 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +6 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
- package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +32 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +43 -0
- package/packages/datadog-instrumentations/src/next.js +184 -20
- package/packages/datadog-instrumentations/src/path-to-regexp.js +11 -11
- package/packages/datadog-instrumentations/src/router.js +52 -13
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1 -1
- package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
- package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
- 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/event-type-guards.js +170 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +52 -4
- package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
- package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
- package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
- package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
- package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
- package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
- package/packages/datadog-plugin-azure-functions/src/index.js +68 -12
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +30 -4
- package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
- package/packages/datadog-plugin-express/src/code_origin.js +2 -2
- package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
- package/packages/datadog-plugin-fetch/src/index.js +7 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +2 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +7 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
- package/packages/datadog-plugin-http/src/client.js +14 -1
- package/packages/datadog-plugin-http/src/server.js +18 -4
- package/packages/datadog-plugin-http2/src/client.js +2 -1
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
- package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
- package/packages/datadog-plugin-postgres/src/index.js +118 -41
- package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
- package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
- package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
- package/packages/datadog-plugin-vitest/src/index.js +3 -2
- package/packages/datadog-plugin-ws/src/close.js +3 -5
- package/packages/datadog-plugin-ws/src/producer.js +1 -4
- package/packages/datadog-plugin-ws/src/receiver.js +3 -5
- package/packages/datadog-plugin-ws/src/server.js +44 -13
- package/packages/datadog-vite/index.js +537 -0
- package/packages/datadog-vite/src/log.js +5 -0
- package/packages/datadog-webpack/src/log.js +2 -29
- 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/index.js +1 -1
- package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
- 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/blocking/index.js +17 -1
- package/packages/dd-trace/src/appsec/channels.js +8 -0
- package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
- package/packages/dd-trace/src/appsec/graphql.js +10 -13
- package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
- package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
- package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
- package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +21 -14
- package/packages/dd-trace/src/appsec/index.js +9 -0
- package/packages/dd-trace/src/appsec/lambda.js +17 -17
- package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
- package/packages/dd-trace/src/appsec/rasp/index.js +64 -3
- package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
- package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
- package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
- package/packages/dd-trace/src/appsec/rasp/utils.js +47 -3
- package/packages/dd-trace/src/appsec/recommended.json +70 -3
- package/packages/dd-trace/src/appsec/reporter.js +9 -0
- package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
- package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
- package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
- package/packages/dd-trace/src/appsec/waf/index.js +65 -6
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
- 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 +14 -5
- package/packages/dd-trace/src/config/index.js +73 -27
- package/packages/dd-trace/src/config/parsers.js +60 -0
- package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
- package/packages/dd-trace/src/config/remote_config.js +2 -1
- package/packages/dd-trace/src/config/supported-configurations.json +41 -13
- package/packages/dd-trace/src/datastreams/fnv.js +27 -0
- 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 +142 -28
- package/packages/dd-trace/src/datastreams/processor.js +27 -7
- package/packages/dd-trace/src/debugger/config.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
- package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
- package/packages/dd-trace/src/debugger/index.js +2 -2
- package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +4 -1
- package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
- package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
- package/packages/dd-trace/src/git_metadata.js +2 -1
- package/packages/dd-trace/src/index.js +6 -3
- package/packages/dd-trace/src/lambda/facade.js +6 -5
- 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 +86 -3
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +182 -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/agentless_configuration_source.js +3 -0
- package/packages/dd-trace/src/openfeature/configuration_source.js +20 -0
- 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/ci_plugin.js +104 -9
- package/packages/dd-trace/src/plugins/index.js +2 -0
- package/packages/dd-trace/src/plugins/util/ci.js +34 -0
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +9 -14
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +3 -5
- package/packages/dd-trace/src/plugins/util/test.js +28 -1
- package/packages/dd-trace/src/plugins/util/url.js +9 -6
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +4 -4
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiler.js +74 -12
- package/packages/dd-trace/src/profiling/profiler.js +30 -2
- package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
- package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
- package/packages/dd-trace/src/profiling/remote-config.js +354 -0
- package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
- package/packages/dd-trace/src/propagation-hash/index.js +7 -0
- package/packages/dd-trace/src/proxy.js +13 -1
- package/packages/dd-trace/src/register-loader.js +43 -0
- package/register.js +10 -44
- package/register.mjs +27 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +11 -0
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vite.d.ts +7 -0
- package/vite.js +3 -0
- package/lambda.d.ts +0 -39
- package/lambda.js +0 -3
- package/packages/datadog-plugin-cypress/src/support.js +0 -1348
|
@@ -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'
|
|
@@ -61,8 +69,83 @@ class McpListToolsLLMObsPlugin extends LLMObsPlugin {
|
|
|
61
69
|
const span = ctx.currentStore?.span
|
|
62
70
|
if (!span || ctx.error) return
|
|
63
71
|
|
|
64
|
-
this._tagger.tagTextIO(span, null,
|
|
72
|
+
this._tagger.tagTextIO(span, null, safeStringify(ctx.result))
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
|
|
68
|
-
|
|
76
|
+
class McpServerRequestLLMObsPlugin extends LLMObsPlugin {
|
|
77
|
+
static id = 'llmobs_mcp_server_request'
|
|
78
|
+
static integration = 'modelcontextprotocol-sdk'
|
|
79
|
+
static prefix = 'tracing:apm:mcp:server:request'
|
|
80
|
+
|
|
81
|
+
getLLMObsSpanRegisterOptions (ctx) {
|
|
82
|
+
const { request } = ctx
|
|
83
|
+
if (request?.method === 'tools/call') {
|
|
84
|
+
return { kind: 'tool', name: request.params?.name || 'unknown_tool' }
|
|
85
|
+
}
|
|
86
|
+
return { kind: 'task', name: `mcp.${request?.method ?? 'unknown'}` }
|
|
87
|
+
}
|
|
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
|
+
|
|
111
|
+
setLLMObsTags (ctx) {
|
|
112
|
+
const span = ctx.currentStore?.span
|
|
113
|
+
if (!span) return
|
|
114
|
+
|
|
115
|
+
if (ctx.llmobs?.intent) this._tagger.tagIntent(span, ctx.llmobs.intent)
|
|
116
|
+
|
|
117
|
+
const { request, extra, server } = ctx
|
|
118
|
+
const spanTags = {
|
|
119
|
+
mcp_method: request?.method,
|
|
120
|
+
...getClientInfoTags(extra?.mcpReq?.envelope, server),
|
|
121
|
+
}
|
|
122
|
+
const sessionId = extra?.sessionId ?? server?.transport?.sessionId
|
|
123
|
+
if (sessionId) spanTags.mcp_session_id = String(sessionId)
|
|
124
|
+
if (request?.method === 'tools/call') {
|
|
125
|
+
spanTags.mcp_tool = request.params?.name || 'unknown_tool'
|
|
126
|
+
spanTags.mcp_tool_kind = 'server'
|
|
127
|
+
}
|
|
128
|
+
this._tagger.tagSpanTags(span, spanTags)
|
|
129
|
+
|
|
130
|
+
const output = ctx.error ? undefined : safeStringify(ctx.result)
|
|
131
|
+
this._tagger.tagTextIO(span, formatServerInput(request, extra?.mcpReq), output)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
class McpToolCallV2LLMObsPlugin extends McpToolCallLLMObsPlugin {
|
|
136
|
+
static id = 'llmobs_mcp_tool_call_v2'
|
|
137
|
+
static prefix = 'tracing:orchestrion:@modelcontextprotocol/client:Client_callTool'
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
class McpListToolsV2LLMObsPlugin extends McpListToolsLLMObsPlugin {
|
|
141
|
+
static id = 'llmobs_mcp_list_tools_v2'
|
|
142
|
+
static prefix = 'tracing:orchestrion:@modelcontextprotocol/client:Client_listTools'
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports = [
|
|
146
|
+
McpToolCallLLMObsPlugin,
|
|
147
|
+
McpListToolsLLMObsPlugin,
|
|
148
|
+
McpToolCallV2LLMObsPlugin,
|
|
149
|
+
McpListToolsV2LLMObsPlugin,
|
|
150
|
+
McpServerRequestLLMObsPlugin,
|
|
151
|
+
]
|
|
@@ -52,4 +52,185 @@ function formatOutput (result) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const DISTRIBUTED_TRACE_META_KEY = '_dd_trace_context'
|
|
56
|
+
const CLIENT_INFO_META_KEY = 'io.modelcontextprotocol/clientInfo'
|
|
57
|
+
const MAX_CLIENT_INFO_TAG_LENGTH = 256
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {unknown} value
|
|
61
|
+
*/
|
|
62
|
+
function safeStringify (value) {
|
|
63
|
+
if (value === undefined) return
|
|
64
|
+
try {
|
|
65
|
+
return JSON.stringify(value)
|
|
66
|
+
} catch {}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Copies `_meta` keys except the trace context.
|
|
71
|
+
* @param {Record<string, unknown>} target
|
|
72
|
+
* @param {Record<string, unknown>} [source]
|
|
73
|
+
*/
|
|
74
|
+
function copyMetaKeys (target, source) {
|
|
75
|
+
if (!source) return false
|
|
76
|
+
|
|
77
|
+
let copied = false
|
|
78
|
+
for (const key of Object.keys(source)) {
|
|
79
|
+
if (key === DISTRIBUTED_TRACE_META_KEY) continue
|
|
80
|
+
target[key] = source[key]
|
|
81
|
+
copied = true
|
|
82
|
+
}
|
|
83
|
+
return copied
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Formats a server request as JSON-RPC without the trace context. Before a handler runs, SDK 2.x moves the reserved
|
|
88
|
+
* `io.modelcontextprotocol/*` `_meta` keys into `mcpReq.envelope` and drops the JSON-RPC id. Both are put back, so the
|
|
89
|
+
* input matches the request that the client sent.
|
|
90
|
+
* @param {{ method?: string, id?: string|number, params?: { _meta?: Record<string, unknown> } }} [request]
|
|
91
|
+
* @param {{ id?: string|number, envelope?: Record<string, unknown> }} [mcpReq]
|
|
92
|
+
*/
|
|
93
|
+
function formatServerInput (request, mcpReq) {
|
|
94
|
+
let params = request?.params
|
|
95
|
+
const meta = {}
|
|
96
|
+
const hasEnvelopeKeys = copyMetaKeys(meta, mcpReq?.envelope)
|
|
97
|
+
const hasRequestKeys = copyMetaKeys(meta, params?._meta)
|
|
98
|
+
|
|
99
|
+
const rest = {}
|
|
100
|
+
let hasRest = false
|
|
101
|
+
if (params) {
|
|
102
|
+
for (const [key, value] of Object.entries(params)) {
|
|
103
|
+
if (key === '_meta') continue
|
|
104
|
+
rest[key] = value
|
|
105
|
+
hasRest = true
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (hasEnvelopeKeys || hasRequestKeys) {
|
|
109
|
+
params = { ...rest, _meta: meta }
|
|
110
|
+
} else if (params?._meta !== undefined) {
|
|
111
|
+
// `_meta` held only the trace context that the client tracer added, so drop `params` if nothing else is left.
|
|
112
|
+
params = hasRest ? rest : undefined
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return safeStringify({ method: request?.method, params, jsonrpc: '2.0', id: request?.id ?? mcpReq?.id })
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Client identity comes from the request envelope on stateless requests and from the handshake otherwise.
|
|
120
|
+
* @param {Record<string, unknown>} [envelope]
|
|
121
|
+
* @param {{ getClientVersion?: () => unknown }} [server]
|
|
122
|
+
*/
|
|
123
|
+
function getClientInfoTags (envelope, server) {
|
|
124
|
+
const clientInfo = envelope?.[CLIENT_INFO_META_KEY] ?? server?.getClientVersion?.()
|
|
125
|
+
const tags = {}
|
|
126
|
+
if (!clientInfo || typeof clientInfo !== 'object') return tags
|
|
127
|
+
|
|
128
|
+
for (const field of ['name', 'title', 'version']) {
|
|
129
|
+
const value = clientInfo[field]
|
|
130
|
+
if (value) tags[`mcp_client_${field}`] = String(value).slice(0, MAX_CLIENT_INFO_TAG_LENGTH)
|
|
131
|
+
}
|
|
132
|
+
return tags
|
|
133
|
+
}
|
|
134
|
+
|
|
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
|
}
|
|
@@ -26,6 +26,7 @@ const POLL_FAILED_WITHOUT_CONFIGURATION = 'Feature Flags: agentless configuratio
|
|
|
26
26
|
* @property {number} requestTimeoutMs
|
|
27
27
|
* @property {string | undefined} apiKey
|
|
28
28
|
* @property {string | undefined} env
|
|
29
|
+
* @property {string | undefined} service
|
|
29
30
|
*/
|
|
30
31
|
|
|
31
32
|
/**
|
|
@@ -163,6 +164,8 @@ class AgentlessConfigurationSource {
|
|
|
163
164
|
const headers = getClientLibraryHeaders()
|
|
164
165
|
headers['Accept-Encoding'] = 'gzip'
|
|
165
166
|
if (this.#config.apiKey) headers['DD-API-KEY'] = this.#config.apiKey
|
|
167
|
+
// The CDN uses this header to attribute the usage of this request to the service.
|
|
168
|
+
if (this.#config.service) headers['DD-Service'] = this.#config.service
|
|
166
169
|
if (this.#etag) headers['If-None-Match'] = this.#etag
|
|
167
170
|
|
|
168
171
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { normalizeService } = require('../config/normalize-service')
|
|
3
4
|
const { createSiteUrl } = require('../exporters/common/url')
|
|
4
5
|
const log = require('../log')
|
|
5
6
|
const { warnRemoteConfigFlagSelection, withFlagSelection } = require('./flag-selection')
|
|
@@ -11,6 +12,8 @@ const AGENTLESS_START_MESSAGE = 'Feature Flags: starting agentless configuration
|
|
|
11
12
|
const REMOTE_CONFIG_DISABLED_WARNING = 'Feature Flags: configuration source is remote_config but Remote ' +
|
|
12
13
|
'Configuration is disabled; flag evaluations will return their default values. Set ' +
|
|
13
14
|
'DD_REMOTE_CONFIGURATION_ENABLED=true or DD_FEATURE_FLAGS_CONFIGURATION_SOURCE=agentless'
|
|
15
|
+
const USAGE_SERVICE_REJECTED_MESSAGE =
|
|
16
|
+
'Feature Flags: service %s has no normalized name; DD-Service header not sent'
|
|
14
17
|
const MISSING_API_KEY_MESSAGE = 'DD_API_KEY is required for the default Datadog Feature Flagging endpoint; ' +
|
|
15
18
|
'set DD_API_KEY, set DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL, or set ' +
|
|
16
19
|
'DD_FEATURE_FLAGS_CONFIGURATION_SOURCE=remote_config to load flags through the Datadog Agent'
|
|
@@ -73,6 +76,7 @@ function create (config, applyConfiguration) {
|
|
|
73
76
|
requestTimeoutMs: requestTimeoutSeconds * 1000,
|
|
74
77
|
apiKey: hasCustomEndpoint ? undefined : config.DD_API_KEY,
|
|
75
78
|
env: config.env,
|
|
79
|
+
service: usageService(config.service),
|
|
76
80
|
}, applyConfiguration)
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -115,6 +119,22 @@ function endpoint (config, configuredBaseUrl) {
|
|
|
115
119
|
return url
|
|
116
120
|
}
|
|
117
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Selects the DD-Service value: the tracer service, normalized with the same function as the inferred service. For
|
|
124
|
+
* example, `My Service` becomes `my_service`.
|
|
125
|
+
*
|
|
126
|
+
* If nothing is left of the normalized name, no value is sent. The normalized name has only ASCII characters, so
|
|
127
|
+
* Node.js cannot throw on the header. The tracer service itself does not change. The CDN alone decides which values it
|
|
128
|
+
* uses.
|
|
129
|
+
*
|
|
130
|
+
* @param {string | undefined} service - Tracer service name.
|
|
131
|
+
*/
|
|
132
|
+
function usageService (service) {
|
|
133
|
+
const name = normalizeService(service)
|
|
134
|
+
if (service && !name) log.debug(USAGE_SERVICE_REJECTED_MESSAGE, service)
|
|
135
|
+
return name || undefined
|
|
136
|
+
}
|
|
137
|
+
|
|
118
138
|
/**
|
|
119
139
|
* Drops everything but the origin; a custom base URL may embed a signed token in its path.
|
|
120
140
|
*
|
|
@@ -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
|
/**
|