dd-trace 5.38.0 → 5.40.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 (97) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/index.d.ts +30 -21
  3. package/package.json +4 -2
  4. package/packages/datadog-instrumentations/src/apollo-server-core.js +1 -1
  5. package/packages/datadog-instrumentations/src/apollo-server.js +1 -1
  6. package/packages/datadog-instrumentations/src/express-session.js +41 -0
  7. package/packages/datadog-instrumentations/src/fetch.js +27 -6
  8. package/packages/datadog-instrumentations/src/helpers/fetch.js +6 -1
  9. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  10. package/packages/datadog-instrumentations/src/jest.js +16 -10
  11. package/packages/datadog-instrumentations/src/mocha/main.js +2 -1
  12. package/packages/datadog-instrumentations/src/nyc.js +2 -1
  13. package/packages/datadog-instrumentations/src/vitest.js +4 -2
  14. package/packages/datadog-plugin-amqplib/src/consumer.js +1 -1
  15. package/packages/datadog-plugin-amqplib/src/producer.js +1 -2
  16. package/packages/datadog-plugin-avsc/src/schema_iterator.js +1 -1
  17. package/packages/datadog-plugin-aws-sdk/src/base.js +5 -1
  18. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +9 -8
  19. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +1 -4
  20. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +1 -2
  21. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +1 -2
  22. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +1 -1
  23. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +1 -2
  24. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +1 -1
  25. package/packages/datadog-plugin-kafkajs/src/consumer.js +5 -2
  26. package/packages/datadog-plugin-kafkajs/src/producer.js +4 -3
  27. package/packages/datadog-plugin-mongodb-core/src/index.js +10 -13
  28. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +1 -1
  29. package/packages/datadog-plugin-rhea/src/consumer.js +1 -1
  30. package/packages/datadog-plugin-rhea/src/producer.js +1 -2
  31. package/packages/datadog-shimmer/src/shimmer.js +95 -95
  32. package/packages/dd-trace/src/appsec/addresses.js +1 -0
  33. package/packages/dd-trace/src/appsec/channels.js +1 -0
  34. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +1 -1
  35. package/packages/dd-trace/src/appsec/iast/iast-context.js +2 -2
  36. package/packages/dd-trace/src/appsec/iast/index.js +0 -1
  37. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -2
  38. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +3 -5
  39. package/packages/dd-trace/src/appsec/index.js +23 -1
  40. package/packages/dd-trace/src/appsec/reporter.js +3 -8
  41. package/packages/dd-trace/src/appsec/rule_manager.js +1 -1
  42. package/packages/dd-trace/src/appsec/sdk/set_user.js +9 -5
  43. package/packages/dd-trace/src/appsec/sdk/track_event.js +2 -4
  44. package/packages/dd-trace/src/appsec/telemetry/common.js +24 -0
  45. package/packages/dd-trace/src/appsec/telemetry/index.js +126 -0
  46. package/packages/dd-trace/src/appsec/telemetry/rasp.js +35 -0
  47. package/packages/dd-trace/src/appsec/telemetry/user.js +24 -0
  48. package/packages/dd-trace/src/appsec/telemetry/waf.js +92 -0
  49. package/packages/dd-trace/src/appsec/user_tracking.js +2 -4
  50. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +16 -4
  51. package/packages/dd-trace/src/config.js +31 -14
  52. package/packages/dd-trace/src/constants.js +1 -1
  53. package/packages/dd-trace/src/{data_streams.js → datastreams/checkpointer.js} +1 -1
  54. package/packages/dd-trace/src/{data_streams_context.js → datastreams/context.js} +2 -2
  55. package/packages/dd-trace/src/datastreams/index.js +104 -0
  56. package/packages/dd-trace/src/datastreams/manager.js +27 -0
  57. package/packages/dd-trace/src/datastreams/processor.js +1 -44
  58. package/packages/dd-trace/src/datastreams/size.js +53 -0
  59. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +2 -2
  60. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +1 -1
  61. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +22 -15
  62. package/packages/dd-trace/src/dogstatsd.js +23 -4
  63. package/packages/dd-trace/src/exporters/agent/index.js +2 -2
  64. package/packages/dd-trace/src/flare/index.js +3 -0
  65. package/packages/dd-trace/src/noop/dogstatsd.js +6 -0
  66. package/packages/dd-trace/src/opentelemetry/tracer.js +45 -1
  67. package/packages/dd-trace/src/opentracing/propagation/text_map.js +11 -47
  68. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +1 -1
  69. package/packages/dd-trace/src/opentracing/span.js +12 -2
  70. package/packages/dd-trace/src/payload-tagging/config/aws.json +8 -0
  71. package/packages/dd-trace/src/plugin_manager.js +4 -3
  72. package/packages/dd-trace/src/plugins/ci_plugin.js +2 -2
  73. package/packages/dd-trace/src/priority_sampler.js +5 -3
  74. package/packages/dd-trace/src/profiling/profiler.js +1 -1
  75. package/packages/dd-trace/src/profiling/profilers/wall.js +15 -4
  76. package/packages/dd-trace/src/proxy.js +41 -22
  77. package/packages/dd-trace/src/{appsec/remote_config → remote_config}/capabilities.js +1 -0
  78. package/packages/dd-trace/src/{appsec/remote_config → remote_config}/index.js +8 -5
  79. package/packages/dd-trace/src/{appsec/remote_config → remote_config}/manager.js +5 -5
  80. package/packages/dd-trace/src/runtime_metrics/index.js +34 -0
  81. package/packages/dd-trace/src/{runtime_metrics.js → runtime_metrics/runtime_metrics.js} +4 -4
  82. package/packages/dd-trace/src/serverless.js +10 -1
  83. package/packages/dd-trace/src/service-naming/index.js +12 -4
  84. package/packages/dd-trace/src/span_processor.js +7 -4
  85. package/packages/dd-trace/src/span_stats.js +1 -2
  86. package/packages/dd-trace/src/standalone/index.js +70 -0
  87. package/packages/dd-trace/src/standalone/product.js +24 -0
  88. package/packages/dd-trace/src/standalone/tracesource.js +22 -0
  89. package/packages/dd-trace/src/standalone/tracesource_priority_sampler.js +47 -0
  90. package/packages/dd-trace/src/telemetry/index.js +16 -387
  91. package/packages/dd-trace/src/telemetry/telemetry.js +394 -0
  92. package/packages/dd-trace/src/tracer.js +7 -15
  93. package/packages/dd-trace/src/appsec/standalone.js +0 -130
  94. package/packages/dd-trace/src/appsec/telemetry.js +0 -218
  95. package/packages/dd-trace/src/service-naming/schemas/index.js +0 -6
  96. /package/packages/dd-trace/src/{appsec/remote_config → remote_config}/apply_states.js +0 -0
  97. /package/packages/dd-trace/src/{appsec/remote_config → remote_config}/scheduler.js +0 -0
@@ -0,0 +1,126 @@
1
+ 'use strict'
2
+
3
+ const { DD_TELEMETRY_REQUEST_METRICS } = require('./common')
4
+ const { addRaspRequestMetrics, trackRaspMetrics } = require('./rasp')
5
+ const { incrementMissingUserId, incrementMissingUserLogin } = require('./user')
6
+ const {
7
+ addWafRequestMetrics,
8
+ trackWafMetrics,
9
+ incrementWafInit,
10
+ incrementWafUpdates,
11
+ incrementWafRequests
12
+ } = require('./waf')
13
+
14
+ const metricsStoreMap = new WeakMap()
15
+
16
+ let enabled = false
17
+
18
+ function enable (telemetryConfig) {
19
+ enabled = telemetryConfig?.enabled && telemetryConfig.metrics
20
+ }
21
+
22
+ function disable () {
23
+ enabled = false
24
+ }
25
+
26
+ function newStore () {
27
+ return {
28
+ [DD_TELEMETRY_REQUEST_METRICS]: {
29
+ duration: 0,
30
+ durationExt: 0,
31
+ raspDuration: 0,
32
+ raspDurationExt: 0,
33
+ raspEvalCount: 0
34
+ }
35
+ }
36
+ }
37
+
38
+ function getStore (req) {
39
+ let store = metricsStoreMap.get(req)
40
+ if (!store) {
41
+ store = newStore()
42
+ metricsStoreMap.set(req, store)
43
+ }
44
+ return store
45
+ }
46
+
47
+ function updateRaspRequestsMetricTags (metrics, req, raspRule) {
48
+ if (!req) return
49
+
50
+ const store = getStore(req)
51
+
52
+ // it does not depend on whether telemetry is enabled or not
53
+ addRaspRequestMetrics(store, metrics)
54
+
55
+ if (!enabled) return
56
+
57
+ trackRaspMetrics(metrics, raspRule)
58
+ }
59
+
60
+ function updateWafRequestsMetricTags (metrics, req) {
61
+ if (!req) return
62
+
63
+ const store = getStore(req)
64
+
65
+ // it does not depend on whether telemetry is enabled or not
66
+ addWafRequestMetrics(store, metrics)
67
+
68
+ if (!enabled) return
69
+
70
+ return trackWafMetrics(store, metrics)
71
+ }
72
+
73
+ function incrementWafInitMetric (wafVersion, rulesVersion) {
74
+ if (!enabled) return
75
+
76
+ incrementWafInit(wafVersion, rulesVersion)
77
+ }
78
+
79
+ function incrementWafUpdatesMetric (wafVersion, rulesVersion) {
80
+ if (!enabled) return
81
+
82
+ incrementWafUpdates(wafVersion, rulesVersion)
83
+ }
84
+
85
+ function incrementWafRequestsMetric (req) {
86
+ if (!req || !enabled) return
87
+
88
+ const store = getStore(req)
89
+ incrementWafRequests(store)
90
+
91
+ metricsStoreMap.delete(req)
92
+ }
93
+
94
+ function incrementMissingUserLoginMetric (framework, eventType) {
95
+ if (!enabled) return
96
+
97
+ incrementMissingUserLogin(framework, eventType)
98
+ }
99
+
100
+ function incrementMissingUserIdMetric (framework, eventType) {
101
+ if (!enabled) return
102
+
103
+ incrementMissingUserId(framework, eventType)
104
+ }
105
+
106
+ function getRequestMetrics (req) {
107
+ if (req) {
108
+ const store = getStore(req)
109
+ return store?.[DD_TELEMETRY_REQUEST_METRICS]
110
+ }
111
+ }
112
+
113
+ module.exports = {
114
+ enable,
115
+ disable,
116
+
117
+ updateWafRequestsMetricTags,
118
+ updateRaspRequestsMetricTags,
119
+ incrementWafInitMetric,
120
+ incrementWafUpdatesMetric,
121
+ incrementWafRequestsMetric,
122
+ incrementMissingUserLoginMetric,
123
+ incrementMissingUserIdMetric,
124
+
125
+ getRequestMetrics
126
+ }
@@ -0,0 +1,35 @@
1
+ 'use strict'
2
+
3
+ const telemetryMetrics = require('../../telemetry/metrics')
4
+ const { DD_TELEMETRY_REQUEST_METRICS } = require('./common')
5
+
6
+ const appsecMetrics = telemetryMetrics.manager.namespace('appsec')
7
+
8
+ function addRaspRequestMetrics (store, { duration, durationExt }) {
9
+ store[DD_TELEMETRY_REQUEST_METRICS].raspDuration += duration || 0
10
+ store[DD_TELEMETRY_REQUEST_METRICS].raspDurationExt += durationExt || 0
11
+ store[DD_TELEMETRY_REQUEST_METRICS].raspEvalCount++
12
+ }
13
+
14
+ function trackRaspMetrics (metrics, raspRule) {
15
+ const tags = { rule_type: raspRule.type, waf_version: metrics.wafVersion }
16
+
17
+ if (raspRule.variant) {
18
+ tags.rule_variant = raspRule.variant
19
+ }
20
+
21
+ appsecMetrics.count('rasp.rule.eval', tags).inc(1)
22
+
23
+ if (metrics.wafTimeout) {
24
+ appsecMetrics.count('rasp.timeout', tags).inc(1)
25
+ }
26
+
27
+ if (metrics.ruleTriggered) {
28
+ appsecMetrics.count('rasp.rule.match', tags).inc(1)
29
+ }
30
+ }
31
+
32
+ module.exports = {
33
+ addRaspRequestMetrics,
34
+ trackRaspMetrics
35
+ }
@@ -0,0 +1,24 @@
1
+ 'use strict'
2
+
3
+ const telemetryMetrics = require('../../telemetry/metrics')
4
+
5
+ const appsecMetrics = telemetryMetrics.manager.namespace('appsec')
6
+
7
+ function incrementMissingUserLogin (framework, eventType) {
8
+ appsecMetrics.count('instrum.user_auth.missing_user_login', {
9
+ framework,
10
+ event_type: eventType
11
+ }).inc()
12
+ }
13
+
14
+ function incrementMissingUserId (framework, eventType) {
15
+ appsecMetrics.count('instrum.user_auth.missing_user_id', {
16
+ framework,
17
+ event_type: eventType
18
+ }).inc()
19
+ }
20
+
21
+ module.exports = {
22
+ incrementMissingUserLogin,
23
+ incrementMissingUserId
24
+ }
@@ -0,0 +1,92 @@
1
+ 'use strict'
2
+
3
+ const telemetryMetrics = require('../../telemetry/metrics')
4
+ const { tags, getVersionsTags, DD_TELEMETRY_REQUEST_METRICS } = require('./common')
5
+
6
+ const appsecMetrics = telemetryMetrics.manager.namespace('appsec')
7
+
8
+ const DD_TELEMETRY_WAF_RESULT_TAGS = Symbol('_dd.appsec.telemetry.waf.result.tags')
9
+
10
+ function addWafRequestMetrics (store, { duration, durationExt }) {
11
+ store[DD_TELEMETRY_REQUEST_METRICS].duration += duration || 0
12
+ store[DD_TELEMETRY_REQUEST_METRICS].durationExt += durationExt || 0
13
+ }
14
+
15
+ function trackWafDurations ({ duration, durationExt }, versionsTags) {
16
+ if (duration) {
17
+ appsecMetrics.distribution('waf.duration', versionsTags).track(duration)
18
+ }
19
+
20
+ if (durationExt) {
21
+ appsecMetrics.distribution('waf.duration_ext', versionsTags).track(durationExt)
22
+ }
23
+ }
24
+
25
+ function trackWafMetrics (store, metrics) {
26
+ const versionsTags = getVersionsTags(metrics.wafVersion, metrics.rulesVersion)
27
+
28
+ trackWafDurations(metrics, versionsTags)
29
+
30
+ const metricTags = getOrCreateMetricTags(store, versionsTags)
31
+
32
+ const { blockTriggered, ruleTriggered, wafTimeout } = metrics
33
+
34
+ if (blockTriggered) {
35
+ metricTags[tags.REQUEST_BLOCKED] = true
36
+ }
37
+
38
+ if (ruleTriggered) {
39
+ metricTags[tags.RULE_TRIGGERED] = true
40
+ }
41
+
42
+ if (wafTimeout) {
43
+ metricTags[tags.WAF_TIMEOUT] = true
44
+ }
45
+
46
+ return metricTags
47
+ }
48
+
49
+ function getOrCreateMetricTags (store, versionsTags) {
50
+ let metricTags = store[DD_TELEMETRY_WAF_RESULT_TAGS]
51
+
52
+ if (!metricTags) {
53
+ metricTags = {
54
+ [tags.REQUEST_BLOCKED]: false,
55
+ [tags.RULE_TRIGGERED]: false,
56
+ [tags.WAF_TIMEOUT]: false,
57
+
58
+ ...versionsTags
59
+ }
60
+ store[DD_TELEMETRY_WAF_RESULT_TAGS] = metricTags
61
+ }
62
+
63
+ return metricTags
64
+ }
65
+
66
+ function incrementWafInit (wafVersion, rulesVersion) {
67
+ const versionsTags = getVersionsTags(wafVersion, rulesVersion)
68
+
69
+ appsecMetrics.count('waf.init', versionsTags).inc()
70
+ }
71
+
72
+ function incrementWafUpdates (wafVersion, rulesVersion) {
73
+ const versionsTags = getVersionsTags(wafVersion, rulesVersion)
74
+
75
+ appsecMetrics.count('waf.updates', versionsTags).inc()
76
+ }
77
+
78
+ function incrementWafRequests (store) {
79
+ const metricTags = store[DD_TELEMETRY_WAF_RESULT_TAGS]
80
+
81
+ if (metricTags) {
82
+ appsecMetrics.count('waf.requests', metricTags).inc()
83
+ }
84
+ }
85
+
86
+ module.exports = {
87
+ addWafRequestMetrics,
88
+ trackWafMetrics,
89
+ incrementWafInit,
90
+ incrementWafUpdates,
91
+ incrementWafRequests
92
+ }
@@ -5,9 +5,8 @@ const log = require('../log')
5
5
  const telemetry = require('./telemetry')
6
6
  const addresses = require('./addresses')
7
7
  const { keepTrace } = require('../priority_sampler')
8
- const { SAMPLING_MECHANISM_APPSEC } = require('../constants')
9
- const standalone = require('./standalone')
10
8
  const waf = require('./waf')
9
+ const { ASM } = require('../standalone/product')
11
10
 
12
11
  // the RFC doesn't include '_id', but it's common in MongoDB
13
12
  const USER_ID_FIELDS = ['id', '_id', 'email', 'username', 'login', 'user']
@@ -151,8 +150,7 @@ function trackLogin (framework, login, user, success, rootSpan) {
151
150
  persistent[addresses.LOGIN_FAILURE] = null
152
151
  }
153
152
 
154
- keepTrace(rootSpan, SAMPLING_MECHANISM_APPSEC)
155
- standalone.sample(rootSpan)
153
+ keepTrace(rootSpan, ASM)
156
154
 
157
155
  rootSpan.addTags(newTags)
158
156
 
@@ -9,7 +9,8 @@ const probeIdToResolveBreakpointSet = new Map()
9
9
  const probeIdToResolveBreakpointRemove = new Map()
10
10
 
11
11
  class TestVisDynamicInstrumentation {
12
- constructor () {
12
+ constructor (config) {
13
+ this._config = config
13
14
  this.worker = null
14
15
  this._readyPromise = new Promise(resolve => {
15
16
  this._onReady = resolve
@@ -32,6 +33,9 @@ class TestVisDynamicInstrumentation {
32
33
  // 1. Probe ID
33
34
  // 2. Promise that's resolved when the breakpoint is set
34
35
  addLineProbe ({ file, line }, onHitBreakpoint) {
36
+ if (!this.worker) { // not init yet
37
+ this.start()
38
+ }
35
39
  const probeId = randomUUID()
36
40
 
37
41
  this.breakpointSetChannel.port2.postMessage(
@@ -52,7 +56,7 @@ class TestVisDynamicInstrumentation {
52
56
  return this._readyPromise
53
57
  }
54
58
 
55
- start (config) {
59
+ start () {
56
60
  if (this.worker) return
57
61
 
58
62
  log.debug('Starting Test Visibility - Dynamic Instrumentation client...')
@@ -77,7 +81,7 @@ class TestVisDynamicInstrumentation {
77
81
  DD_TRACE_TELEMETRY_ENABLED: 0
78
82
  },
79
83
  workerData: {
80
- config: config.serialize(),
84
+ config: this._config.serialize(),
81
85
  parentThreadId,
82
86
  rcPort: rcChannel.port1,
83
87
  configPort: configChannel.port1,
@@ -138,4 +142,12 @@ class TestVisDynamicInstrumentation {
138
142
  }
139
143
  }
140
144
 
141
- module.exports = new TestVisDynamicInstrumentation()
145
+ let dynamicInstrumentation
146
+
147
+ module.exports = (config) => {
148
+ if (dynamicInstrumentation) {
149
+ return dynamicInstrumentation
150
+ }
151
+ dynamicInstrumentation = new TestVisDynamicInstrumentation(config)
152
+ return dynamicInstrumentation
153
+ }
@@ -16,7 +16,7 @@ const { GIT_REPOSITORY_URL, GIT_COMMIT_SHA } = require('./plugins/util/tags')
16
16
  const { getGitMetadataFromGitProperties, removeUserSensitiveInfo } = require('./git_properties')
17
17
  const { updateConfig } = require('./telemetry')
18
18
  const telemetryMetrics = require('./telemetry/metrics')
19
- const { getIsGCPFunction, getIsAzureFunction } = require('./serverless')
19
+ const { isInServerlessEnvironment, getIsGCPFunction, getIsAzureFunction } = require('./serverless')
20
20
  const { ORIGIN_KEY, GRPC_CLIENT_ERROR_STATUSES, GRPC_SERVER_ERROR_STATUSES } = require('./constants')
21
21
  const { appendRules } = require('./payload-tagging/config')
22
22
 
@@ -419,10 +419,7 @@ class Config {
419
419
  }
420
420
 
421
421
  _isInServerlessEnvironment () {
422
- const inAWSLambda = process.env.AWS_LAMBDA_FUNCTION_NAME !== undefined
423
- const isGCPFunction = getIsGCPFunction()
424
- const isAzureFunction = getIsAzureFunction()
425
- return inAWSLambda || isGCPFunction || isAzureFunction
422
+ return isInServerlessEnvironment()
426
423
  }
427
424
 
428
425
  // for _merge to work, every config value must have a default value
@@ -443,6 +440,7 @@ class Config {
443
440
 
444
441
  const defaults = setHiddenProperty(this, '_defaults', {})
445
442
 
443
+ this._setBoolean(defaults, 'apmTracingEnabled', true)
446
444
  this._setValue(defaults, 'appsec.apiSecurity.enabled', true)
447
445
  this._setValue(defaults, 'appsec.apiSecurity.sampleDelay', 30)
448
446
  this._setValue(defaults, 'appsec.blockedTemplateGraphql', undefined)
@@ -456,7 +454,6 @@ class Config {
456
454
  this._setValue(defaults, 'appsec.rateLimit', 100)
457
455
  this._setValue(defaults, 'appsec.rules', undefined)
458
456
  this._setValue(defaults, 'appsec.sca.enabled', null)
459
- this._setValue(defaults, 'appsec.standalone.enabled', undefined)
460
457
  this._setValue(defaults, 'appsec.stackTrace.enabled', true)
461
458
  this._setValue(defaults, 'appsec.stackTrace.maxDepth', 32)
462
459
  this._setValue(defaults, 'appsec.stackTrace.maxStackTraces', 2)
@@ -575,7 +572,8 @@ class Config {
575
572
  this._setValue(defaults, 'url', undefined)
576
573
  this._setValue(defaults, 'version', pkg.version)
577
574
  this._setValue(defaults, 'instrumentation_config_id', undefined)
578
- this._setValue(defaults, 'aws.dynamoDb.tablePrimaryKeys', undefined)
575
+ this._setValue(defaults, 'trace.aws.addSpanPointers', true)
576
+ this._setValue(defaults, 'trace.dynamoDb.tablePrimaryKeys', undefined)
579
577
  }
580
578
 
581
579
  _applyEnvironment () {
@@ -584,6 +582,7 @@ class Config {
584
582
  DD_AGENT_HOST,
585
583
  DD_API_SECURITY_ENABLED,
586
584
  DD_API_SECURITY_SAMPLE_DELAY,
585
+ DD_APM_TRACING_ENABLED,
587
586
  DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE,
588
587
  DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING,
589
588
  DD_APPSEC_ENABLED,
@@ -600,7 +599,6 @@ class Config {
600
599
  DD_APPSEC_RASP_ENABLED,
601
600
  DD_APPSEC_TRACE_RATE_LIMIT,
602
601
  DD_APPSEC_WAF_TIMEOUT,
603
- DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS,
604
602
  DD_CRASHTRACKING_ENABLED,
605
603
  DD_CODE_ORIGIN_FOR_SPANS_ENABLED,
606
604
  DD_DATA_STREAMS_ENABLED,
@@ -666,10 +664,12 @@ class Config {
666
664
  DD_TRACE_AGENT_HOSTNAME,
667
665
  DD_TRACE_AGENT_PORT,
668
666
  DD_TRACE_AGENT_PROTOCOL_VERSION,
667
+ DD_TRACE_AWS_ADD_SPAN_POINTERS,
669
668
  DD_TRACE_BAGGAGE_MAX_BYTES,
670
669
  DD_TRACE_BAGGAGE_MAX_ITEMS,
671
670
  DD_TRACE_CLIENT_IP_ENABLED,
672
671
  DD_TRACE_CLIENT_IP_HEADER,
672
+ DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS,
673
673
  DD_TRACE_ENABLED,
674
674
  DD_TRACE_EXPERIMENTAL_EXPORTER,
675
675
  DD_TRACE_EXPERIMENTAL_GET_RUM_DATA_ENABLED,
@@ -720,6 +720,10 @@ class Config {
720
720
  tagger.add(tags, DD_TRACE_TAGS)
721
721
  tagger.add(tags, DD_TRACE_GLOBAL_TAGS)
722
722
 
723
+ this._setBoolean(env, 'apmTracingEnabled', coalesce(
724
+ DD_APM_TRACING_ENABLED,
725
+ DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED && isFalse(DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED)
726
+ ))
723
727
  this._setBoolean(env, 'appsec.apiSecurity.enabled', coalesce(
724
728
  DD_API_SECURITY_ENABLED && isTrue(DD_API_SECURITY_ENABLED),
725
729
  DD_EXPERIMENTAL_API_SECURITY_ENABLED && isTrue(DD_EXPERIMENTAL_API_SECURITY_ENABLED)
@@ -743,7 +747,6 @@ class Config {
743
747
  this._setString(env, 'appsec.rules', DD_APPSEC_RULES)
744
748
  // DD_APPSEC_SCA_ENABLED is never used locally, but only sent to the backend
745
749
  this._setBoolean(env, 'appsec.sca.enabled', DD_APPSEC_SCA_ENABLED)
746
- this._setBoolean(env, 'appsec.standalone.enabled', DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED)
747
750
  this._setBoolean(env, 'appsec.stackTrace.enabled', DD_APPSEC_STACK_TRACE_ENABLED)
748
751
  this._setValue(env, 'appsec.stackTrace.maxDepth', maybeInt(DD_APPSEC_MAX_STACK_TRACE_DEPTH))
749
752
  this._envUnprocessed['appsec.stackTrace.maxDepth'] = DD_APPSEC_MAX_STACK_TRACE_DEPTH
@@ -755,7 +758,10 @@ class Config {
755
758
  this._setValue(env, 'baggageMaxItems', DD_TRACE_BAGGAGE_MAX_ITEMS)
756
759
  this._setBoolean(env, 'clientIpEnabled', DD_TRACE_CLIENT_IP_ENABLED)
757
760
  this._setString(env, 'clientIpHeader', DD_TRACE_CLIENT_IP_HEADER)
758
- this._setBoolean(env, 'crashtracking.enabled', DD_CRASHTRACKING_ENABLED)
761
+ this._setBoolean(env, 'crashtracking.enabled', coalesce(
762
+ DD_CRASHTRACKING_ENABLED,
763
+ !this._isInServerlessEnvironment()
764
+ ))
759
765
  this._setBoolean(env, 'codeOriginForSpans.enabled', DD_CODE_ORIGIN_FOR_SPANS_ENABLED)
760
766
  this._setString(env, 'dbmPropagationMode', DD_DBM_PROPAGATION_MODE)
761
767
  this._setString(env, 'dogstatsd.hostname', DD_DOGSTATSD_HOST || DD_DOGSTATSD_HOSTNAME)
@@ -825,7 +831,11 @@ class Config {
825
831
  this._envUnprocessed.peerServiceMapping = DD_TRACE_PEER_SERVICE_MAPPING
826
832
  }
827
833
  this._setString(env, 'port', DD_TRACE_AGENT_PORT)
828
- const profilingEnabledEnv = coalesce(DD_EXPERIMENTAL_PROFILING_ENABLED, DD_PROFILING_ENABLED)
834
+ const profilingEnabledEnv = coalesce(
835
+ DD_EXPERIMENTAL_PROFILING_ENABLED,
836
+ DD_PROFILING_ENABLED,
837
+ this._isInServerlessEnvironment() ? 'false' : undefined
838
+ )
829
839
  const profilingEnabled = isTrue(profilingEnabledEnv)
830
840
  ? 'true'
831
841
  : isFalse(profilingEnabledEnv)
@@ -905,7 +915,8 @@ class Config {
905
915
  this._setBoolean(env, 'tracing', DD_TRACING_ENABLED)
906
916
  this._setString(env, 'version', DD_VERSION || tags.version)
907
917
  this._setBoolean(env, 'inferredProxyServicesEnabled', DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED)
908
- this._setString(env, 'aws.dynamoDb.tablePrimaryKeys', DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS)
918
+ this._setBoolean(env, 'trace.aws.addSpanPointers', DD_TRACE_AWS_ADD_SPAN_POINTERS)
919
+ this._setString(env, 'trace.dynamoDb.tablePrimaryKeys', DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS)
909
920
  this._setArray(env, 'graphqlErrorExtensions', DD_TRACE_GRAPHQL_ERROR_EXTENSIONS)
910
921
  }
911
922
 
@@ -918,6 +929,10 @@ class Config {
918
929
 
919
930
  tagger.add(tags, options.tags)
920
931
 
932
+ this._setBoolean(opts, 'apmTracingEnabled', coalesce(
933
+ options.apmTracingEnabled,
934
+ options.experimental?.appsec?.standalone && !options.experimental.appsec.standalone.enabled
935
+ ))
921
936
  this._setBoolean(opts, 'appsec.apiSecurity.enabled', options.appsec.apiSecurity?.enabled)
922
937
  this._setValue(opts, 'appsec.blockedTemplateGraphql', maybeFile(options.appsec.blockedTemplateGraphql))
923
938
  this._setValue(opts, 'appsec.blockedTemplateHtml', maybeFile(options.appsec.blockedTemplateHtml))
@@ -932,7 +947,6 @@ class Config {
932
947
  this._setValue(opts, 'appsec.rateLimit', maybeInt(options.appsec.rateLimit))
933
948
  this._optsUnprocessed['appsec.rateLimit'] = options.appsec.rateLimit
934
949
  this._setString(opts, 'appsec.rules', options.appsec.rules)
935
- this._setBoolean(opts, 'appsec.standalone.enabled', options.experimental?.appsec?.standalone?.enabled)
936
950
  this._setBoolean(opts, 'appsec.stackTrace.enabled', options.appsec.stackTrace?.enabled)
937
951
  this._setValue(opts, 'appsec.stackTrace.maxDepth', maybeInt(options.appsec.stackTrace?.maxDepth))
938
952
  this._optsUnprocessed['appsec.stackTrace.maxDepth'] = options.appsec.stackTrace?.maxDepth
@@ -1117,7 +1131,10 @@ class Config {
1117
1131
  }
1118
1132
 
1119
1133
  _isTraceStatsComputationEnabled () {
1120
- return coalesce(
1134
+ const apmTracingEnabled = this._options.apmTracingEnabled !== false &&
1135
+ this._env.apmTracingEnabled !== false
1136
+
1137
+ return apmTracingEnabled && coalesce(
1121
1138
  this._optionsArg.stats,
1122
1139
  process.env.DD_TRACE_STATS_COMPUTATION_ENABLED,
1123
1140
  getIsGCPFunction() || getIsAzureFunction()
@@ -34,7 +34,7 @@ module.exports = {
34
34
  SCI_REPOSITORY_URL: '_dd.git.repository_url',
35
35
  SCI_COMMIT_SHA: '_dd.git.commit.sha',
36
36
  APM_TRACING_ENABLED_KEY: '_dd.apm.enabled',
37
- APPSEC_PROPAGATION_KEY: '_dd.p.appsec',
37
+ TRACE_SOURCE_PROPAGATION_KEY: '_dd.p.ts',
38
38
  PAYLOAD_TAG_REQUEST_PREFIX: 'aws.request.body',
39
39
  PAYLOAD_TAG_RESPONSE_PREFIX: 'aws.response.body',
40
40
  PAYLOAD_TAGGING_MAX_TAGS: 758,
@@ -1,4 +1,4 @@
1
- const DataStreamsContext = require('./data_streams_context')
1
+ const DataStreamsContext = require('./context')
2
2
 
3
3
  class DataStreamsCheckpointer {
4
4
  constructor (tracer) {
@@ -1,5 +1,5 @@
1
- const { storage } = require('../../datadog-core')
2
- const log = require('./log')
1
+ const { storage } = require('../../../datadog-core')
2
+ const log = require('../log')
3
3
 
4
4
  function getDataStreamsContext () {
5
5
  const store = storage('legacy').getStore()
@@ -0,0 +1,104 @@
1
+ 'use strict'
2
+
3
+ const {
4
+ getAmqpMessageSize,
5
+ getHeadersSize,
6
+ getMessageSize,
7
+ getSizeOrZero
8
+ } = require('./size')
9
+
10
+ // This is only needed because DSM code is spread across existing tracing
11
+ // plugins instead of having dedicated DSM plugins that are themselves
12
+ // lazy loaded.
13
+ //
14
+ // TODO: Remove this when DSM has been moved to dedicaed plugins.
15
+ function lazyClass (classGetter, methods = [], staticMethods = []) {
16
+ let constructorArgs
17
+ let ActiveClass
18
+
19
+ const LazyClass = function (...args) {
20
+ constructorArgs = args
21
+ }
22
+
23
+ const activate = () => {
24
+ return (ActiveClass = ActiveClass || classGetter())
25
+ }
26
+
27
+ for (const method of methods) {
28
+ LazyClass.prototype[method] = function (...args) {
29
+ const instance = activate() && new ActiveClass(...constructorArgs)
30
+
31
+ // Replace the whole prototype instead of only the method itself whenever
32
+ // any individual method is called to avoid running through this code
33
+ // again every time another method is called. This is not only more
34
+ // efficient but it also means that the class instance does not need to be
35
+ // stored for future calls to other methods.
36
+ Object.setPrototypeOf(this, instance)
37
+
38
+ return this[method](...args)
39
+ }
40
+ }
41
+
42
+ for (const method of staticMethods) {
43
+ LazyClass[method] = function (...args) {
44
+ LazyClass[method] = activate() && ActiveClass[method]
45
+
46
+ return LazyClass[method](...args)
47
+ }
48
+ }
49
+
50
+ return LazyClass
51
+ }
52
+
53
+ const DsmPathwayCodec = lazyClass(() => require('./pathway').DsmPathwayCodec, [], [
54
+ 'encode',
55
+ 'decode'
56
+ ])
57
+
58
+ const DataStreamsCheckpointer = lazyClass(() => require('./checkpointer').DataStreamsCheckpointer, [
59
+ 'setProduceCheckpoint',
60
+ 'setConsumeCheckpoint'
61
+ ])
62
+
63
+ const DataStreamsManager = lazyClass(() => require('./manager').DataStreamsManager, [
64
+ 'setCheckpoint',
65
+ 'decodeDataStreamsContext'
66
+ ])
67
+
68
+ // TODO: Are all those methods actually public?
69
+ const DataStreamsProcessor = lazyClass(() => require('./processor').DataStreamsProcessor, [
70
+ 'onInterval',
71
+ 'bucketFromTimestamp',
72
+ 'recordCheckpoint',
73
+ 'setCheckpoint',
74
+ 'recordOffset',
75
+ 'setOffset',
76
+ 'setUrl',
77
+ 'trySampleSchema',
78
+ 'canSampleSchema',
79
+ 'getSchema'
80
+ ])
81
+
82
+ const SchemaBuilder = lazyClass(() => require('./schemas/schema_builder').SchemaBuilder, [
83
+ 'build',
84
+ 'addProperty',
85
+ 'shouldExtractSchema'
86
+ ], [
87
+ 'getCache',
88
+ 'getSchemaDefinition',
89
+ 'getSchema'
90
+ ])
91
+
92
+ module.exports = {
93
+ DsmPathwayCodec,
94
+ DataStreamsCheckpointer,
95
+ DataStreamsManager,
96
+ DataStreamsProcessor,
97
+ SchemaBuilder,
98
+
99
+ // These are small functions so they are exposed directly and not lazy loaded.
100
+ getAmqpMessageSize,
101
+ getHeadersSize,
102
+ getMessageSize,
103
+ getSizeOrZero
104
+ }
@@ -0,0 +1,27 @@
1
+ 'use strict'
2
+
3
+ const { DsmPathwayCodec } = require('./pathway')
4
+ const DataStreamsContext = require('./context')
5
+
6
+ class DataStreamsManager {
7
+ constructor (processor) {
8
+ this._dataStreamsProcessor = processor
9
+ }
10
+
11
+ setCheckpoint (edgeTags, span, payloadSize = 0) {
12
+ const ctx = this._dataStreamsProcessor.setCheckpoint(
13
+ edgeTags, span, DataStreamsContext.getDataStreamsContext(), payloadSize
14
+ )
15
+ DataStreamsContext.setDataStreamsContext(ctx)
16
+ return ctx
17
+ }
18
+
19
+ decodeDataStreamsContext (carrier) {
20
+ const ctx = DsmPathwayCodec.decode(carrier)
21
+ // we erase the previous context everytime we decode a new one
22
+ DataStreamsContext.setDataStreamsContext(ctx)
23
+ return ctx
24
+ }
25
+ }
26
+
27
+ module.exports = { DataStreamsManager }