dd-trace 5.79.0 → 5.81.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/LICENSE-3rdparty.csv +79 -87
- package/ext/tags.d.ts +1 -0
- package/ext/tags.js +1 -0
- package/index.d.ts +46 -39
- package/initialize.mjs +10 -10
- package/loader-hook.mjs +10 -3
- package/package.json +23 -40
- package/packages/datadog-core/src/storage.js +4 -4
- package/packages/datadog-esbuild/index.js +36 -19
- package/packages/datadog-esbuild/src/utils.js +5 -1
- package/packages/datadog-instrumentations/index.js +1 -0
- package/packages/datadog-instrumentations/src/anthropic.js +12 -0
- package/packages/datadog-instrumentations/src/aws-sdk.js +13 -2
- package/packages/datadog-instrumentations/src/azure-service-bus.js +43 -36
- package/packages/datadog-instrumentations/src/cucumber.js +2 -2
- package/packages/datadog-instrumentations/src/find-my-way.js +6 -5
- package/packages/datadog-instrumentations/src/google-genai.js +120 -0
- package/packages/datadog-instrumentations/src/graphql.js +20 -0
- package/packages/datadog-instrumentations/src/helpers/hook.js +1 -0
- package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
- package/packages/datadog-instrumentations/src/helpers/instrument.js +12 -1
- package/packages/datadog-instrumentations/src/helpers/register.js +6 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +27 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +152 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +5 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langchain.js +237 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/loader.js +9 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +11 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +139 -0
- package/packages/datadog-instrumentations/src/jest.js +1 -1
- package/packages/datadog-instrumentations/src/langchain.js +3 -109
- package/packages/datadog-instrumentations/src/mocha/main.js +1 -1
- package/packages/datadog-instrumentations/src/mysql2.js +1 -1
- package/packages/datadog-instrumentations/src/playwright.js +65 -16
- package/packages/datadog-instrumentations/src/router.js +1 -1
- package/packages/datadog-instrumentations/src/selenium.js +3 -1
- package/packages/datadog-instrumentations/src/ws.js +35 -17
- package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +3 -2
- package/packages/datadog-plugin-azure-service-bus/src/producer.js +14 -5
- package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +1 -1
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +23 -2
- package/packages/datadog-plugin-cypress/src/plugin.js +1 -1
- package/packages/datadog-plugin-cypress/src/support.js +73 -31
- package/packages/datadog-plugin-google-genai/src/index.js +17 -0
- package/packages/datadog-plugin-google-genai/src/tracing.js +41 -0
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +5 -4
- package/packages/datadog-plugin-jest/src/util.js +4 -3
- package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -1
- package/packages/datadog-plugin-kafkajs/src/producer.js +3 -1
- package/packages/datadog-plugin-langchain/src/tracing.js +7 -3
- package/packages/datadog-plugin-next/src/index.js +11 -3
- package/packages/datadog-plugin-openai/src/stream-helpers.js +1 -1
- package/packages/datadog-shimmer/src/shimmer.js +2 -2
- package/packages/dd-trace/src/aiguard/sdk.js +29 -14
- package/packages/dd-trace/src/appsec/api_security_sampler.js +1 -1
- package/packages/dd-trace/src/appsec/iast/overhead-controller.js +1 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +1 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +1 -2
- package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
- package/packages/dd-trace/src/appsec/reporter.js +0 -4
- package/packages/dd-trace/src/baggage.js +11 -0
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +4 -8
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +1 -1
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +4 -2
- package/packages/dd-trace/src/config.js +81 -7
- package/packages/dd-trace/src/config_defaults.js +15 -2
- package/packages/dd-trace/src/datastreams/encoding.js +23 -6
- package/packages/dd-trace/src/datastreams/pathway.js +40 -1
- package/packages/dd-trace/src/datastreams/processor.js +1 -1
- package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +15 -5
- package/packages/dd-trace/src/debugger/devtools_client/condition.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/config.js +2 -0
- package/packages/dd-trace/src/debugger/devtools_client/index.js +30 -15
- package/packages/dd-trace/src/debugger/devtools_client/inspector_promises_polyfill.js +2 -0
- package/packages/dd-trace/src/debugger/devtools_client/json-buffer.js +24 -18
- package/packages/dd-trace/src/debugger/devtools_client/send.js +18 -8
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +103 -15
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/constants.js +25 -0
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +56 -25
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +64 -23
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/symbols.js +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +404 -0
- package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/state.js +7 -2
- package/packages/dd-trace/src/debugger/devtools_client/status.js +1 -1
- package/packages/dd-trace/src/debugger/index.js +1 -1
- package/packages/dd-trace/src/encode/0.4.js +3 -3
- package/packages/dd-trace/src/encode/coverage-ci-visibility.js +2 -2
- package/packages/dd-trace/src/encode/span-stats.js +7 -1
- package/packages/dd-trace/src/exporters/agent/writer.js +6 -13
- package/packages/dd-trace/src/histogram.js +1 -1
- package/packages/dd-trace/src/id.js +60 -0
- package/packages/dd-trace/src/lambda/runtime/ritm.js +2 -3
- package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
- package/packages/dd-trace/src/llmobs/index.js +5 -5
- package/packages/dd-trace/src/llmobs/noop.js +6 -0
- package/packages/dd-trace/src/llmobs/plugins/ai/index.js +1 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/index.js +104 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +486 -0
- package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +2 -2
- package/packages/dd-trace/src/llmobs/plugins/{openai.js → openai/index.js} +87 -39
- package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +114 -0
- package/packages/dd-trace/src/llmobs/sdk.js +10 -1
- package/packages/dd-trace/src/llmobs/span_processor.js +11 -6
- package/packages/dd-trace/src/llmobs/tagger.js +35 -17
- package/packages/dd-trace/src/msgpack/chunk.js +2 -2
- package/packages/dd-trace/src/msgpack/encoder.js +2 -3
- package/packages/dd-trace/src/msgpack/index.js +2 -2
- package/packages/dd-trace/src/openfeature/flagging_provider.js +5 -3
- package/packages/dd-trace/src/opentelemetry/logs/index.js +3 -3
- package/packages/dd-trace/src/opentelemetry/logs/logger.js +14 -8
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +6 -4
- package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +9 -17
- package/packages/dd-trace/src/opentelemetry/metrics/constants.js +34 -0
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +81 -0
- package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +225 -0
- package/packages/dd-trace/src/opentelemetry/metrics/meter.js +171 -0
- package/packages/dd-trace/src/opentelemetry/metrics/meter_provider.js +54 -0
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +62 -0
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +251 -0
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +532 -0
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +10 -18
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +36 -22
- package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +2 -2
- package/packages/dd-trace/src/opentelemetry/span.js +1 -1
- package/packages/dd-trace/src/opentelemetry/tracer.js +1 -1
- package/packages/dd-trace/src/opentelemetry/tracer_provider.js +1 -1
- package/packages/dd-trace/src/payload-tagging/index.js +2 -2
- package/packages/dd-trace/src/plugin_manager.js +4 -2
- package/packages/dd-trace/src/plugins/database.js +1 -0
- package/packages/dd-trace/src/plugins/index.js +1 -0
- package/packages/dd-trace/src/plugins/plugin.js +7 -9
- package/packages/dd-trace/src/plugins/util/test.js +3 -3
- package/packages/dd-trace/src/plugins/util/url.js +119 -1
- package/packages/dd-trace/src/plugins/util/web.js +10 -41
- package/packages/dd-trace/src/process-tags/index.js +81 -0
- package/packages/dd-trace/src/profiling/config.js +1 -1
- package/packages/dd-trace/src/profiling/exporter_cli.js +7 -6
- package/packages/dd-trace/src/profiling/exporters/agent.js +1 -1
- package/packages/dd-trace/src/profiling/profilers/events.js +10 -1
- package/packages/dd-trace/src/proxy.js +5 -0
- package/packages/dd-trace/src/rate_limiter.js +1 -1
- package/packages/dd-trace/src/remote_config/manager.js +1 -1
- package/packages/dd-trace/src/require-package-json.js +1 -1
- package/packages/dd-trace/src/ritm.js +1 -1
- package/packages/dd-trace/src/service-naming/index.js +31 -4
- package/packages/dd-trace/src/service-naming/schemas/v0/web.js +4 -0
- package/packages/dd-trace/src/service-naming/schemas/v1/web.js +4 -0
- package/packages/dd-trace/src/{format.js → span_format.js} +9 -4
- package/packages/dd-trace/src/span_processor.js +16 -11
- package/packages/dd-trace/src/span_stats.js +15 -4
- package/packages/dd-trace/src/spanleak.js +1 -1
- package/packages/dd-trace/src/supported-configurations.json +13 -0
- package/packages/dd-trace/src/telemetry/dependencies.js +1 -1
- package/packages/dd-trace/src/telemetry/telemetry.js +11 -2
- package/vendor/dist/@datadog/sketches-js/LICENSE +39 -0
- package/vendor/dist/@datadog/sketches-js/index.js +1 -0
- package/vendor/dist/@datadog/source-map/LICENSE +28 -0
- package/vendor/dist/@datadog/source-map/index.js +1 -0
- package/vendor/dist/@isaacs/ttlcache/LICENSE +55 -0
- package/vendor/dist/@isaacs/ttlcache/index.js +1 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +201 -0
- package/vendor/dist/@opentelemetry/core/index.js +1 -0
- package/vendor/dist/@opentelemetry/resources/LICENSE +201 -0
- package/vendor/dist/@opentelemetry/resources/index.js +1 -0
- package/vendor/dist/astring/LICENSE +19 -0
- package/vendor/dist/astring/index.js +1 -0
- package/vendor/dist/crypto-randomuuid/index.js +1 -0
- package/vendor/dist/escape-string-regexp/LICENSE +9 -0
- package/vendor/dist/escape-string-regexp/index.js +1 -0
- package/vendor/dist/esquery/LICENSE +24 -0
- package/vendor/dist/esquery/index.js +1 -0
- package/vendor/dist/ignore/LICENSE +21 -0
- package/vendor/dist/ignore/index.js +1 -0
- package/vendor/dist/istanbul-lib-coverage/LICENSE +24 -0
- package/vendor/dist/istanbul-lib-coverage/index.js +1 -0
- package/vendor/dist/jest-docblock/LICENSE +21 -0
- package/vendor/dist/jest-docblock/index.js +1 -0
- package/vendor/dist/jsonpath-plus/LICENSE +22 -0
- package/vendor/dist/jsonpath-plus/index.js +1 -0
- package/vendor/dist/limiter/LICENSE +19 -0
- package/vendor/dist/limiter/index.js +1 -0
- package/vendor/dist/lodash.sortby/LICENSE +47 -0
- package/vendor/dist/lodash.sortby/index.js +1 -0
- package/vendor/dist/lru-cache/LICENSE +15 -0
- package/vendor/dist/lru-cache/index.js +1 -0
- package/vendor/dist/meriyah/LICENSE +7 -0
- package/vendor/dist/meriyah/index.js +1 -0
- package/vendor/dist/module-details-from-path/LICENSE +21 -0
- package/vendor/dist/module-details-from-path/index.js +1 -0
- package/vendor/dist/mutexify/promise/LICENSE +21 -0
- package/vendor/dist/mutexify/promise/index.js +1 -0
- package/vendor/dist/opentracing/LICENSE +201 -0
- package/vendor/dist/opentracing/binary_carrier.d.ts +11 -0
- package/vendor/dist/opentracing/constants.d.ts +61 -0
- package/vendor/dist/opentracing/examples/demo/demo.d.ts +2 -0
- package/vendor/dist/opentracing/ext/tags.d.ts +90 -0
- package/vendor/dist/opentracing/functions.d.ts +20 -0
- package/vendor/dist/opentracing/global_tracer.d.ts +14 -0
- package/vendor/dist/opentracing/index.d.ts +12 -0
- package/vendor/dist/opentracing/index.js +1 -0
- package/vendor/dist/opentracing/mock_tracer/index.d.ts +5 -0
- package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +13 -0
- package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +16 -0
- package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +50 -0
- package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +26 -0
- package/vendor/dist/opentracing/noop.d.ts +8 -0
- package/vendor/dist/opentracing/reference.d.ts +33 -0
- package/vendor/dist/opentracing/span.d.ts +147 -0
- package/vendor/dist/opentracing/span_context.d.ts +26 -0
- package/vendor/dist/opentracing/test/api_compatibility.d.ts +16 -0
- package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +3 -0
- package/vendor/dist/opentracing/test/noop_implementation.d.ts +4 -0
- package/vendor/dist/opentracing/test/opentracing_api.d.ts +3 -0
- package/vendor/dist/opentracing/test/unittest.d.ts +2 -0
- package/vendor/dist/opentracing/tracer.d.ts +127 -0
- package/vendor/dist/path-to-regexp/LICENSE +21 -0
- package/vendor/dist/path-to-regexp/index.js +1 -0
- package/vendor/dist/pprof-format/LICENSE +8 -0
- package/vendor/dist/pprof-format/index.js +1 -0
- package/vendor/dist/protobufjs/LICENSE +39 -0
- package/vendor/dist/protobufjs/index.js +1 -0
- package/vendor/dist/protobufjs/minimal/LICENSE +39 -0
- package/vendor/dist/protobufjs/minimal/index.js +1 -0
- package/vendor/dist/retry/LICENSE +21 -0
- package/vendor/dist/retry/index.js +1 -0
- package/vendor/dist/rfdc/LICENSE +15 -0
- package/vendor/dist/rfdc/index.js +1 -0
- package/vendor/dist/semifies/LICENSE +201 -0
- package/vendor/dist/semifies/index.js +1 -0
- package/vendor/dist/shell-quote/LICENSE +24 -0
- package/vendor/dist/shell-quote/index.js +1 -0
- package/vendor/dist/source-map/LICENSE +28 -0
- package/vendor/dist/source-map/index.js +1 -0
- package/vendor/dist/source-map/lib/util/LICENSE +28 -0
- package/vendor/dist/source-map/lib/util/index.js +1 -0
- package/vendor/dist/source-map/mappings.wasm +0 -0
- package/vendor/dist/tlhunter-sorted-set/LICENSE +21 -0
- package/vendor/dist/tlhunter-sorted-set/index.js +1 -0
- package/vendor/dist/ttl-set/LICENSE +21 -0
- package/vendor/dist/ttl-set/index.js +1 -0
|
@@ -14,26 +14,43 @@ let batch = 0
|
|
|
14
14
|
|
|
15
15
|
// Internal representation of a trace or span ID.
|
|
16
16
|
class Identifier {
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} value
|
|
19
|
+
* @param {number} [radix]
|
|
20
|
+
*/
|
|
17
21
|
constructor (value, radix = 16) {
|
|
18
22
|
this._buffer = radix === 16
|
|
19
23
|
? createBuffer(value)
|
|
20
24
|
: fromString(value, radix)
|
|
21
25
|
}
|
|
22
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @param {number} [radix]
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
23
31
|
toString (radix = 16) {
|
|
24
32
|
return radix === 16
|
|
25
33
|
? toHexString(this._buffer)
|
|
26
34
|
: toNumberString(this._buffer, radix)
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @returns {bigint}
|
|
39
|
+
*/
|
|
29
40
|
toBigInt () {
|
|
30
41
|
return Buffer.from(this._buffer).readBigUInt64BE(0)
|
|
31
42
|
}
|
|
32
43
|
|
|
44
|
+
/**
|
|
45
|
+
* @returns {number[] | Uint8Array}
|
|
46
|
+
*/
|
|
33
47
|
toBuffer () {
|
|
34
48
|
return this._buffer
|
|
35
49
|
}
|
|
36
50
|
|
|
51
|
+
/**
|
|
52
|
+
* @returns {number[] | Uint8Array}
|
|
53
|
+
*/
|
|
37
54
|
toArray () {
|
|
38
55
|
if (this._buffer.length === 8) {
|
|
39
56
|
return this._buffer
|
|
@@ -41,10 +58,17 @@ class Identifier {
|
|
|
41
58
|
return this._buffer.slice(-8)
|
|
42
59
|
}
|
|
43
60
|
|
|
61
|
+
/**
|
|
62
|
+
* @returns {string}
|
|
63
|
+
*/
|
|
44
64
|
toJSON () {
|
|
45
65
|
return this.toString()
|
|
46
66
|
}
|
|
47
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @param {Identifier} other
|
|
70
|
+
* @returns {boolean}
|
|
71
|
+
*/
|
|
48
72
|
equals (other) {
|
|
49
73
|
const length = this._buffer.length
|
|
50
74
|
const otherLength = other._buffer.length
|
|
@@ -59,6 +83,10 @@ class Identifier {
|
|
|
59
83
|
}
|
|
60
84
|
|
|
61
85
|
// Create a buffer, using an optional hexadecimal value if provided.
|
|
86
|
+
/**
|
|
87
|
+
* @param {string} value
|
|
88
|
+
* @returns {number[] | Uint8Array}
|
|
89
|
+
*/
|
|
62
90
|
function createBuffer (value) {
|
|
63
91
|
if (value === '0') return zeroId
|
|
64
92
|
if (!value) return pseudoRandom()
|
|
@@ -77,6 +105,11 @@ function createBuffer (value) {
|
|
|
77
105
|
}
|
|
78
106
|
|
|
79
107
|
// Convert a numerical string to a buffer using the specified radix.
|
|
108
|
+
/**
|
|
109
|
+
* @param {string} str
|
|
110
|
+
* @param {number} raddix
|
|
111
|
+
* @returns {number[]}
|
|
112
|
+
*/
|
|
80
113
|
function fromString (str, raddix) {
|
|
81
114
|
const buffer = new Array(8)
|
|
82
115
|
const len = str.length
|
|
@@ -116,6 +149,11 @@ function fromString (str, raddix) {
|
|
|
116
149
|
}
|
|
117
150
|
|
|
118
151
|
// Convert a buffer to a numerical string.
|
|
152
|
+
/**
|
|
153
|
+
* @param {number[] | Uint8Array} buffer
|
|
154
|
+
* @param {number} [radix]
|
|
155
|
+
* @returns {string}
|
|
156
|
+
*/
|
|
119
157
|
function toNumberString (buffer, radix) {
|
|
120
158
|
let high = readInt32(buffer, buffer.length - 8)
|
|
121
159
|
let low = readInt32(buffer, buffer.length - 4)
|
|
@@ -137,11 +175,18 @@ function toNumberString (buffer, radix) {
|
|
|
137
175
|
}
|
|
138
176
|
|
|
139
177
|
// Convert a buffer to a hexadecimal string.
|
|
178
|
+
/**
|
|
179
|
+
* @param {number[] | Uint8Array} buffer
|
|
180
|
+
* @returns {string}
|
|
181
|
+
*/
|
|
140
182
|
function toHexString (buffer) {
|
|
141
183
|
return map.call(buffer, pad).join('')
|
|
142
184
|
}
|
|
143
185
|
|
|
144
186
|
// Simple pseudo-random 64-bit ID generator.
|
|
187
|
+
/**
|
|
188
|
+
* @returns {number[] | Uint8Array}
|
|
189
|
+
*/
|
|
145
190
|
function pseudoRandom () {
|
|
146
191
|
if (batch === 0) {
|
|
147
192
|
randomFillSync(data)
|
|
@@ -164,6 +209,11 @@ function pseudoRandom () {
|
|
|
164
209
|
}
|
|
165
210
|
|
|
166
211
|
// Read a buffer to unsigned integer bytes.
|
|
212
|
+
/**
|
|
213
|
+
* @param {number[] | Uint8Array} buffer
|
|
214
|
+
* @param {number} offset
|
|
215
|
+
* @returns {number}
|
|
216
|
+
*/
|
|
167
217
|
function readInt32 (buffer, offset) {
|
|
168
218
|
return (buffer[offset + 0] * 16_777_216) +
|
|
169
219
|
(buffer[offset + 1] << 16) +
|
|
@@ -172,6 +222,11 @@ function readInt32 (buffer, offset) {
|
|
|
172
222
|
}
|
|
173
223
|
|
|
174
224
|
// Write unsigned integer bytes to a buffer.
|
|
225
|
+
/**
|
|
226
|
+
* @param {number[] | Uint8Array} buffer
|
|
227
|
+
* @param {number} value
|
|
228
|
+
* @param {number} offset
|
|
229
|
+
*/
|
|
175
230
|
function writeUInt32BE (buffer, value, offset) {
|
|
176
231
|
buffer[3 + offset] = value & 255
|
|
177
232
|
value >>= 8
|
|
@@ -182,6 +237,11 @@ function writeUInt32BE (buffer, value, offset) {
|
|
|
182
237
|
buffer[0 + offset] = value & 255
|
|
183
238
|
}
|
|
184
239
|
|
|
240
|
+
/**
|
|
241
|
+
* @param {string} value
|
|
242
|
+
* @param {number} [radix]
|
|
243
|
+
* @returns {Identifier}
|
|
244
|
+
*/
|
|
185
245
|
module.exports = function createIdentifier (value, radix) {
|
|
186
246
|
return new Identifier(value, radix)
|
|
187
247
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Modifications copyright 2022 Datadog, Inc.
|
|
4
4
|
*
|
|
5
5
|
* Some functions are part of aws-lambda-nodejs-runtime-interface-client
|
|
6
|
-
* https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/
|
|
6
|
+
* https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/v2.1.0/src/utils/UserFunction.ts
|
|
7
7
|
*/
|
|
8
8
|
'use strict'
|
|
9
9
|
|
|
@@ -53,8 +53,7 @@ function _extractModuleNameAndHandlerPath (handler) {
|
|
|
53
53
|
const FUNCTION_EXPR = /^([^.]*)\.(.*)$/
|
|
54
54
|
const match = handler.match(FUNCTION_EXPR)
|
|
55
55
|
if (!match || match.length !== 3) {
|
|
56
|
-
|
|
57
|
-
return // TODO: throw error
|
|
56
|
+
throw new Error(`Malformed handler name: ${handler}`)
|
|
58
57
|
}
|
|
59
58
|
return [match[1], match[2]] // [module, handler-path]
|
|
60
59
|
}
|
|
@@ -34,6 +34,7 @@ module.exports = {
|
|
|
34
34
|
TOTAL_TOKENS_METRIC_KEY: 'total_tokens',
|
|
35
35
|
CACHE_READ_INPUT_TOKENS_METRIC_KEY: 'cache_read_input_tokens',
|
|
36
36
|
CACHE_WRITE_INPUT_TOKENS_METRIC_KEY: 'cache_write_input_tokens',
|
|
37
|
+
REASONING_OUTPUT_TOKENS_METRIC_KEY: 'reasoning_output_tokens',
|
|
37
38
|
|
|
38
39
|
DROPPED_IO_COLLECTION_ERROR: 'dropped_io'
|
|
39
40
|
}
|
|
@@ -12,7 +12,7 @@ const telemetry = require('./telemetry')
|
|
|
12
12
|
const LLMObsSpanProcessor = require('./span_processor')
|
|
13
13
|
|
|
14
14
|
const { channel } = require('dc-polyfill')
|
|
15
|
-
const
|
|
15
|
+
const spanFinishCh = channel('dd-trace:span:finish')
|
|
16
16
|
const evalMetricAppendCh = channel('llmobs:eval-metric:append')
|
|
17
17
|
const flushCh = channel('llmobs:writers:flush')
|
|
18
18
|
const injectCh = channel('dd-trace:span:inject')
|
|
@@ -62,7 +62,7 @@ function enable (config) {
|
|
|
62
62
|
// span processing
|
|
63
63
|
spanProcessor = new LLMObsSpanProcessor(config)
|
|
64
64
|
spanProcessor.setWriter(spanWriter)
|
|
65
|
-
|
|
65
|
+
spanFinishCh.subscribe(handleSpanProcess)
|
|
66
66
|
|
|
67
67
|
// distributed tracing for llmobs
|
|
68
68
|
injectCh.subscribe(handleLLMObsParentIdInjection)
|
|
@@ -86,7 +86,7 @@ function enable (config) {
|
|
|
86
86
|
function disable () {
|
|
87
87
|
if (evalMetricAppendCh.hasSubscribers) evalMetricAppendCh.unsubscribe(handleEvalMetricAppend)
|
|
88
88
|
if (flushCh.hasSubscribers) flushCh.unsubscribe(handleFlush)
|
|
89
|
-
if (
|
|
89
|
+
if (spanFinishCh.hasSubscribers) spanFinishCh.unsubscribe(handleSpanProcess)
|
|
90
90
|
if (injectCh.hasSubscribers) injectCh.unsubscribe(handleLLMObsParentIdInjection)
|
|
91
91
|
if (registerUserSpanProcessorCh.hasSubscribers) registerUserSpanProcessorCh.unsubscribe(handleRegisterProcessor)
|
|
92
92
|
|
|
@@ -133,8 +133,8 @@ function handleRegisterProcessor (userSpanProcessor) {
|
|
|
133
133
|
spanProcessor.setUserSpanProcessor(userSpanProcessor)
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
function handleSpanProcess (
|
|
137
|
-
spanProcessor.process(
|
|
136
|
+
function handleSpanProcess (span) {
|
|
137
|
+
spanProcessor.process(span)
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
function handleEvalMetricAppend (payload) {
|
|
@@ -75,6 +75,12 @@ class NoopLLMObs {
|
|
|
75
75
|
submitEvaluation (llmobsSpanContext, options) {}
|
|
76
76
|
|
|
77
77
|
flush () {}
|
|
78
|
+
|
|
79
|
+
registerProcessor (processor) {}
|
|
80
|
+
|
|
81
|
+
deregisterProcessor () {}
|
|
82
|
+
|
|
83
|
+
annotationContext (options, fn) { return fn() }
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
module.exports = NoopLLMObs
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const LLMObsPlugin = require('../base')
|
|
4
|
+
const {
|
|
5
|
+
getOperation,
|
|
6
|
+
extractMetrics,
|
|
7
|
+
extractMetadata,
|
|
8
|
+
aggregateStreamingChunks,
|
|
9
|
+
formatInputMessages,
|
|
10
|
+
formatEmbeddingInput,
|
|
11
|
+
formatOutputMessages,
|
|
12
|
+
formatEmbeddingOutput
|
|
13
|
+
} = require('./util')
|
|
14
|
+
|
|
15
|
+
class GenAiLLMObsPlugin extends LLMObsPlugin {
|
|
16
|
+
static id = 'google-genai'
|
|
17
|
+
static integration = 'google_genai'
|
|
18
|
+
static prefix = 'tracing:apm:google:genai:request'
|
|
19
|
+
|
|
20
|
+
constructor () {
|
|
21
|
+
super(...arguments)
|
|
22
|
+
|
|
23
|
+
// Subscribe to streaming chunk events
|
|
24
|
+
this.addSub('apm:google:genai:request:chunk', ({ ctx, chunk, done }) => {
|
|
25
|
+
ctx.isStreaming = true
|
|
26
|
+
ctx.chunks = ctx.chunks || []
|
|
27
|
+
|
|
28
|
+
if (chunk) ctx.chunks.push(chunk)
|
|
29
|
+
if (!done) return
|
|
30
|
+
|
|
31
|
+
// Aggregate streaming chunks into a single response
|
|
32
|
+
ctx.result = aggregateStreamingChunks(ctx.chunks)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getLLMObsSpanRegisterOptions (ctx) {
|
|
37
|
+
const { args, methodName } = ctx
|
|
38
|
+
if (!methodName) return
|
|
39
|
+
|
|
40
|
+
const inputs = args[0]
|
|
41
|
+
const operation = getOperation(methodName)
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
modelProvider: 'google',
|
|
45
|
+
modelName: inputs.model,
|
|
46
|
+
kind: operation,
|
|
47
|
+
name: 'google_genai.request'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setLLMObsTags (ctx) {
|
|
52
|
+
const { args, methodName } = ctx
|
|
53
|
+
const span = ctx.currentStore?.span
|
|
54
|
+
if (!methodName) return
|
|
55
|
+
|
|
56
|
+
const inputs = args[0]
|
|
57
|
+
const response = ctx.result
|
|
58
|
+
const error = !!span.context()._tags.error
|
|
59
|
+
|
|
60
|
+
const operation = getOperation(methodName)
|
|
61
|
+
|
|
62
|
+
if (operation === 'llm') {
|
|
63
|
+
this.#tagGenerateContent(span, inputs, response, error, ctx.isStreaming)
|
|
64
|
+
} else if (operation === 'embedding') {
|
|
65
|
+
this.#tagEmbedding(span, inputs, response, error)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!error && response) {
|
|
69
|
+
const metrics = extractMetrics(response)
|
|
70
|
+
this._tagger.tagMetrics(span, metrics)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#tagGenerateContent (span, inputs, response, error, isStreaming = false) {
|
|
75
|
+
const { config = {} } = inputs
|
|
76
|
+
|
|
77
|
+
const inputMessages = formatInputMessages(inputs.contents)
|
|
78
|
+
|
|
79
|
+
const metadata = extractMetadata(config)
|
|
80
|
+
this._tagger.tagMetadata(span, metadata)
|
|
81
|
+
|
|
82
|
+
if (error) {
|
|
83
|
+
this._tagger.tagLLMIO(span, inputMessages, [{ content: '' }])
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const outputMessages = formatOutputMessages(response, isStreaming)
|
|
88
|
+
this._tagger.tagLLMIO(span, inputMessages, outputMessages)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#tagEmbedding (span, inputs, response, error) {
|
|
92
|
+
const embeddingInput = formatEmbeddingInput(inputs.contents)
|
|
93
|
+
|
|
94
|
+
if (error) {
|
|
95
|
+
this._tagger.tagEmbeddingIO(span, embeddingInput)
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const embeddingOutput = formatEmbeddingOutput(response)
|
|
100
|
+
this._tagger.tagEmbeddingIO(span, embeddingInput, embeddingOutput)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = GenAiLLMObsPlugin
|