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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const TracingPlugin = require('../../dd-trace/src/plugins/tracing.js')
|
|
4
|
+
|
|
5
|
+
class GenAiTracingPlugin extends TracingPlugin {
|
|
6
|
+
static id = 'google-genai'
|
|
7
|
+
static operation = 'request'
|
|
8
|
+
static prefix = 'tracing:apm:google:genai:request'
|
|
9
|
+
|
|
10
|
+
static get type () { return 'web' }
|
|
11
|
+
static get kind () { return 'client' }
|
|
12
|
+
|
|
13
|
+
bindStart (ctx) {
|
|
14
|
+
const { args, methodName } = ctx
|
|
15
|
+
|
|
16
|
+
const inputs = args[0]
|
|
17
|
+
const model = inputs?.model || 'unknown'
|
|
18
|
+
|
|
19
|
+
this.startSpan('google_genai.request', {
|
|
20
|
+
meta: {
|
|
21
|
+
'resource.name': methodName,
|
|
22
|
+
'google_genai.request.model': model,
|
|
23
|
+
'google_genai.request.provider': 'google'
|
|
24
|
+
}
|
|
25
|
+
}, ctx)
|
|
26
|
+
|
|
27
|
+
return ctx.currentStore
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
asyncEnd (ctx) {
|
|
31
|
+
const { span } = ctx.currentStore
|
|
32
|
+
if (!span) return
|
|
33
|
+
|
|
34
|
+
if (ctx.result) {
|
|
35
|
+
span.setTag('google_genai.response.model', ctx.result.modelVersion || ctx.inputs?.model)
|
|
36
|
+
}
|
|
37
|
+
span.finish()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = GenAiTracingPlugin
|
|
@@ -5,10 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
6
|
};
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
8
|
+
const ddGlobal = globalThis[Symbol.for('dd-trace')];
|
|
9
|
+
const visitor_1 = ddGlobal.graphql_visitor;
|
|
10
|
+
const printer_1 = ddGlobal.graphql_printer;
|
|
11
|
+
const utilities_1 = ddGlobal.graphql_utilities;
|
|
12
|
+
const lodash_sortby_1 = __importDefault(require("../../../../vendor/dist/lodash.sortby"));
|
|
12
13
|
function hideLiterals(ast) {
|
|
13
14
|
return visitor_1.visit(ast, {
|
|
14
15
|
IntValue(node) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { readFileSync } = require('fs')
|
|
4
|
-
const { parse } = require('jest-docblock')
|
|
4
|
+
const { parse } = require('../../../vendor/dist/jest-docblock')
|
|
5
5
|
|
|
6
6
|
const { getTestSuitePath } = require('../../dd-trace/src/plugins/util/test')
|
|
7
7
|
const log = require('../../dd-trace/src/log')
|
|
@@ -62,6 +62,7 @@ function getJestTestName (test, shouldStripSeed = false) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const globalDocblockRegExp = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/
|
|
65
|
+
const MAX_COMMENTS_CHECKED = 10
|
|
65
66
|
|
|
66
67
|
function isMarkedAsUnskippable (test) {
|
|
67
68
|
let testSource
|
|
@@ -86,7 +87,7 @@ function isMarkedAsUnskippable (test) {
|
|
|
86
87
|
docblocks = parse(comment)
|
|
87
88
|
} catch {
|
|
88
89
|
// Skip unparsable comment and continue scanning
|
|
89
|
-
if (commentsChecked++ >=
|
|
90
|
+
if (commentsChecked++ >= MAX_COMMENTS_CHECKED) {
|
|
90
91
|
return false
|
|
91
92
|
}
|
|
92
93
|
continue
|
|
@@ -103,7 +104,7 @@ function isMarkedAsUnskippable (test) {
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
if (commentsChecked++ >=
|
|
107
|
+
if (commentsChecked++ >= MAX_COMMENTS_CHECKED) {
|
|
107
108
|
return false
|
|
108
109
|
}
|
|
109
110
|
|
|
@@ -28,7 +28,8 @@ class KafkajsConsumerPlugin extends ConsumerPlugin {
|
|
|
28
28
|
* @property {string} topic
|
|
29
29
|
* @property {number} partition
|
|
30
30
|
* @property {number} offset
|
|
31
|
-
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
32
33
|
* @typedef {object} CommitEventItem
|
|
33
34
|
* @property {string} groupId
|
|
34
35
|
* @property {string} topic
|
|
@@ -25,6 +25,8 @@ class KafkajsProducerPlugin extends ProducerPlugin {
|
|
|
25
25
|
* @property {string} topic
|
|
26
26
|
* @property {number} partition
|
|
27
27
|
* @property {number} offset
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
28
30
|
*
|
|
29
31
|
* @typedef {object} ProducerResponseItem
|
|
30
32
|
* @property {string} topic
|
|
@@ -49,7 +51,7 @@ class KafkajsProducerPlugin extends ProducerPlugin {
|
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
53
|
*
|
|
52
|
-
* @param {ProducerResponseItem[]}
|
|
54
|
+
* @param {{ result: ProducerResponseItem[] }} ctx
|
|
53
55
|
* @returns {void}
|
|
54
56
|
*/
|
|
55
57
|
commit (ctx) {
|
|
@@ -12,6 +12,8 @@ const LangChainHandler = require('./handlers/default')
|
|
|
12
12
|
const LangChainLanguageModelHandler = require('./handlers/language_models')
|
|
13
13
|
const LangChainEmbeddingHandler = require('./handlers/embedding')
|
|
14
14
|
|
|
15
|
+
const defaultNs = ['langchain', 'embeddings']
|
|
16
|
+
|
|
15
17
|
class BaseLangChainTracingPlugin extends TracingPlugin {
|
|
16
18
|
static id = 'langchain'
|
|
17
19
|
static operation = 'invoke'
|
|
@@ -36,7 +38,9 @@ class BaseLangChainTracingPlugin extends TracingPlugin {
|
|
|
36
38
|
const type = ctx.type = this.constructor.lcType
|
|
37
39
|
|
|
38
40
|
// Runnable interfaces have an `lc_namespace` property
|
|
39
|
-
const ns = ctx.self.lc_namespace ||
|
|
41
|
+
const ns = ctx.self.lc_namespace || (
|
|
42
|
+
ctx.self.constructor.name === 'OpenAIEmbeddings' ? [...defaultNs, 'openai'] : defaultNs
|
|
43
|
+
)
|
|
40
44
|
|
|
41
45
|
const resourceParts = [...ns, ctx.self.constructor.name]
|
|
42
46
|
if (type === 'tool') {
|
|
@@ -111,13 +115,13 @@ class BaseLLMGeneratePlugin extends BaseLangChainTracingPlugin {
|
|
|
111
115
|
class EmbeddingsEmbedQueryPlugin extends BaseLangChainTracingPlugin {
|
|
112
116
|
static id = 'langchain_embeddings_embed_query'
|
|
113
117
|
static lcType = 'embedding'
|
|
114
|
-
static prefix = 'tracing:
|
|
118
|
+
static prefix = 'tracing:orchestrion:@langchain/core:Embeddings_embedQuery'
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
class EmbeddingsEmbedDocumentsPlugin extends BaseLangChainTracingPlugin {
|
|
118
122
|
static id = 'langchain_embeddings_embed_documents'
|
|
119
123
|
static lcType = 'embedding'
|
|
120
|
-
static prefix = 'tracing:
|
|
124
|
+
static prefix = 'tracing:orchestrion:@langchain/core:Embeddings_embedDocuments'
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
class ToolInvokePlugin extends BaseLangChainTracingPlugin {
|
|
@@ -10,10 +10,10 @@ const errorPages = new Set(['/404', '/500', '/_error', '/_not-found', '/_not-fou
|
|
|
10
10
|
|
|
11
11
|
class NextPlugin extends ServerPlugin {
|
|
12
12
|
static id = 'next'
|
|
13
|
+
#requestsBySpanId = new WeakMap()
|
|
13
14
|
|
|
14
15
|
constructor (...args) {
|
|
15
16
|
super(...args)
|
|
16
|
-
this._requests = new WeakMap()
|
|
17
17
|
this.addSub('apm:next:page:load', message => this.pageLoad(message))
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -35,7 +35,9 @@ class NextPlugin extends ServerPlugin {
|
|
|
35
35
|
|
|
36
36
|
analyticsSampler.sample(span, this.config.measured, true)
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
// Store request by span ID to handle cases where child spans are activated
|
|
39
|
+
const spanId = span.context()._spanId
|
|
40
|
+
this.#requestsBySpanId.set(spanId, req)
|
|
39
41
|
|
|
40
42
|
return { ...store, span }
|
|
41
43
|
}
|
|
@@ -89,7 +91,13 @@ class NextPlugin extends ServerPlugin {
|
|
|
89
91
|
if (!store) return
|
|
90
92
|
|
|
91
93
|
const span = store.span
|
|
92
|
-
|
|
94
|
+
|
|
95
|
+
const spanId = span.context()._spanId
|
|
96
|
+
const parentSpanId = span.context()._parentId
|
|
97
|
+
|
|
98
|
+
// Try current span first, then parent span.
|
|
99
|
+
// This handles cases where pageLoad runs in a child span context
|
|
100
|
+
const req = this.#requestsBySpanId.get(spanId) ?? this.#requestsBySpanId.get(parentSpanId)
|
|
93
101
|
|
|
94
102
|
// safeguard against missing req in complicated timeout scenarios
|
|
95
103
|
if (!req) return
|
|
@@ -111,7 +111,7 @@ function constructChatCompletionResponseFromStreamedChunks (chunks, n) {
|
|
|
111
111
|
* Constructs the entire response from a stream of OpenAI responses chunks.
|
|
112
112
|
* The responses API uses event-based streaming with delta chunks.
|
|
113
113
|
* @param {Array<Record<string, any>>} chunks
|
|
114
|
-
* @returns {Record<string, any
|
|
114
|
+
* @returns {Record<string, any>|undefined}
|
|
115
115
|
*/
|
|
116
116
|
function constructResponseResponseFromStreamedChunks (chunks) {
|
|
117
117
|
// The responses API streams events with different types:
|
|
@@ -91,7 +91,7 @@ function wrapFunction (original, wrapper) {
|
|
|
91
91
|
* @param {Record<string | symbol, unknown> | Function | undefined} target - The target
|
|
92
92
|
* object.
|
|
93
93
|
* @param {string | symbol} name - The property key of the method to wrap.
|
|
94
|
-
* @param {(original: Function) => (...args) => any} wrapper - The wrapper function.
|
|
94
|
+
* @param {(original: Function) => (...args: unknown[]) => any} wrapper - The wrapper function.
|
|
95
95
|
* @param {{ replaceGetter?: boolean }} [options] - If `replaceGetter` is set to
|
|
96
96
|
* true, the getter is accessed and the getter is replaced with one that just
|
|
97
97
|
* returns the earlier retrieved value. Use with care! This may only be done in
|
|
@@ -214,7 +214,7 @@ function wrap (target, name, wrapper, options) {
|
|
|
214
214
|
* Record<string | symbol, unknown> |
|
|
215
215
|
* Function} targets - The target objects.
|
|
216
216
|
* @param {Array<string | symbol> | string | symbol} names - The property keys of the methods to wrap.
|
|
217
|
-
* @param {(original: Function) => (...args) => any} wrapper - The wrapper function.
|
|
217
|
+
* @param {(original: Function) => (...args: unknown[]) => any} wrapper - The wrapper function.
|
|
218
218
|
*/
|
|
219
219
|
function massWrap (targets, names, wrapper) {
|
|
220
220
|
targets = toArray(targets)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const rfdc = require('../../../../vendor/dist/rfdc')({ proto: false, circles: false })
|
|
3
4
|
const NoopAIGuard = require('./noop')
|
|
4
5
|
const executeRequest = require('./client')
|
|
5
6
|
const {
|
|
@@ -22,10 +23,11 @@ const appsecMetrics = telemetryMetrics.manager.namespace('appsec')
|
|
|
22
23
|
const ALLOW = 'ALLOW'
|
|
23
24
|
|
|
24
25
|
class AIGuardAbortError extends Error {
|
|
25
|
-
constructor (reason) {
|
|
26
|
+
constructor (reason, tags) {
|
|
26
27
|
super(reason)
|
|
27
28
|
this.name = 'AIGuardAbortError'
|
|
28
29
|
this.reason = reason
|
|
30
|
+
this.tags = tags
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -77,20 +79,26 @@ class AIGuard extends NoopAIGuard {
|
|
|
77
79
|
this.#initialized = true
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Returns a safe copy of the messages to be serialized into the meta struct.
|
|
84
|
+
*
|
|
85
|
+
* - Clones each message so callers cannot mutate the data set in the meta struct.
|
|
86
|
+
* - Truncates the list of messages and `content` fields emitting metrics accordingly.
|
|
87
|
+
*/
|
|
88
|
+
#buildMessagesForMetaStruct (messages) {
|
|
81
89
|
const size = Math.min(messages.length, this.#maxMessagesLength)
|
|
82
90
|
if (messages.length > size) {
|
|
83
91
|
appsecMetrics.count(AI_GUARD_TELEMETRY_TRUNCATED, { type: 'messages' }).inc(1)
|
|
84
92
|
}
|
|
85
|
-
const result =
|
|
86
|
-
|
|
93
|
+
const result = []
|
|
87
94
|
let contentTruncated = false
|
|
88
|
-
for (let i =
|
|
89
|
-
const message =
|
|
95
|
+
for (let i = messages.length - size; i < messages.length; i++) {
|
|
96
|
+
const message = rfdc(messages[i])
|
|
90
97
|
if (message.content?.length > this.#maxContentSize) {
|
|
91
98
|
contentTruncated = true
|
|
92
|
-
|
|
99
|
+
message.content = message.content.slice(0, this.#maxContentSize)
|
|
93
100
|
}
|
|
101
|
+
result.push(message)
|
|
94
102
|
}
|
|
95
103
|
if (contentTruncated) {
|
|
96
104
|
appsecMetrics.count(AI_GUARD_TELEMETRY_TRUNCATED, { type: 'content' }).inc(1)
|
|
@@ -138,10 +146,11 @@ class AIGuard extends NoopAIGuard {
|
|
|
138
146
|
span.setTag(AI_GUARD_TOOL_NAME_TAG_KEY, name)
|
|
139
147
|
}
|
|
140
148
|
}
|
|
149
|
+
const metaStruct = {
|
|
150
|
+
messages: this.#buildMessagesForMetaStruct(messages)
|
|
151
|
+
}
|
|
141
152
|
span.meta_struct = {
|
|
142
|
-
[AI_GUARD_META_STRUCT_KEY]:
|
|
143
|
-
messages: this.#truncate(messages)
|
|
144
|
-
}
|
|
153
|
+
[AI_GUARD_META_STRUCT_KEY]: metaStruct
|
|
145
154
|
}
|
|
146
155
|
let response
|
|
147
156
|
try {
|
|
@@ -166,7 +175,7 @@ class AIGuard extends NoopAIGuard {
|
|
|
166
175
|
`AI Guard service call failed, status ${response.status}`,
|
|
167
176
|
{ errors: response.body?.errors })
|
|
168
177
|
}
|
|
169
|
-
let action, reason, blockingEnabled
|
|
178
|
+
let action, reason, tags, blockingEnabled
|
|
170
179
|
try {
|
|
171
180
|
const attr = response.body.data.attributes
|
|
172
181
|
if (!attr.action) {
|
|
@@ -174,6 +183,7 @@ class AIGuard extends NoopAIGuard {
|
|
|
174
183
|
}
|
|
175
184
|
action = attr.action
|
|
176
185
|
reason = attr.reason
|
|
186
|
+
tags = attr.tags
|
|
177
187
|
blockingEnabled = attr.is_blocking_enabled ?? false
|
|
178
188
|
} catch (e) {
|
|
179
189
|
appsecMetrics.count(AI_GUARD_TELEMETRY_REQUESTS, { error: true }).inc(1)
|
|
@@ -182,12 +192,17 @@ class AIGuard extends NoopAIGuard {
|
|
|
182
192
|
const shouldBlock = block && blockingEnabled && action !== ALLOW
|
|
183
193
|
appsecMetrics.count(AI_GUARD_TELEMETRY_REQUESTS, { action, error: false, block: shouldBlock }).inc(1)
|
|
184
194
|
span.setTag(AI_GUARD_ACTION_TAG_KEY, action)
|
|
185
|
-
|
|
195
|
+
if (reason) {
|
|
196
|
+
span.setTag(AI_GUARD_REASON_TAG_KEY, reason)
|
|
197
|
+
}
|
|
198
|
+
if (tags?.length > 0) {
|
|
199
|
+
metaStruct.attack_categories = tags
|
|
200
|
+
}
|
|
186
201
|
if (shouldBlock) {
|
|
187
202
|
span.setTag(AI_GUARD_BLOCKED_TAG_KEY, 'true')
|
|
188
|
-
throw new AIGuardAbortError(reason)
|
|
203
|
+
throw new AIGuardAbortError(reason, tags)
|
|
189
204
|
}
|
|
190
|
-
return { action, reason }
|
|
205
|
+
return { action, reason, tags }
|
|
191
206
|
})
|
|
192
207
|
}
|
|
193
208
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { TTLCache } = require('
|
|
3
|
+
const { TTLCache } = require('../../../../vendor/dist/@isaacs/ttlcache')
|
|
4
4
|
const web = require('../plugins/util/web')
|
|
5
5
|
const log = require('../log')
|
|
6
6
|
const { AUTO_REJECT, USER_REJECT } = require('../../../../ext/priority')
|
|
@@ -47,7 +47,7 @@ export async function load (url, context, nextLoad) {
|
|
|
47
47
|
passes.push('iast')
|
|
48
48
|
}
|
|
49
49
|
} else {
|
|
50
|
-
passes = [
|
|
50
|
+
passes = [] // TODO: Re-enable Orchestrion when viable.
|
|
51
51
|
}
|
|
52
52
|
const rewritten = rewriter.rewrite(result.source.toString(), url, passes)
|
|
53
53
|
|
|
@@ -175,9 +175,8 @@ function enableRewriter (telemetryVerbosity) {
|
|
|
175
175
|
shimmer.wrap(Module.prototype, '_compile', compileMethod => getCompileMethodFn(compileMethod))
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
+
enableEsmRewriter(telemetryVerbosity)
|
|
178
179
|
}
|
|
179
|
-
|
|
180
|
-
enableEsmRewriter(telemetryVerbosity)
|
|
181
180
|
} catch (e) {
|
|
182
181
|
log.error('Error enabling Rewriter', e)
|
|
183
182
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { LRUCache } = require('lru-cache')
|
|
3
|
+
const { LRUCache } = require('../../../../../vendor/dist/lru-cache')
|
|
4
4
|
const vulnerabilitiesFormatter = require('./vulnerabilities-formatter')
|
|
5
5
|
const { IAST_ENABLED_TAG_KEY, IAST_JSON_TAG_KEY } = require('./tags')
|
|
6
6
|
const { keepTrace } = require('../../priority_sampler')
|
|
@@ -546,10 +546,6 @@ function finishRequest (req, res, storedResponseHeaders, requestBody) {
|
|
|
546
546
|
reportRequestBody(rootSpan, requestBody)
|
|
547
547
|
}
|
|
548
548
|
|
|
549
|
-
if (tags['appsec.event'] === 'true' && typeof req.route?.path === 'string') {
|
|
550
|
-
newTags['http.endpoint'] = req.route.path
|
|
551
|
-
}
|
|
552
|
-
|
|
553
549
|
rootSpan.addTags(newTags)
|
|
554
550
|
}
|
|
555
551
|
|
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
const { storage } = require('../../datadog-core')
|
|
4
4
|
const baggageStorage = storage('baggage')
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} key
|
|
8
|
+
* @param {string} value
|
|
9
|
+
*/
|
|
6
10
|
function setBaggageItem (key, value) {
|
|
7
11
|
storage('baggage').enterWith({ ...baggageStorage.getStore(), [key]: value })
|
|
8
12
|
return storage('baggage').getStore()
|
|
9
13
|
}
|
|
10
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} key
|
|
17
|
+
*/
|
|
11
18
|
function getBaggageItem (key) {
|
|
12
19
|
return storage('baggage').getStore()?.[key]
|
|
13
20
|
}
|
|
@@ -16,6 +23,10 @@ function getAllBaggageItems () {
|
|
|
16
23
|
return storage('baggage').getStore() ?? {}
|
|
17
24
|
}
|
|
18
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} keyToRemove
|
|
28
|
+
* @returns {Record<string, unknown>}
|
|
29
|
+
*/
|
|
19
30
|
function removeBaggageItem (keyToRemove) {
|
|
20
31
|
const { [keyToRemove]: _, ...newBaggage } = storage('baggage').getStore()
|
|
21
32
|
storage('baggage').enterWith(newBaggage)
|
|
@@ -36,7 +36,7 @@ session.on('Debugger.paused', async ({ params: { hitBreakpoints: [hitBreakpoint]
|
|
|
36
36
|
|
|
37
37
|
const stack = getStackFromCallFrames(callFrames)
|
|
38
38
|
|
|
39
|
-
const
|
|
39
|
+
const { processLocalState } = await getLocalStateForCallFrame(callFrames[0])
|
|
40
40
|
|
|
41
41
|
await session.post('Debugger.resume')
|
|
42
42
|
|
|
@@ -48,17 +48,13 @@ session.on('Debugger.paused', async ({ params: { hitBreakpoints: [hitBreakpoint]
|
|
|
48
48
|
version: '0',
|
|
49
49
|
location: probe.location
|
|
50
50
|
},
|
|
51
|
+
captures: {
|
|
52
|
+
lines: { [probe.location.lines[0]]: { locals: processLocalState() } }
|
|
53
|
+
},
|
|
51
54
|
stack,
|
|
52
55
|
language: 'javascript'
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
const state = getLocalState()
|
|
56
|
-
if (state) {
|
|
57
|
-
snapshot.captures = {
|
|
58
|
-
lines: { [probe.location.lines[0]]: { locals: state } }
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
58
|
breakpointHitChannel.postMessage({ snapshot })
|
|
63
59
|
})
|
|
64
60
|
|
|
@@ -245,7 +245,7 @@ function generateAndUploadPackFiles ({
|
|
|
245
245
|
|
|
246
246
|
/**
|
|
247
247
|
* This function uploads git metadata to CI Visibility's backend.
|
|
248
|
-
*/
|
|
248
|
+
*/
|
|
249
249
|
function sendGitMetadata (url, { isEvpProxy, evpProxyPrefix }, configRepositoryUrl, callback) {
|
|
250
250
|
if (!isGitAvailable()) {
|
|
251
251
|
return callback(new Error('Git is not available'))
|
|
@@ -14,7 +14,8 @@ function getTestManagementTests ({
|
|
|
14
14
|
commitMessage,
|
|
15
15
|
sha,
|
|
16
16
|
commitHeadSha,
|
|
17
|
-
commitHeadMessage
|
|
17
|
+
commitHeadMessage,
|
|
18
|
+
branch
|
|
18
19
|
}, done) {
|
|
19
20
|
const options = {
|
|
20
21
|
path: '/api/v2/test/libraries/test-management/tests',
|
|
@@ -49,7 +50,8 @@ function getTestManagementTests ({
|
|
|
49
50
|
attributes: {
|
|
50
51
|
repository_url: repositoryUrl,
|
|
51
52
|
commit_message: commitHeadMessage || commitMessage,
|
|
52
|
-
sha: commitHeadSha || sha
|
|
53
|
+
sha: commitHeadSha || sha,
|
|
54
|
+
branch
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
})
|