dd-trace 6.17.0 → 6.18.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 (70) hide show
  1. package/index.d.ts +52 -9
  2. package/package.json +1 -1
  3. package/packages/datadog-instrumentations/src/cucumber.js +10 -5
  4. package/packages/datadog-instrumentations/src/cypress-config.js +27 -15
  5. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +6 -0
  6. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +2 -1
  7. package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -6
  8. package/packages/datadog-instrumentations/src/helpers/register.js +20 -0
  9. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +41 -4
  10. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +15 -13
  11. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +43 -0
  12. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +13 -0
  13. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +28 -3
  14. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +4 -0
  15. package/packages/datadog-instrumentations/src/jest.js +27 -3
  16. package/packages/datadog-instrumentations/src/mocha/main.js +7 -5
  17. package/packages/datadog-instrumentations/src/mocha/utils.js +8 -8
  18. package/packages/datadog-instrumentations/src/playwright-reporter.js +3 -4
  19. package/packages/datadog-instrumentations/src/playwright.js +47 -6
  20. package/packages/datadog-instrumentations/src/undici.js +7 -3
  21. package/packages/datadog-instrumentations/src/vitest-main.js +91 -20
  22. package/packages/datadog-instrumentations/src/webdriverio.js +28 -12
  23. package/packages/datadog-instrumentations/src/ws.js +41 -1
  24. package/packages/datadog-plugin-cucumber/src/index.js +3 -4
  25. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +44 -14
  26. package/packages/datadog-plugin-cypress/src/index.js +3 -1
  27. package/packages/datadog-plugin-jest/src/index.js +3 -4
  28. package/packages/datadog-plugin-mocha/src/index.js +3 -4
  29. package/packages/datadog-plugin-playwright/src/index.js +11 -6
  30. package/packages/datadog-plugin-vitest/src/index.js +3 -4
  31. package/packages/datadog-plugin-ws/src/producer.js +1 -1
  32. package/packages/datadog-shimmer/src/shimmer.js +14 -10
  33. package/packages/datadog-turbopack/index.js +4 -1
  34. package/packages/datadog-turbopack/src/loader.js +6 -2
  35. package/packages/dd-trace/src/agent/info.js +5 -4
  36. package/packages/dd-trace/src/config/generated-config-types.d.ts +15 -15
  37. package/packages/dd-trace/src/config/index.js +7 -6
  38. package/packages/dd-trace/src/config/supported-configurations.json +11 -0
  39. package/packages/dd-trace/src/debugger/devtools_client/config.js +2 -1
  40. package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
  41. package/packages/dd-trace/src/debugger/devtools_client/snapshot/redaction.js +5 -3
  42. package/packages/dd-trace/src/debugger/devtools_client/status.js +1 -1
  43. package/packages/dd-trace/src/debugger/index.js +1 -1
  44. package/packages/dd-trace/src/evp_proxy/constants.js +2 -0
  45. package/packages/dd-trace/src/evp_proxy/direct.js +17 -13
  46. package/packages/dd-trace/src/evp_proxy/discovery.js +14 -10
  47. package/packages/dd-trace/src/evp_proxy/path.js +21 -7
  48. package/packages/dd-trace/src/exporters/common/url.js +33 -2
  49. package/packages/dd-trace/src/llmobs/prompts/manager.js +10 -2
  50. package/packages/dd-trace/src/llmobs/prompts/prompt.js +77 -11
  51. package/packages/dd-trace/src/llmobs/tagger.js +9 -4
  52. package/packages/dd-trace/src/openfeature/configuration_source.js +4 -1
  53. package/packages/dd-trace/src/openfeature/flagging_provider.js +3 -3
  54. package/packages/dd-trace/src/openfeature/index.js +6 -2
  55. package/packages/dd-trace/src/openfeature/writers/base.js +90 -17
  56. package/packages/dd-trace/src/openfeature/writers/exposures.js +4 -0
  57. package/packages/dd-trace/src/openfeature/writers/util.js +104 -33
  58. package/packages/dd-trace/src/opentracing/tracer.js +3 -3
  59. package/packages/dd-trace/src/plugin_manager.js +27 -8
  60. package/packages/dd-trace/src/plugins/ci_plugin.js +1 -1
  61. package/packages/dd-trace/src/plugins/util/test.js +9 -4
  62. package/packages/dd-trace/src/proxy.js +2 -2
  63. package/packages/dd-trace/src/telemetry/send-data.js +2 -1
  64. package/packages/dd-trace/src/telemetry/telemetry.js +1 -1
  65. package/packages/dd-trace/src/tracer.js +5 -4
  66. package/packages/datadog-instrumentations/src/azure-cosmos.js +0 -7
  67. package/packages/datadog-instrumentations/src/bullmq.js +0 -11
  68. package/packages/datadog-instrumentations/src/langchain.js +0 -7
  69. package/packages/datadog-instrumentations/src/langgraph.js +0 -7
  70. package/packages/datadog-instrumentations/src/mercurius.js +0 -11
package/index.d.ts CHANGED
@@ -3886,13 +3886,13 @@ declare namespace tracer {
3886
3886
  /** Create a text or chat prompt and its first version. */
3887
3887
  createPrompt (
3888
3888
  promptId: string,
3889
- template: string | PromptTemplateMessage[],
3889
+ template: string | PromptTemplateItem[],
3890
3890
  options?: CreatePromptOptions
3891
3891
  ): Promise<PromptResponse>
3892
3892
  /** Add a text or chat version to an existing prompt. */
3893
3893
  createPromptVersion (
3894
3894
  promptId: string,
3895
- template: string | PromptTemplateMessage[],
3895
+ template: string | PromptTemplateItem[],
3896
3896
  options?: CreatePromptVersionOptions
3897
3897
  ): Promise<PromptVersionResponse>
3898
3898
  /** Update prompt metadata. */
@@ -3916,10 +3916,45 @@ declare namespace tracer {
3916
3916
  content: string
3917
3917
  }
3918
3918
 
3919
+ /** Provider fields on expanded messages; authored templates remain text-only. */
3920
+ interface FormattedPromptMessage extends PromptTemplateMessage {
3921
+ // The inherited content type stays string for compatibility; tool-only payloads can omit it or contain null.
3922
+ tool_calls?: PromptToolCall[] | null,
3923
+ tool_results?: PromptToolResult[] | null,
3924
+ tool_call_id?: string | null
3925
+ }
3926
+
3927
+ interface PromptToolCall {
3928
+ id?: string | null,
3929
+ type?: string | null,
3930
+ tool_id?: string | null,
3931
+ name?: string | null,
3932
+ arguments?: unknown,
3933
+ function?: {
3934
+ name: string,
3935
+ arguments: string
3936
+ } | null
3937
+ }
3938
+
3939
+ interface PromptToolResult {
3940
+ id?: string | null,
3941
+ type?: string | null,
3942
+ tool_id?: string | null,
3943
+ name?: string | null,
3944
+ result?: unknown
3945
+ }
3946
+
3947
+ interface PromptMessagePlaceholder {
3948
+ type: 'placeholder',
3949
+ name: string
3950
+ }
3951
+
3952
+ type PromptTemplateItem = PromptTemplateMessage | PromptMessagePlaceholder
3953
+
3919
3954
  type PromptFallbackValue =
3920
3955
  | string
3921
- | PromptTemplateMessage[]
3922
- | { template: string | PromptTemplateMessage[], version?: string }
3956
+ | PromptTemplateItem[]
3957
+ | { template: string | PromptTemplateItem[], version?: string, config?: Record<string, JSONType> }
3923
3958
  type PromptFallback = PromptFallbackValue | (() => PromptFallbackValue)
3924
3959
 
3925
3960
  interface GetPromptOptions {
@@ -3938,13 +3973,15 @@ declare namespace tracer {
3938
3973
  title?: string,
3939
3974
  description?: string,
3940
3975
  userVersion?: string,
3941
- envIds?: string[]
3976
+ envIds?: string[],
3977
+ config?: Record<string, JSONType>
3942
3978
  }
3943
3979
 
3944
3980
  interface CreatePromptVersionOptions {
3945
3981
  description?: string,
3946
3982
  userVersion?: string,
3947
- envIds?: string[]
3983
+ envIds?: string[],
3984
+ config?: Record<string, JSONType>
3948
3985
  }
3949
3986
 
3950
3987
  interface UpdatePromptOptions {
@@ -3957,14 +3994,16 @@ declare namespace tracer {
3957
3994
  envIds?: string[]
3958
3995
  }
3959
3996
 
3997
+ // Preserve released output types; placeholder entries and null/omitted tool content are not fully described here.
3960
3998
  interface ManagedPrompt {
3961
3999
  readonly id: string,
3962
4000
  readonly version: string,
3963
4001
  readonly source: 'registry' | 'cache' | 'fallback' | 'ff' | 'resolve',
3964
4002
  readonly template: string | ReadonlyArray<Readonly<PromptTemplateMessage>>,
4003
+ readonly config: Readonly<Record<string, ReadonlyJSONType>>,
3965
4004
  readonly promptUuid?: string,
3966
4005
  readonly promptVersionUuid?: string,
3967
- format (variables?: Record<string, unknown>): string | PromptTemplateMessage[]
4006
+ format (variables?: Record<string, unknown>): string | FormattedPromptMessage[]
3968
4007
  toAnnotation (variables?: Record<string, unknown>): Prompt
3969
4008
  }
3970
4009
 
@@ -3982,7 +4021,8 @@ declare namespace tracer {
3982
4021
  ml_app?: string,
3983
4022
  ml_apps?: string[],
3984
4023
  last_version_created_at?: string,
3985
- extracted_from?: string
4024
+ extracted_from?: string,
4025
+ config?: Record<string, JSONType>
3986
4026
  }
3987
4027
 
3988
4028
  interface PromptVersionResponse {
@@ -3996,7 +4036,8 @@ declare namespace tracer {
3996
4036
  version_created_at?: string,
3997
4037
  author?: string,
3998
4038
  description?: string,
3999
- ml_app?: string
4039
+ ml_app?: string,
4040
+ config?: Record<string, JSONType>
4000
4041
  }
4001
4042
 
4002
4043
  interface DeletedPromptResponse {
@@ -4008,6 +4049,8 @@ declare namespace tracer {
4008
4049
  /** JSON-serializable value accepted by LLMObs Experiments. */
4009
4050
  type JSONType = string | number | boolean | null | JSONType[] | { [key: string]: JSONType }
4010
4051
 
4052
+ type ReadonlyJSONType = string | number | boolean | null | ReadonlyArray<ReadonlyJSONType> | { readonly [key: string]: ReadonlyJSONType }
4053
+
4011
4054
  /**
4012
4055
  * A task run over each dataset record during an experiment.
4013
4056
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "6.17.0",
3
+ "version": "6.18.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -142,7 +142,6 @@ let knownTests = {}
142
142
  let skippedSuites = []
143
143
  let isSuitesSkipped = false
144
144
  let areAllSuitesSkipped = false
145
- let hasTestsToRun = false
146
145
  let repositoryRoot
147
146
 
148
147
  function shouldRunEarlyFlakeDetection () {
@@ -1218,7 +1217,6 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
1218
1217
  }
1219
1218
  }
1220
1219
 
1221
- hasTestsToRun = isCoordinator ? this.sourcedPickles.length > 0 : this.pickleIds.length > 0
1222
1220
  pickleByFile = isCoordinator ? getPickleByFileNew(this) : getPickleByFile(this)
1223
1221
 
1224
1222
  if (isKnownTestsEnabled) {
@@ -1330,10 +1328,17 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
1330
1328
  global.__coverage__ = fromCoverageMapToCoverage(originalCoverageMap)
1331
1329
  }
1332
1330
 
1333
- const isExpectedEmptySession = success && !hasTestsToRun
1331
+ const testCaseAttempts = (this.eventDataCollector || eventDataCollector).getTestCaseAttempts()
1332
+ const getStatus = satisfies(frameworkVersion, '>=7.3.0') ? getStatusFromResultLatest : getStatusFromResult
1333
+ const hasExecutedTests = testCaseAttempts.some(({ worstTestStepResult }) =>
1334
+ getStatus(worstTestStepResult).status !== 'skip'
1335
+ )
1336
+ const testSessionEmptyReason = success && !hasExecutedTests
1337
+ ? (testCaseAttempts.length > 0 || skippedSuites.length > 0 ? 'all_tests_skipped' : 'zero_tests')
1338
+ : undefined
1334
1339
  const flushPromise = getChannelPromise(sessionFinishCh, {
1335
- status: isExpectedEmptySession ? 'skip' : (success ? 'pass' : 'fail'),
1336
- isExpectedEmptySession,
1340
+ status: testSessionEmptyReason ? 'skip' : (success ? 'pass' : 'fail'),
1341
+ testSessionEmptyReason,
1337
1342
  isSuitesSkipped,
1338
1343
  testCodeCoverageLinesTotal,
1339
1344
  testSessionCoverageFiles,
@@ -426,15 +426,16 @@ function registerManualAfterScreenshotHandlers (on, handlers, datadogHandler) {
426
426
  }
427
427
 
428
428
  /**
429
- * Registers one Cypress after:spec handler that runs every collected handler
429
+ * Registers one Cypress lifecycle handler that runs every collected handler
430
430
  * in registration order. Cypress 10+ otherwise keeps only the last handler.
431
431
  *
432
432
  * @param {Function} on Cypress event registration function
433
- * @param {Function[]} handlers collected after:spec handlers
434
- * @param {Function} [datadogHandler] manual Datadog after:spec handler
433
+ * @param {'before:run'|'after:spec'} event lifecycle event
434
+ * @param {Function[]} handlers collected lifecycle handlers
435
+ * @param {Function} [datadogHandler] Datadog lifecycle handler
435
436
  * @param {Function} [cleanup] removes generated support files after an error
436
437
  */
437
- function registerAfterSpecHandlers (on, handlers, datadogHandler, cleanup) {
438
+ function registerLifecycleHandlers (on, event, handlers, datadogHandler, cleanup) {
438
439
  const userHandlers = datadogHandler
439
440
  ? handlers.filter(handler => handler !== datadogHandler)
440
441
  : handlers
@@ -442,27 +443,31 @@ function registerAfterSpecHandlers (on, handlers, datadogHandler, cleanup) {
442
443
  if (userHandlers.length === 0) {
443
444
  if (datadogHandler) {
444
445
  if (cleanup) {
445
- on('after:spec', (...args) => Promise.resolve().then(() => datadogHandler(...args)).catch((error) => {
446
+ on(event, (...args) => Promise.resolve().then(() => datadogHandler(...args)).catch((error) => {
446
447
  cleanup()
447
448
  throw error
448
449
  }))
449
450
  } else {
450
- on('after:spec', datadogHandler)
451
+ on(event, datadogHandler)
451
452
  }
452
453
  }
453
454
  return
454
455
  }
455
456
 
456
- on('after:spec', (spec, results) => {
457
+ on(event, (...args) => {
457
458
  const callHandler = datadogHandler
458
- ? handler => runUserHandler(() => handler(spec, results))
459
- : handler => handler(spec, results)
459
+ ? handler => runUserHandler(() => handler(...args))
460
+ : handler => handler(...args)
460
461
  const chain = userHandlers.reduce(
461
462
  (promise, handler) => promise.then(() => callHandler(handler)),
462
463
  Promise.resolve()
463
464
  )
464
465
  if (!datadogHandler) return chain
465
- const finalization = finalizeAfterUserHandlers(chain, (...args) => datadogHandler(spec, results, ...args))
466
+ const finalization = finalizeAfterUserHandlers(chain, (...errors) => {
467
+ // A failed setup hook must abort the run before Datadog starts its session.
468
+ if (event === 'before:run' && errors.length > 0) return
469
+ return datadogHandler(...args, ...errors)
470
+ })
466
471
  if (!cleanup) return finalization
467
472
  return finalization.catch((error) => {
468
473
  cleanup()
@@ -514,6 +519,9 @@ function registerDdTraceHooks (
514
519
  if (generatedSupportFiles) registerGeneratedFilesForExitCleanup(generatedSupportFiles)
515
520
 
516
521
  const cleanupWrapper = () => {
522
+ // Open mode reuses this support file across runs, including failed setup attempts.
523
+ // The registered process-exit cleanup owns its lifetime instead.
524
+ if (config.isInteractive) return
517
525
  if (generatedSupportFiles) cleanupGeneratedFiles(generatedSupportFiles)
518
526
  }
519
527
 
@@ -537,8 +545,13 @@ function registerDdTraceHooks (
537
545
  })
538
546
  }
539
547
 
548
+ const registerBeforeRun = handler => {
549
+ registerLifecycleHandlers(on, 'before:run', userBeforeRunHandlers, handler, cleanupWrapper)
550
+ }
551
+
540
552
  const registerNoopHandlers = () => {
541
- registerAfterSpecHandlers(on, userAfterSpecHandlers)
553
+ registerBeforeRun()
554
+ registerLifecycleHandlers(on, 'after:spec', userAfterSpecHandlers)
542
555
  for (const h of userAfterScreenshotHandlers) on('after:screenshot', h)
543
556
  registerAfterRunWithCleanup()
544
557
  on('task', noopTask)
@@ -555,8 +568,8 @@ function registerDdTraceHooks (
555
568
  manualPlugin.initialConfig.experimentalInteractiveRunEvents = config.experimentalInteractiveRunEvents
556
569
  }
557
570
  }
558
- for (const handler of userBeforeRunHandlers) on('before:run', handler)
559
- registerAfterSpecHandlers(on, userAfterSpecHandlers, manualPlugin.afterSpecHandler, cleanupWrapper)
571
+ registerBeforeRun(manualPlugin.beforeRunHandler)
572
+ registerLifecycleHandlers(on, 'after:spec', userAfterSpecHandlers, manualPlugin.afterSpecHandler, cleanupWrapper)
560
573
  registerManualAfterScreenshotHandlers(on, userAfterScreenshotHandlers, manualPlugin.afterScreenshotHandler)
561
574
  registerAfterRunWithCleanup(manualPlugin.afterRunHandler)
562
575
  on('task', manualPlugin.taskHandler)
@@ -572,8 +585,6 @@ function registerDdTraceHooks (
572
585
  )
573
586
  }
574
587
 
575
- for (const handler of userBeforeRunHandlers) on('before:run', handler)
576
-
577
588
  if (!setupNodeEventsCh.hasSubscribers) {
578
589
  registerNoopHandlers()
579
590
  return config
@@ -588,6 +599,7 @@ function registerDdTraceHooks (
588
599
  userAfterSpecHandlers,
589
600
  userAfterRunHandlers,
590
601
  userAfterScreenshotHandlers,
602
+ registerBeforeRun,
591
603
  cleanupWrapper,
592
604
  registered: false,
593
605
  configPromise: undefined,
@@ -13,6 +13,7 @@ const {
13
13
  } = require('./instrumentation-utils')
14
14
  const hooks = require('./hooks')
15
15
  const instrumentations = require('./instrumentations')
16
+ const { isRewriteActivationEnabled } = require('./rewriter/targets')
16
17
  const disabledInstrumentations = getDisabledInstrumentations()
17
18
 
18
19
  // register.js has now set up ritm (require-in-the-middle). In bundled
@@ -94,6 +95,11 @@ dc.subscribe(CHANNEL, (message) => {
94
95
  const name = payload.package
95
96
  if (disabledInstrumentations.has(name)) return
96
97
 
98
+ if (payload.activate && isRewriteActivationEnabled(name)) {
99
+ loadChannel.publish({ name })
100
+ return
101
+ }
102
+
97
103
  const isPrefixedWithNode = name.startsWith('node:')
98
104
  const isNodeModule = isPrefixedWithNode || !hooks[name]
99
105
 
@@ -69,6 +69,7 @@ const earlyLoadFrameworks = new Map([
69
69
  */
70
70
  module.exports.checkForRequiredModules = function () {
71
71
  const packages = require('./hooks')
72
+ const { isRewriteTargetName } = require('./rewriter/targets')
72
73
  const naughties = new Set()
73
74
  const frameworksSeen = new Set()
74
75
  let didWarn = false
@@ -98,7 +99,7 @@ module.exports.checkForRequiredModules = function () {
98
99
  continue
99
100
  }
100
101
 
101
- if (naughties.has(pkg) || !(pkg in packages)) continue
102
+ if (naughties.has(pkg) || (!(pkg in packages) && !isRewriteTargetName(pkg))) continue
102
103
 
103
104
  loadOrderWarnings.push(
104
105
  () => `Warning: Package '${pkg}' was loaded before dd-trace! This may break instrumentation.`
@@ -25,14 +25,12 @@ module.exports = {
25
25
  '@anthropic-ai/sdk': { esmFirst: true, fn: () => require('../anthropic') },
26
26
  '@apollo/server': () => require('../apollo-server'),
27
27
  '@apollo/gateway': () => require('../apollo'),
28
- '@langchain/langgraph': { esmFirst: true, fn: () => require('../langgraph') },
29
28
  '@modelcontextprotocol/sdk': { esmFirst: true, fn: () => require('../modelcontextprotocol-sdk') },
30
29
  '@openai/agents': () => require('../openai-agents'),
31
30
  '@openai/agents-openai': () => require('../openai-agents'),
32
31
  'apollo-server-core': () => require('../apollo-server-core'),
33
32
  '@aws-sdk/smithy-client': () => require('../aws-sdk'),
34
33
  '@aws/durable-execution-sdk-js': () => require('../aws-durable-execution-sdk-js'),
35
- '@azure/cosmos': { esmFirst: true, fn: () => require('../azure-cosmos') },
36
34
  '@azure/event-hubs': () => require('../azure-event-hubs'),
37
35
  '@azure/functions': () => require('../azure-functions'),
38
36
  'durable-functions': () => require('../azure-durable-functions'),
@@ -54,7 +52,6 @@ module.exports = {
54
52
  '@jest/test-sequencer': () => require('../jest'),
55
53
  '@jest/transform': () => require('../jest'),
56
54
  '@koa/router': () => require('../koa'),
57
- '@langchain/core': { esmFirst: true, fn: () => require('../langchain') },
58
55
  '@node-redis/client': () => require('../redis'),
59
56
  '@opensearch-project/opensearch': () => require('../opensearch'),
60
57
  '@opentelemetry/sdk-trace': () => require('../otel-sdk-trace'),
@@ -78,7 +75,6 @@ module.exports = {
78
75
  bluebird: () => require('../bluebird'),
79
76
  'body-parser': () => require('../body-parser'),
80
77
  'browser-bunyan': () => require('../browser-bunyan'),
81
- bullmq: () => require('../bullmq'),
82
78
  bunyan: () => require('../bunyan'),
83
79
  'cassandra-driver': () => require('../cassandra-driver'),
84
80
  connect: () => require('../connect'),
@@ -114,14 +110,12 @@ module.exports = {
114
110
  'koa-router': () => require('../koa'),
115
111
  '@confluentinc/kafka-javascript': () => require('../confluentinc-kafka-javascript'),
116
112
  kafkajs: () => require('../kafkajs'),
117
- langchain: () => require('../langchain'),
118
113
  ldapjs: () => require('../ldapjs'),
119
114
  'light-my-request': () => require('../light-my-request'),
120
115
  'limitd-client': () => require('../limitd-client'),
121
116
  lodash: () => require('../lodash'),
122
117
  mariadb: { esmFirst: true, fn: () => require('../mariadb') },
123
118
  memcached: () => require('../memcached'),
124
- mercurius: () => require('../mercurius'),
125
119
  'microgateway-core': () => require('../microgateway-core'),
126
120
  mocha: () => require('../mocha'),
127
121
  'mocha-each': () => require('../mocha'),
@@ -25,6 +25,7 @@ const pathSepExpr = new RegExp(`\\${path.sep}`, 'g')
25
25
  const disabledInstrumentations = getDisabledInstrumentations()
26
26
 
27
27
  const loadChannel = channel('dd-trace:instrumentation:load')
28
+ const orchestrionLoadChannel = channel('dd-trace:instrumentation:load:orchestrion')
28
29
 
29
30
  // Globals
30
31
  if (!disabledInstrumentations.has('fetch')) {
@@ -55,6 +56,25 @@ const instrumentedNodeModules = new Map()
55
56
  const instrumentedIntegrationsSuccess = new Map()
56
57
  /** @type {Set<string>} */
57
58
  const alreadyLoggedIncompatibleIntegrations = new Set()
59
+ /** @type {Set<string>} */
60
+ const compatibleOrchestrionTargets = new Set()
61
+
62
+ orchestrionLoadChannel.subscribe(({ moduleName, version, result }) => {
63
+ const nameVersion = `${moduleName}@${version}`
64
+
65
+ if (result === 'unsupported') {
66
+ if (!compatibleOrchestrionTargets.has(nameVersion) && !instrumentedIntegrationsSuccess.has(nameVersion)) {
67
+ instrumentedIntegrationsSuccess.set(nameVersion, false)
68
+ }
69
+ return
70
+ }
71
+
72
+ if (result === 'matched' || result === 'rewritten') {
73
+ compatibleOrchestrionTargets.add(nameVersion)
74
+ instrumentedIntegrationsSuccess.set(nameVersion, true)
75
+ if (result === 'rewritten') loadChannel.publish({ name: moduleName })
76
+ }
77
+ })
58
78
 
59
79
  for (const name of names) {
60
80
  if (disabledInstrumentations.has(name)) continue
@@ -19,7 +19,7 @@ const { getRewriteTarget } = require('./targets')
19
19
  * { code: string, map?: string|object }} transform
20
20
  *
21
21
  * @typedef {(content: string|Buffer|ArrayBuffer|Uint8Array, filename: string, format?: string,
22
- * target?: { moduleName: string, filePath: string }, sourceMap?: string|object) =>
22
+ * target?: { moduleName: string, filePath: string, activate?: boolean }, sourceMap?: string|object) =>
23
23
  * { code: string|Buffer|ArrayBuffer|Uint8Array, map?: string|object }} BundlerRewriter
24
24
  */
25
25
 
@@ -62,7 +62,7 @@ function normalizeFilename (filename) {
62
62
  * @param {string|Buffer|ArrayBuffer|Uint8Array} content
63
63
  * @param {string} filename
64
64
  * @param {string} [format]
65
- * @param {{ moduleName: string, filePath: string }} [target]
65
+ * @param {{ moduleName: string, filePath: string, activate?: boolean }} [target]
66
66
  * @returns {string|Buffer|ArrayBuffer|Uint8Array}
67
67
  */
68
68
  function rewrite (content, filename, format, target) {
@@ -74,7 +74,7 @@ function rewrite (content, filename, format, target) {
74
74
  if (!target) return content
75
75
 
76
76
  const moduleType = format === 'module' ? 'esm' : 'cjs'
77
- const { moduleName, filePath } = target
77
+ const { moduleName, filePath, activate } = target
78
78
  if (disabled.has(moduleName)) return content
79
79
 
80
80
  const version = getVersion(filename, filePath)
@@ -82,10 +82,18 @@ function rewrite (content, filename, format, target) {
82
82
 
83
83
  const transformer = getMatcher(moduleType).getTransformer(moduleName, version, filePath)
84
84
 
85
- if (!transformer) return content
85
+ if (!transformer && !activate) return content
86
86
 
87
87
  const source = getSourceText(content)
88
88
 
89
+ if (!transformer) {
90
+ return appendOrchestrionLoad(
91
+ source,
92
+ { moduleName, version, result: 'unsupported' },
93
+ moduleType
94
+ )
95
+ }
96
+
89
97
  // TODO: pass existing sourcemap as input for remapping
90
98
  let { code, map } = transformer.transform(source, moduleType)
91
99
 
@@ -98,6 +106,11 @@ function rewrite (content, filename, format, target) {
98
106
  map = shiftSourceMapLine(map)
99
107
  }
100
108
 
109
+ if (activate) {
110
+ const result = code === source ? 'matched' : 'rewritten'
111
+ code = appendOrchestrionLoad(code, { moduleName, version, result }, moduleType)
112
+ }
113
+
101
114
  if (!map) return code
102
115
 
103
116
  const inlineMap = Buffer.from(typeof map === 'string' ? map : JSON.stringify(map)).toString('base64')
@@ -236,6 +249,30 @@ function getSourceText (source) {
236
249
  return Buffer.from(source).toString('utf8')
237
250
  }
238
251
 
252
+ /**
253
+ * Publish target-level compatibility on the application thread when a pure target is evaluated.
254
+ *
255
+ * @param {string} source
256
+ * @param {{ moduleName: string, version: string,
257
+ * result: 'unsupported'|'matched'|'rewritten' }} payload
258
+ * @param {'cjs'|'esm'} moduleType
259
+ */
260
+ function appendOrchestrionLoad (source, payload, moduleType) {
261
+ const dcModule = JSON.stringify(getDcPolyfillSpecifier(moduleType) ?? 'diagnostics_channel')
262
+ const message = JSON.stringify(payload)
263
+
264
+ if (moduleType === 'esm') {
265
+ let binding = 'ddTraceOrchestrionDc'
266
+ let suffix = 0
267
+ while (source.includes(binding)) binding = `ddTraceOrchestrionDc${++suffix}`
268
+
269
+ return `${source};import ${binding} from ${dcModule};` +
270
+ `${binding}.channel('dd-trace:instrumentation:load:orchestrion').publish(${message});`
271
+ }
272
+
273
+ return `${source};require(${dcModule}).channel('dd-trace:instrumentation:load:orchestrion').publish(${message});`
274
+ }
275
+
239
276
  /**
240
277
  * Account for a shebang restored ahead of the generated program. The transformer already maps original positions
241
278
  * past the input shebang, so only the generated side needs an additional empty line.
@@ -1,17 +1,19 @@
1
1
  'use strict'
2
2
 
3
- // activationName is the plugin-manager key published after a target is successfully rewritten.
3
+ // Activated rewrites publish their module name to the plugin manager after evaluation.
4
+ // Only pure Orchestrion integrations that need this activation set activate: true.
5
+ // Other entries use hooks or another activation path, or do not need activation from a rewrite.
4
6
  const registry = [
5
7
  { instrumentations: require('./instrumentations/ai') },
6
- { activationName: '@azure/cosmos', instrumentations: require('./instrumentations/azure-cosmos') },
8
+ { activate: true, instrumentations: require('./instrumentations/azure-cosmos') },
7
9
  { instrumentations: require('./instrumentations/azure-durable-functions') },
8
- { activationName: 'bullmq', instrumentations: require('./instrumentations/bullmq') },
10
+ { activate: true, instrumentations: require('./instrumentations/bullmq') },
9
11
  { instrumentations: require('./instrumentations/claude-agent-sdk') },
10
12
  { instrumentations: require('./instrumentations/graphql') },
11
13
  { instrumentations: require('./instrumentations/graphql-jit') },
12
- { activationName: '@langchain/core', instrumentations: require('./instrumentations/langchain') },
13
- { activationName: '@langchain/langgraph', instrumentations: require('./instrumentations/langgraph') },
14
- { activationName: 'mercurius', instrumentations: require('./instrumentations/mercurius') },
14
+ { activate: true, instrumentations: require('./instrumentations/langchain') },
15
+ { activate: true, instrumentations: require('./instrumentations/langgraph') },
16
+ { activate: true, instrumentations: require('./instrumentations/mercurius') },
15
17
  { instrumentations: require('./instrumentations/modelcontextprotocol-sdk') },
16
18
  { instrumentations: require('./instrumentations/openai-agents') },
17
19
  { instrumentations: require('./instrumentations/playwright') },
@@ -21,10 +23,10 @@ const registry = [
21
23
  { instrumentations: require('./instrumentations/supabase') },
22
24
  ]
23
25
 
24
- const activationNames = new Map()
25
- for (const { activationName, instrumentations } of registry) {
26
- if (!activationName) continue
27
- for (const { module } of instrumentations) activationNames.set(module.name, activationName)
26
+ const activatedModules = new Set()
27
+ for (const { activate, instrumentations } of registry) {
28
+ if (!activate) continue
29
+ for (const { module } of instrumentations) activatedModules.add(module.name)
28
30
  }
29
31
 
30
32
  const instrumentations = registry.flatMap(entry => entry.instrumentations)
@@ -32,8 +34,8 @@ const instrumentations = registry.flatMap(entry => entry.instrumentations)
32
34
  /**
33
35
  * @param {string} moduleName
34
36
  */
35
- function getRewriteActivationName (moduleName) {
36
- return activationNames.get(moduleName)
37
+ function isRewriteActivationEnabled (moduleName) {
38
+ return activatedModules.has(moduleName)
37
39
  }
38
40
 
39
- module.exports = { getRewriteActivationName, instrumentations, registry }
41
+ module.exports = { isRewriteActivationEnabled, instrumentations, registry }
@@ -3,6 +3,49 @@
3
3
  // Playwright keeps several hook targets in private local classes/functions.
4
4
  // Keep these rewrites limited to bundled internals that addHook cannot wrap.
5
5
  module.exports = [
6
+ {
7
+ module: {
8
+ name: '@playwright/test',
9
+ versionRange: '>=1.18.0 <1.38.0',
10
+ filePath: 'lib/reporters/multiplexer.js',
11
+ },
12
+ functionQuery: {
13
+ className: 'Multiplexer',
14
+ methodName: 'onError',
15
+ kind: 'Sync',
16
+ },
17
+ channelName: 'Multiplexer_onError',
18
+ },
19
+ {
20
+ module: {
21
+ name: 'playwright',
22
+ versionRange: '>=1.44.0 <1.60.0',
23
+ filePath: 'lib/runner/runner.js',
24
+ },
25
+ astQuery: 'FunctionDeclaration[id.name="writeLastRunInfo"] ' +
26
+ 'CallExpression[callee.property.name="map"] > ArrowFunctionExpression',
27
+ channelName: 'lastRunTestId',
28
+ },
29
+ {
30
+ module: {
31
+ name: 'playwright',
32
+ versionRange: '>=1.44.0 <1.60.0',
33
+ filePath: 'lib/runner/lastRun.js',
34
+ },
35
+ astQuery: 'ClassDeclaration[id.name="LastRunReporter"] ' +
36
+ 'CallExpression[callee.property.name="map"] > ArrowFunctionExpression',
37
+ channelName: 'lastRunTestId',
38
+ },
39
+ {
40
+ module: {
41
+ name: 'playwright',
42
+ versionRange: '>=1.60.0',
43
+ filePath: 'lib/runner/index.js',
44
+ },
45
+ astQuery: 'VariableDeclarator[id.name="LastRunReporter"] ' +
46
+ 'CallExpression[callee.property.name="map"] > ArrowFunctionExpression',
47
+ channelName: 'lastRunTestId',
48
+ },
6
49
  {
7
50
  module: {
8
51
  name: 'playwright',
@@ -1,6 +1,19 @@
1
1
  'use strict'
2
2
 
3
3
  module.exports = [
4
+ {
5
+ module: {
6
+ name: '@wdio/config',
7
+ versionRange: '>=9.0.0',
8
+ filePath: 'build/node/index.js',
9
+ },
10
+ functionQuery: {
11
+ className: 'ConfigParser',
12
+ methodName: 'shard',
13
+ kind: 'Sync',
14
+ },
15
+ channelName: 'ConfigParser_shard',
16
+ },
4
17
  {
5
18
  module: {
6
19
  name: '@wdio/cli',