dd-trace 5.24.0 → 5.25.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.
Files changed (98) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/index.d.ts +335 -0
  3. package/package.json +13 -7
  4. package/packages/datadog-code-origin/index.js +4 -4
  5. package/packages/datadog-core/src/utils/src/parse-tags.js +33 -0
  6. package/packages/datadog-esbuild/index.js +4 -2
  7. package/packages/datadog-instrumentations/src/amqplib.js +65 -5
  8. package/packages/datadog-instrumentations/src/child_process.js +135 -27
  9. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -0
  10. package/packages/datadog-instrumentations/src/helpers/register.js +9 -0
  11. package/packages/datadog-instrumentations/src/kafkajs.js +123 -63
  12. package/packages/datadog-instrumentations/src/mocha/utils.js +2 -2
  13. package/packages/datadog-instrumentations/src/multer.js +37 -0
  14. package/packages/datadog-instrumentations/src/openai.js +2 -2
  15. package/packages/datadog-instrumentations/src/url.js +84 -0
  16. package/packages/datadog-instrumentations/src/utils/src/extract-package-and-module-path.js +7 -4
  17. package/packages/datadog-plugin-amqplib/src/consumer.js +4 -4
  18. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +1 -0
  19. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +1 -0
  20. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -0
  21. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +1 -0
  22. package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
  23. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +8 -1
  24. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +8 -0
  25. package/packages/datadog-plugin-grpc/src/client.js +3 -0
  26. package/packages/datadog-plugin-grpc/src/server.js +3 -0
  27. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +6 -3
  28. package/packages/datadog-plugin-kafkajs/src/consumer.js +8 -4
  29. package/packages/datadog-plugin-kafkajs/src/producer.js +10 -4
  30. package/packages/datadog-plugin-mocha/src/index.js +4 -1
  31. package/packages/datadog-plugin-openai/src/index.js +9 -1015
  32. package/packages/datadog-plugin-openai/src/tracing.js +1023 -0
  33. package/packages/dd-trace/src/appsec/addresses.js +2 -0
  34. package/packages/dd-trace/src/appsec/channels.js +3 -1
  35. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +55 -7
  36. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +4 -2
  37. package/packages/dd-trace/src/appsec/index.js +3 -0
  38. package/packages/dd-trace/src/appsec/rasp/command_injection.js +49 -0
  39. package/packages/dd-trace/src/appsec/rasp/index.js +3 -0
  40. package/packages/dd-trace/src/appsec/rasp/ssrf.js +4 -3
  41. package/packages/dd-trace/src/appsec/rasp/utils.js +3 -2
  42. package/packages/dd-trace/src/appsec/recommended.json +2 -4
  43. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +1 -0
  44. package/packages/dd-trace/src/appsec/remote_config/index.js +2 -0
  45. package/packages/dd-trace/src/appsec/reporter.js +5 -4
  46. package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -3
  47. package/packages/dd-trace/src/appsec/waf/waf_manager.js +4 -0
  48. package/packages/dd-trace/src/azure_metadata.js +120 -0
  49. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +97 -0
  50. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +90 -0
  51. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +19 -1
  52. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +53 -0
  53. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +8 -1
  54. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +43 -0
  55. package/packages/dd-trace/src/config.js +75 -6
  56. package/packages/dd-trace/src/constants.js +3 -1
  57. package/packages/dd-trace/src/datastreams/pathway.js +1 -0
  58. package/packages/dd-trace/src/debugger/devtools_client/index.js +9 -13
  59. package/packages/dd-trace/src/debugger/devtools_client/send.js +15 -1
  60. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +57 -23
  61. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +12 -2
  62. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +31 -20
  63. package/packages/dd-trace/src/debugger/devtools_client/snapshot/symbols.js +6 -0
  64. package/packages/dd-trace/src/debugger/devtools_client/state.js +11 -2
  65. package/packages/dd-trace/src/debugger/index.js +10 -3
  66. package/packages/dd-trace/src/llmobs/constants/tags.js +34 -0
  67. package/packages/dd-trace/src/llmobs/constants/text.js +6 -0
  68. package/packages/dd-trace/src/llmobs/constants/writers.js +13 -0
  69. package/packages/dd-trace/src/llmobs/index.js +103 -0
  70. package/packages/dd-trace/src/llmobs/noop.js +82 -0
  71. package/packages/dd-trace/src/llmobs/plugins/base.js +65 -0
  72. package/packages/dd-trace/src/llmobs/plugins/openai.js +205 -0
  73. package/packages/dd-trace/src/llmobs/sdk.js +377 -0
  74. package/packages/dd-trace/src/llmobs/span_processor.js +195 -0
  75. package/packages/dd-trace/src/llmobs/storage.js +7 -0
  76. package/packages/dd-trace/src/llmobs/tagger.js +322 -0
  77. package/packages/dd-trace/src/llmobs/util.js +176 -0
  78. package/packages/dd-trace/src/llmobs/writers/base.js +111 -0
  79. package/packages/dd-trace/src/llmobs/writers/evaluations.js +29 -0
  80. package/packages/dd-trace/src/llmobs/writers/spans/agentProxy.js +23 -0
  81. package/packages/dd-trace/src/llmobs/writers/spans/agentless.js +17 -0
  82. package/packages/dd-trace/src/llmobs/writers/spans/base.js +49 -0
  83. package/packages/dd-trace/src/noop/proxy.js +3 -0
  84. package/packages/dd-trace/src/noop/span.js +3 -0
  85. package/packages/dd-trace/src/opentelemetry/span.js +1 -1
  86. package/packages/dd-trace/src/opentelemetry/tracer.js +1 -0
  87. package/packages/dd-trace/src/opentracing/propagation/text_map.js +73 -12
  88. package/packages/dd-trace/src/opentracing/span.js +12 -0
  89. package/packages/dd-trace/src/opentracing/tracer.js +8 -1
  90. package/packages/dd-trace/src/payload-tagging/config/aws.json +71 -3
  91. package/packages/dd-trace/src/plugins/outbound.js +9 -0
  92. package/packages/dd-trace/src/priority_sampler.js +16 -0
  93. package/packages/dd-trace/src/profiling/config.js +3 -1
  94. package/packages/dd-trace/src/profiling/exporters/agent.js +7 -5
  95. package/packages/dd-trace/src/profiling/profilers/wall.js +2 -1
  96. package/packages/dd-trace/src/proxy.js +8 -1
  97. package/packages/dd-trace/src/span_processor.js +5 -0
  98. package/packages/dd-trace/src/telemetry/index.js +11 -1
@@ -29,6 +29,7 @@ require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
29
29
  require,rfdc,MIT,Copyright 2019 David Mark Clements
30
30
  require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
31
31
  require,shell-quote,mit,Copyright (c) 2013 James Halliday
32
+ dev,@apollo/server,MIT,Copyright (c) 2016-2020 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
32
33
  dev,@types/node,MIT,Copyright Authors
33
34
  dev,autocannon,MIT,Copyright 2016 Matteo Collina
34
35
  dev,aws-sdk,Apache 2.0,Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
package/index.d.ts CHANGED
@@ -137,6 +137,11 @@ interface Tracer extends opentracing.Tracer {
137
137
  TracerProvider: tracer.opentelemetry.TracerProvider;
138
138
 
139
139
  dogstatsd: tracer.DogStatsD;
140
+
141
+ /**
142
+ * LLM Observability SDK
143
+ */
144
+ llmobs: tracer.llmobs.LLMObs;
140
145
  }
141
146
 
142
147
  // left out of the namespace, so it
@@ -752,6 +757,11 @@ declare namespace tracer {
752
757
  */
753
758
  maxDepth?: number
754
759
  }
760
+
761
+ /**
762
+ * Configuration enabling LLM Observability. Enablement is superceded by the DD_LLMOBS_ENABLED environment variable.
763
+ */
764
+ llmobs?: llmobs.LLMObsEnableOptions
755
765
  }
756
766
 
757
767
  /**
@@ -2198,6 +2208,331 @@ declare namespace tracer {
2198
2208
  */
2199
2209
  telemetryVerbosity?: string
2200
2210
  }
2211
+
2212
+ export namespace llmobs {
2213
+ export interface LLMObs {
2214
+
2215
+ /**
2216
+ * Whether or not LLM Observability is enabled.
2217
+ */
2218
+ enabled: boolean,
2219
+
2220
+ /**
2221
+ * Enable LLM Observability tracing.
2222
+ */
2223
+ enable (options: LLMObsEnableOptions): void,
2224
+
2225
+ /**
2226
+ * Disable LLM Observability tracing.
2227
+ */
2228
+ disable (): void,
2229
+
2230
+ /**
2231
+ * Instruments a function by automatically creating a span activated on its
2232
+ * scope.
2233
+ *
2234
+ * The span will automatically be finished when one of these conditions is
2235
+ * met:
2236
+ *
2237
+ * * The function returns a promise, in which case the span will finish when
2238
+ * the promise is resolved or rejected.
2239
+ * * The function takes a callback as its second parameter, in which case the
2240
+ * span will finish when that callback is called.
2241
+ * * The function doesn't accept a callback and doesn't return a promise, in
2242
+ * which case the span will finish at the end of the function execution.
2243
+ * @param fn The function to instrument.
2244
+ * @param options Optional LLM Observability span options.
2245
+ * @returns The return value of the function.
2246
+ */
2247
+ trace<T> (options: LLMObsNamedSpanOptions, fn: (span: tracer.Span, done: (error?: Error) => void) => T): T
2248
+
2249
+ /**
2250
+ * Wrap a function to automatically create a span activated on its
2251
+ * scope when it's called.
2252
+ *
2253
+ * The span will automatically be finished when one of these conditions is
2254
+ * met:
2255
+ *
2256
+ * * The function returns a promise, in which case the span will finish when
2257
+ * the promise is resolved or rejected.
2258
+ * * The function takes a callback as its last parameter, in which case the
2259
+ * span will finish when that callback is called.
2260
+ * * The function doesn't accept a callback and doesn't return a promise, in
2261
+ * which case the span will finish at the end of the function execution.
2262
+ * @param fn The function to instrument.
2263
+ * @param options Optional LLM Observability span options.
2264
+ * @returns A new function that wraps the provided function with span creation.
2265
+ */
2266
+ wrap<T = (...args: any[]) => any> (options: LLMObsNamelessSpanOptions, fn: T): T
2267
+
2268
+ /**
2269
+ * Decorate a function in a javascript runtime that supports function decorators.
2270
+ * Note that this is **not** supported in the Node.js runtime, but is in TypeScript.
2271
+ *
2272
+ * In TypeScript, this decorator is only supported in contexts where general TypeScript
2273
+ * function decorators are supported.
2274
+ *
2275
+ * @param options Optional LLM Observability span options.
2276
+ */
2277
+ decorate (options: llmobs.LLMObsNamelessSpanOptions): any
2278
+
2279
+ /**
2280
+ * Returns a representation of a span to export its span and trace IDs.
2281
+ * If no span is provided, the current LLMObs-type span will be used.
2282
+ * @param span Optional span to export.
2283
+ * @returns An object containing the span and trace IDs.
2284
+ */
2285
+ exportSpan (span?: tracer.Span): llmobs.ExportedLLMObsSpan
2286
+
2287
+
2288
+ /**
2289
+ * Sets inputs, outputs, tags, metadata, and metrics as provided for a given LLM Observability span.
2290
+ * Note that with the exception of tags, this method will override any existing values for the provided fields.
2291
+ *
2292
+ * For example:
2293
+ * ```javascript
2294
+ * llmobs.trace({ kind: 'llm', name: 'myLLM', modelName: 'gpt-4o', modelProvider: 'openai' }, () => {
2295
+ * llmobs.annotate({
2296
+ * inputData: [{ content: 'system prompt, role: 'system' }, { content: 'user prompt', role: 'user' }],
2297
+ * outputData: { content: 'response', role: 'ai' },
2298
+ * metadata: { temperature: 0.7 },
2299
+ * tags: { host: 'localhost' },
2300
+ * metrics: { inputTokens: 10, outputTokens: 20, totalTokens: 30 }
2301
+ * })
2302
+ * })
2303
+ * ```
2304
+ *
2305
+ * @param span The span to annotate (defaults to the current LLM Observability span if not provided)
2306
+ * @param options An object containing the inputs, outputs, tags, metadata, and metrics to set on the span.
2307
+ */
2308
+ annotate (options: llmobs.AnnotationOptions): void
2309
+ annotate (span: tracer.Span | undefined, options: llmobs.AnnotationOptions): void
2310
+
2311
+ /**
2312
+ * Submits a custom evalutation metric for a given span ID and trace ID.
2313
+ * @param spanContext The span context of the span to submit the evaluation metric for.
2314
+ * @param options An object containing the label, metric type, value, and tags of the evaluation metric.
2315
+ */
2316
+ submitEvaluation (spanContext: llmobs.ExportedLLMObsSpan, options: llmobs.EvaluationOptions): void
2317
+
2318
+ /**
2319
+ * Flushes any remaining spans and evaluation metrics to LLM Observability.
2320
+ */
2321
+ flush (): void
2322
+ }
2323
+
2324
+ interface EvaluationOptions {
2325
+ /**
2326
+ * The name of the evalutation metric
2327
+ */
2328
+ label: string,
2329
+
2330
+ /**
2331
+ * The type of evaluation metric, one of 'categorical' or 'score'
2332
+ */
2333
+ metricType: 'categorical' | 'score',
2334
+
2335
+ /**
2336
+ * The value of the evaluation metric.
2337
+ * Must be string for 'categorical' metrics and number for 'score' metrics.
2338
+ */
2339
+ value: string | number,
2340
+
2341
+ /**
2342
+ * An object of string key-value pairs to tag the evaluation metric with.
2343
+ */
2344
+ tags?: { [key: string]: any },
2345
+
2346
+ /**
2347
+ * The name of the ML application
2348
+ */
2349
+ mlApp?: string,
2350
+
2351
+ /**
2352
+ * The timestamp in milliseconds when the evaluation metric result was generated.
2353
+ */
2354
+ timestampMs?: number
2355
+ }
2356
+
2357
+ interface Document {
2358
+ /**
2359
+ * Document text
2360
+ */
2361
+ text?: string,
2362
+
2363
+ /**
2364
+ * Document name
2365
+ */
2366
+ name?: string,
2367
+
2368
+ /**
2369
+ * Document ID
2370
+ */
2371
+ id?: string,
2372
+
2373
+ /**
2374
+ * Score of the document retrieval as a source of ground truth
2375
+ */
2376
+ score?: number
2377
+ }
2378
+
2379
+ /**
2380
+ * Represents a single LLM chat model message
2381
+ */
2382
+ interface Message {
2383
+ /**
2384
+ * Content of the message.
2385
+ */
2386
+ content: string,
2387
+
2388
+ /**
2389
+ * Role of the message (ie system, user, ai)
2390
+ */
2391
+ role?: string,
2392
+
2393
+ /**
2394
+ * Tool calls of the message
2395
+ */
2396
+ toolCalls?: ToolCall[],
2397
+ }
2398
+
2399
+ /**
2400
+ * Represents a single tool call for an LLM chat model message
2401
+ */
2402
+ interface ToolCall {
2403
+ /**
2404
+ * Name of the tool
2405
+ */
2406
+ name?: string,
2407
+
2408
+ /**
2409
+ * Arguments passed to the tool
2410
+ */
2411
+ arguments?: { [key: string]: any },
2412
+
2413
+ /**
2414
+ * The tool ID
2415
+ */
2416
+ toolId?: string,
2417
+
2418
+ /**
2419
+ * The tool type
2420
+ */
2421
+ type?: string
2422
+ }
2423
+
2424
+ /**
2425
+ * Annotation options for LLM Observability spans.
2426
+ */
2427
+ interface AnnotationOptions {
2428
+ /**
2429
+ * A single input string, object, or a list of objects based on the span kind:
2430
+ * 1. LLM spans: accepts a string, or an object of the form {content: "...", role: "..."}, or a list of objects with the same signature.
2431
+ * 2. Embedding spans: accepts a string, list of strings, or an object of the form {text: "...", ...}, or a list of objects with the same signature.
2432
+ * 3. Other: any JSON serializable type
2433
+ */
2434
+ inputData?: string | Message | Message[] | Document | Document[] | { [key: string]: any },
2435
+
2436
+ /**
2437
+ * A single output string, object, or a list of objects based on the span kind:
2438
+ * 1. LLM spans: accepts a string, or an object of the form {content: "...", role: "..."}, or a list of objects with the same signature.
2439
+ * 2. Retrieval spans: An object containing any of the key value pairs {name: str, id: str, text: str, source: number} or a list of dictionaries with the same signature.
2440
+ * 3. Other: any JSON serializable type
2441
+ */
2442
+ outputData?: string | Message | Message[] | Document | Document[] | { [key: string]: any },
2443
+
2444
+ /**
2445
+ * Object of JSON serializable key-value metadata pairs relevant to the input/output operation described by the LLM Observability span.
2446
+ */
2447
+ metadata?: { [key: string]: any },
2448
+
2449
+ /**
2450
+ * Object of JSON seraliazable key-value metrics (number) pairs, such as `{input,output,total}Tokens`
2451
+ */
2452
+ metrics?: { [key: string]: number },
2453
+
2454
+ /**
2455
+ * Object of JSON serializable key-value tag pairs to set or update on the LLM Observability span regarding the span's context.
2456
+ */
2457
+ tags?: { [key: string]: any }
2458
+ }
2459
+
2460
+ /**
2461
+ * An object containing the span ID and trace ID of interest
2462
+ */
2463
+ interface ExportedLLMObsSpan {
2464
+ /**
2465
+ * Trace ID associated with the span of interest
2466
+ */
2467
+ traceId: string,
2468
+
2469
+ /**
2470
+ * Span ID associated with the span of interest
2471
+ */
2472
+ spanId: string,
2473
+ }
2474
+
2475
+ interface LLMObsSpanOptions extends SpanOptions {
2476
+ /**
2477
+ * LLM Observability span kind. One of `agent`, `workflow`, `task`, `tool`, `retrieval`, `embedding`, or `llm`.
2478
+ */
2479
+ kind: llmobs.spanKind,
2480
+
2481
+ /**
2482
+ * The ID of the underlying user session. Required for tracking sessions.
2483
+ */
2484
+ sessionId?: string,
2485
+
2486
+ /**
2487
+ * The name of the ML application that the agent is orchestrating.
2488
+ * If not provided, the default value will be set to mlApp provided during initalization, or `DD_LLMOBS_ML_APP`.
2489
+ */
2490
+ mlApp?: string,
2491
+
2492
+ /**
2493
+ * The name of the invoked LLM or embedding model. Only used on `llm` and `embedding` spans.
2494
+ */
2495
+ modelName?: string,
2496
+
2497
+ /**
2498
+ * The name of the invoked LLM or embedding model provider. Only used on `llm` and `embedding` spans.
2499
+ * If not provided for LLM or embedding spans, a default value of 'custom' will be set.
2500
+ */
2501
+ modelProvider?: string,
2502
+ }
2503
+
2504
+ interface LLMObsNamedSpanOptions extends LLMObsSpanOptions {
2505
+ /**
2506
+ * The name of the traced operation. This is a required option.
2507
+ */
2508
+ name: string,
2509
+ }
2510
+
2511
+ interface LLMObsNamelessSpanOptions extends LLMObsSpanOptions {
2512
+ /**
2513
+ * The name of the traced operation.
2514
+ */
2515
+ name?: string,
2516
+ }
2517
+
2518
+ /**
2519
+ * Options for enabling LLM Observability tracing.
2520
+ */
2521
+ interface LLMObsEnableOptions {
2522
+ /**
2523
+ * The name of your ML application.
2524
+ */
2525
+ mlApp?: string,
2526
+
2527
+ /**
2528
+ * Set to `true` to disbale sending data that requires a Datadog Agent.
2529
+ */
2530
+ agentlessEnabled?: boolean,
2531
+ }
2532
+
2533
+ /** @hidden */
2534
+ type spanKind = 'agent' | 'workflow' | 'task' | 'tool' | 'retrieval' | 'embedding' | 'llm'
2535
+ }
2201
2536
  }
2202
2537
 
2203
2538
  /**
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.24.0",
3
+ "version": "5.25.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "scripts": {
8
+ "env": "bash ./plugin-env",
8
9
  "preinstall": "node scripts/preinstall.js",
9
10
  "bench": "node benchmark",
10
11
  "bench:profiler": "node benchmark/profiler",
@@ -12,8 +13,8 @@
12
13
  "bench:e2e:ci-visibility": "node benchmark/e2e-ci/benchmark-run.js",
13
14
  "type:doc": "cd docs && yarn && yarn build",
14
15
  "type:test": "cd docs && yarn && yarn test",
15
- "lint": "node scripts/check_licenses.js && eslint . && yarn audit --groups dependencies",
16
- "lint-fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit --groups dependencies",
16
+ "lint": "node scripts/check_licenses.js && eslint . && yarn audit",
17
+ "lint-fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit",
17
18
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
18
19
  "test": "SERVICES=* yarn services && mocha --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
19
20
  "test:appsec": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
@@ -30,6 +31,10 @@
30
31
  "test:core:ci": "npm run test:core -- --coverage --nyc-arg=--include=\"packages/datadog-core/src/**/*.js\"",
31
32
  "test:lambda": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/lambda/**/*.spec.js\"",
32
33
  "test:lambda:ci": "nyc --no-clean --include \"packages/dd-trace/src/lambda/**/*.js\" -- npm run test:lambda",
34
+ "test:llmobs:sdk": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/llmobs/plugins/**/*.spec.js\" \"packages/dd-trace/test/llmobs/**/*.spec.js\" ",
35
+ "test:llmobs:sdk:ci": "nyc --no-clean --include \"packages/dd-trace/src/llmobs/**/*.js\" -- npm run test:llmobs:sdk",
36
+ "test:llmobs:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/llmobs/plugins/**/*.spec.js\"",
37
+ "test:llmobs:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/llmobs/**/*.js\" -- npm run test:llmobs:plugins",
33
38
  "test:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\"",
34
39
  "test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins",
35
40
  "test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
@@ -76,11 +81,11 @@
76
81
  "node": ">=18"
77
82
  },
78
83
  "dependencies": {
79
- "@datadog/native-appsec": "8.1.1",
84
+ "@datadog/native-appsec": "8.2.1",
80
85
  "@datadog/native-iast-rewriter": "2.5.0",
81
- "@datadog/native-iast-taint-tracking": "3.1.0",
82
- "@datadog/native-metrics": "^2.0.0",
83
- "@datadog/pprof": "5.3.0",
86
+ "@datadog/native-iast-taint-tracking": "3.2.0",
87
+ "@datadog/native-metrics": "^3.0.1",
88
+ "@datadog/pprof": "5.4.1",
84
89
  "@datadog/sketches-js": "^2.1.0",
85
90
  "@opentelemetry/api": ">=1.0.0 <1.9.0",
86
91
  "@opentelemetry/core": "^1.14.0",
@@ -108,6 +113,7 @@
108
113
  "tlhunter-sorted-set": "^0.1.0"
109
114
  },
110
115
  "devDependencies": {
116
+ "@apollo/server": "^4.11.0",
111
117
  "@types/node": "^16.18.103",
112
118
  "autocannon": "^4.5.2",
113
119
  "aws-sdk": "^2.1446.0",
@@ -5,15 +5,15 @@ const { getUserLandFrames } = require('../dd-trace/src/plugins/util/stacktrace')
5
5
  const limit = Number(process.env._DD_CODE_ORIGIN_MAX_USER_FRAMES) || 8
6
6
 
7
7
  module.exports = {
8
- entryTag,
9
- exitTag
8
+ entryTags,
9
+ exitTags
10
10
  }
11
11
 
12
- function entryTag (topOfStackFunc) {
12
+ function entryTags (topOfStackFunc) {
13
13
  return tag('entry', topOfStackFunc)
14
14
  }
15
15
 
16
- function exitTag (topOfStackFunc) {
16
+ function exitTags (topOfStackFunc) {
17
17
  return tag('exit', topOfStackFunc)
18
18
  }
19
19
 
@@ -0,0 +1,33 @@
1
+ 'use strict'
2
+
3
+ const digitRegex = /^\d+$/
4
+
5
+ /**
6
+ * Converts a flat object of tags into a nested object. For example:
7
+ * { 'a.b.c': 'value' } -> { a: { b: { c: 'value' } } }
8
+ * Also supports array-keys. For example:
9
+ * { 'a.0.b': 'value' } -> { a: [{ b: 'value' }] }
10
+ *
11
+ * @param {Object} tags - Key/value pairs of tags
12
+ * @returns Object - Parsed tags
13
+ */
14
+ module.exports = tags => {
15
+ const parsedTags = {}
16
+ for (const [tag, value] of Object.entries(tags)) {
17
+ const keys = tag.split('.')
18
+ let current = parsedTags
19
+ let depth = 0
20
+ for (const key of keys) {
21
+ if (!current[key]) {
22
+ if (depth === keys.length - 1) {
23
+ current[key] = value
24
+ break
25
+ }
26
+ current[key] = keys[depth + 1]?.match(digitRegex) ? [] : {}
27
+ }
28
+ current = current[key]
29
+ depth++
30
+ }
31
+ }
32
+ return parsedTags
33
+ }
@@ -96,7 +96,9 @@ module.exports.setup = function (build) {
96
96
 
97
97
  let pathToPackageJson
98
98
  try {
99
- pathToPackageJson = require.resolve(`${extracted.pkg}/package.json`, { paths: [args.resolveDir] })
99
+ // we can't use require.resolve('pkg/package.json') as ESM modules don't make the file available
100
+ pathToPackageJson = require.resolve(`${extracted.pkg}`, { paths: [args.resolveDir] })
101
+ pathToPackageJson = extractPackageAndModulePath(pathToPackageJson).pkgJson
100
102
  } catch (err) {
101
103
  if (err.code === 'MODULE_NOT_FOUND') {
102
104
  if (!internal) {
@@ -111,7 +113,7 @@ module.exports.setup = function (build) {
111
113
  }
112
114
  }
113
115
 
114
- const packageJson = require(pathToPackageJson)
116
+ const packageJson = JSON.parse(fs.readFileSync(pathToPackageJson).toString())
115
117
 
116
118
  if (DEBUG) console.log(`RESOLVE: ${args.path}@${packageJson.version}`)
117
119
 
@@ -25,6 +25,70 @@ addHook({ name: 'amqplib', file: 'lib/defs.js', versions: [MIN_VERSION] }, defs
25
25
  return defs
26
26
  })
27
27
 
28
+ addHook({ name: 'amqplib', file: 'lib/channel_model.js', versions: [MIN_VERSION] }, x => {
29
+ shimmer.wrap(x.Channel.prototype, 'get', getMessage => function (queue, options) {
30
+ return getMessage.apply(this, arguments).then(message => {
31
+ if (message === null) {
32
+ return message
33
+ }
34
+ startCh.publish({ method: 'basic.get', message, fields: message.fields, queue })
35
+ // finish right away
36
+ finishCh.publish()
37
+ return message
38
+ })
39
+ })
40
+ shimmer.wrap(x.Channel.prototype, 'consume', consume => function (queue, callback, options) {
41
+ if (!startCh.hasSubscribers) {
42
+ return consume.apply(this, arguments)
43
+ }
44
+ arguments[1] = (message, ...args) => {
45
+ if (message === null) {
46
+ return callback(message, ...args)
47
+ }
48
+ startCh.publish({ method: 'basic.deliver', message, fields: message.fields, queue })
49
+ const result = callback(message, ...args)
50
+ finishCh.publish()
51
+ return result
52
+ }
53
+ return consume.apply(this, arguments)
54
+ })
55
+ return x
56
+ })
57
+
58
+ addHook({ name: 'amqplib', file: 'lib/callback_model.js', versions: [MIN_VERSION] }, channel => {
59
+ shimmer.wrap(channel.Channel.prototype, 'get', getMessage => function (queue, options, callback) {
60
+ if (!startCh.hasSubscribers) {
61
+ return getMessage.apply(this, arguments)
62
+ }
63
+ arguments[2] = (error, message, ...args) => {
64
+ if (error !== null || message === null) {
65
+ return callback(error, message, ...args)
66
+ }
67
+ startCh.publish({ method: 'basic.get', message, fields: message.fields, queue })
68
+ const result = callback(error, message, ...args)
69
+ finishCh.publish()
70
+ return result
71
+ }
72
+ return getMessage.apply(this, arguments)
73
+ })
74
+ shimmer.wrap(channel.Channel.prototype, 'consume', consume => function (queue, callback) {
75
+ if (!startCh.hasSubscribers) {
76
+ return consume.apply(this, arguments)
77
+ }
78
+ arguments[1] = (message, ...args) => {
79
+ if (message === null) {
80
+ return callback(message, ...args)
81
+ }
82
+ startCh.publish({ method: 'basic.deliver', message, fields: message.fields, queue })
83
+ const result = callback(message, ...args)
84
+ finishCh.publish()
85
+ return result
86
+ }
87
+ return consume.apply(this, arguments)
88
+ })
89
+ return channel
90
+ })
91
+
28
92
  addHook({ name: 'amqplib', file: 'lib/channel.js', versions: [MIN_VERSION] }, channel => {
29
93
  shimmer.wrap(channel.Channel.prototype, 'sendImmediately', sendImmediately => function (method, fields) {
30
94
  return instrument(sendImmediately, this, arguments, methods[method], fields)
@@ -33,15 +97,11 @@ addHook({ name: 'amqplib', file: 'lib/channel.js', versions: [MIN_VERSION] }, ch
33
97
  shimmer.wrap(channel.Channel.prototype, 'sendMessage', sendMessage => function (fields) {
34
98
  return instrument(sendMessage, this, arguments, 'basic.publish', fields, arguments[2])
35
99
  })
36
-
37
- shimmer.wrap(channel.BaseChannel.prototype, 'dispatchMessage', dispatchMessage => function (fields, message) {
38
- return instrument(dispatchMessage, this, arguments, 'basic.deliver', fields, message)
39
- })
40
100
  return channel
41
101
  })
42
102
 
43
103
  function instrument (send, channel, args, method, fields, message) {
44
- if (!startCh.hasSubscribers) {
104
+ if (!startCh.hasSubscribers || method === 'basic.get') {
45
105
  return send.apply(channel, args)
46
106
  }
47
107