dd-trace 5.33.1 → 5.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-3rdparty.csv +1 -2
- package/package.json +2 -3
- package/packages/datadog-plugin-graphql/src/execute.js +6 -0
- package/packages/datadog-plugin-graphql/src/utils.js +40 -0
- package/packages/datadog-plugin-graphql/src/validate.js +6 -0
- package/packages/dd-trace/src/appsec/iast/analyzers/code-injection-analyzer.js +19 -1
- package/packages/dd-trace/src/config.js +8 -0
- package/packages/dd-trace/src/debugger/devtools_client/state.js +67 -17
- package/packages/dd-trace/src/id.js +0 -2
- package/packages/dd-trace/src/plugin_manager.js +9 -1
package/LICENSE-3rdparty.csv
CHANGED
|
@@ -35,6 +35,7 @@ dev,@apollo/server,MIT,Copyright (c) 2016-2020 Apollo Graph, Inc. (Formerly Mete
|
|
|
35
35
|
dev,@types/node,MIT,Copyright Authors
|
|
36
36
|
dev,@eslint/eslintrc,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
|
|
37
37
|
dev,@eslint/js,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
|
|
38
|
+
dev,@msgpack/msgpack,ISC,Copyright 2019 The MessagePack Community
|
|
38
39
|
dev,@stylistic/eslint-plugin-js,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
|
|
39
40
|
dev,autocannon,MIT,Copyright 2016 Matteo Collina
|
|
40
41
|
dev,aws-sdk,Apache 2.0,Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
@@ -58,12 +59,10 @@ dev,get-port,MIT,Copyright Sindre Sorhus
|
|
|
58
59
|
dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors
|
|
59
60
|
dev,globals,MIT,Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
60
61
|
dev,graphql,MIT,Copyright 2015 Facebook Inc.
|
|
61
|
-
dev,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
|
|
62
62
|
dev,jszip,MIT,Copyright 2015-2016 Stuart Knightley and contributors
|
|
63
63
|
dev,knex,MIT,Copyright (c) 2013-present Tim Griesser
|
|
64
64
|
dev,mkdirp,MIT,Copyright 2010 James Halliday
|
|
65
65
|
dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foundation
|
|
66
|
-
dev,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
|
|
67
66
|
dev,multer,MIT,Copyright 2014 Hage Yaapa
|
|
68
67
|
dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
|
|
69
68
|
dev,nyc,ISC,Copyright 2015 Contributors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dd-trace",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.34.0",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -118,6 +118,7 @@
|
|
|
118
118
|
"@apollo/server": "^4.11.0",
|
|
119
119
|
"@eslint/eslintrc": "^3.1.0",
|
|
120
120
|
"@eslint/js": "^9.11.1",
|
|
121
|
+
"@msgpack/msgpack": "^3.0.0-beta3",
|
|
121
122
|
"@stylistic/eslint-plugin-js": "^2.8.0",
|
|
122
123
|
"@types/node": "^16.0.0",
|
|
123
124
|
"autocannon": "^4.5.2",
|
|
@@ -142,12 +143,10 @@
|
|
|
142
143
|
"glob": "^7.1.6",
|
|
143
144
|
"globals": "^15.10.0",
|
|
144
145
|
"graphql": "0.13.2",
|
|
145
|
-
"int64-buffer": "^0.1.9",
|
|
146
146
|
"jszip": "^3.5.0",
|
|
147
147
|
"knex": "^2.4.2",
|
|
148
148
|
"mkdirp": "^3.0.1",
|
|
149
149
|
"mocha": "^10",
|
|
150
|
-
"msgpack-lite": "^0.1.26",
|
|
151
150
|
"multer": "^1.4.5-lts.1",
|
|
152
151
|
"nock": "^11.3.3",
|
|
153
152
|
"nyc": "^15.1.0",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const TracingPlugin = require('../../dd-trace/src/plugins/tracing')
|
|
4
|
+
const { extractErrorIntoSpanEvent } = require('./utils')
|
|
4
5
|
|
|
5
6
|
let tools
|
|
6
7
|
|
|
@@ -34,6 +35,11 @@ class GraphQLExecutePlugin extends TracingPlugin {
|
|
|
34
35
|
finish ({ res, args }) {
|
|
35
36
|
const span = this.activeSpan
|
|
36
37
|
this.config.hooks.execute(span, args, res)
|
|
38
|
+
if (res?.errors) {
|
|
39
|
+
for (const err of res.errors) {
|
|
40
|
+
extractErrorIntoSpanEvent(this._tracerConfig, span, err)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
37
43
|
super.finish()
|
|
38
44
|
}
|
|
39
45
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
function extractErrorIntoSpanEvent (config, span, exc) {
|
|
2
|
+
const attributes = {}
|
|
3
|
+
|
|
4
|
+
if (exc.name) {
|
|
5
|
+
attributes.type = exc.name
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (exc.stack) {
|
|
9
|
+
attributes.stacktrace = exc.stack
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (exc.locations) {
|
|
13
|
+
attributes.locations = []
|
|
14
|
+
for (const location of exc.locations) {
|
|
15
|
+
attributes.locations.push(`${location.line}:${location.column}`)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (exc.path) {
|
|
20
|
+
attributes.path = exc.path.map(String)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (exc.message) {
|
|
24
|
+
attributes.message = exc.message
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (config.graphqlErrorExtensions) {
|
|
28
|
+
for (const ext of config.graphqlErrorExtensions) {
|
|
29
|
+
if (exc.extensions?.[ext]) {
|
|
30
|
+
attributes[`extensions.${ext}`] = exc.extensions[ext].toString()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
span.addEvent('dd.graphql.query.error', attributes, Date.now())
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
extractErrorIntoSpanEvent
|
|
40
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const TracingPlugin = require('../../dd-trace/src/plugins/tracing')
|
|
4
|
+
const { extractErrorIntoSpanEvent } = require('./utils')
|
|
4
5
|
|
|
5
6
|
class GraphQLValidatePlugin extends TracingPlugin {
|
|
6
7
|
static get id () { return 'graphql' }
|
|
@@ -21,6 +22,11 @@ class GraphQLValidatePlugin extends TracingPlugin {
|
|
|
21
22
|
finish ({ document, errors }) {
|
|
22
23
|
const span = this.activeSpan
|
|
23
24
|
this.config.hooks.validate(span, document, errors)
|
|
25
|
+
if (errors) {
|
|
26
|
+
for (const err of errors) {
|
|
27
|
+
extractErrorIntoSpanEvent(this._tracerConfig, span, err)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
24
30
|
super.finish()
|
|
25
31
|
}
|
|
26
32
|
}
|
|
@@ -2,14 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
const InjectionAnalyzer = require('./injection-analyzer')
|
|
4
4
|
const { CODE_INJECTION } = require('../vulnerabilities')
|
|
5
|
+
const { INSTRUMENTED_SINK } = require('../telemetry/iast-metric')
|
|
6
|
+
const { storage } = require('../../../../../datadog-core')
|
|
7
|
+
const { getIastContext } = require('../iast-context')
|
|
5
8
|
|
|
6
9
|
class CodeInjectionAnalyzer extends InjectionAnalyzer {
|
|
7
10
|
constructor () {
|
|
8
11
|
super(CODE_INJECTION)
|
|
12
|
+
this.evalInstrumentedInc = false
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
onConfigure () {
|
|
12
|
-
this.addSub('datadog:eval:call', ({ script }) =>
|
|
16
|
+
this.addSub('datadog:eval:call', ({ script }) => {
|
|
17
|
+
if (!this.evalInstrumentedInc) {
|
|
18
|
+
const store = storage.getStore()
|
|
19
|
+
const iastContext = getIastContext(store)
|
|
20
|
+
const tags = INSTRUMENTED_SINK.formatTags(CODE_INJECTION)
|
|
21
|
+
|
|
22
|
+
for (const tag of tags) {
|
|
23
|
+
INSTRUMENTED_SINK.inc(iastContext, tag)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.evalInstrumentedInc = true
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.analyze(script)
|
|
30
|
+
})
|
|
13
31
|
this.addSub('datadog:vm:run-script:start', ({ code }) => this.analyze(code))
|
|
14
32
|
this.addSub('datadog:vm:source-text-module:start', ({ code }) => this.analyze(code))
|
|
15
33
|
}
|
|
@@ -482,6 +482,7 @@ class Config {
|
|
|
482
482
|
this._setValue(defaults, 'flushInterval', 2000)
|
|
483
483
|
this._setValue(defaults, 'flushMinSpans', 1000)
|
|
484
484
|
this._setValue(defaults, 'gitMetadataEnabled', true)
|
|
485
|
+
this._setValue(defaults, 'graphqlErrorExtensions', [])
|
|
485
486
|
this._setValue(defaults, 'grpc.client.error.statuses', GRPC_CLIENT_ERROR_STATUSES)
|
|
486
487
|
this._setValue(defaults, 'grpc.server.error.statuses', GRPC_SERVER_ERROR_STATUSES)
|
|
487
488
|
this._setValue(defaults, 'headerTags', [])
|
|
@@ -521,6 +522,7 @@ class Config {
|
|
|
521
522
|
this._setValue(defaults, 'lookup', undefined)
|
|
522
523
|
this._setValue(defaults, 'inferredProxyServicesEnabled', false)
|
|
523
524
|
this._setValue(defaults, 'memcachedCommandEnabled', false)
|
|
525
|
+
this._setValue(defaults, 'middlewareTracingEnabled', true)
|
|
524
526
|
this._setValue(defaults, 'openAiLogsEnabled', false)
|
|
525
527
|
this._setValue(defaults, 'openai.spanCharLimit', 128)
|
|
526
528
|
this._setValue(defaults, 'peerServiceMapping', {})
|
|
@@ -669,9 +671,11 @@ class Config {
|
|
|
669
671
|
DD_TRACE_EXPERIMENTAL_RUNTIME_ID_ENABLED,
|
|
670
672
|
DD_TRACE_GIT_METADATA_ENABLED,
|
|
671
673
|
DD_TRACE_GLOBAL_TAGS,
|
|
674
|
+
DD_TRACE_GRAPHQL_ERROR_EXTENSIONS,
|
|
672
675
|
DD_TRACE_HEADER_TAGS,
|
|
673
676
|
DD_TRACE_LEGACY_BAGGAGE_ENABLED,
|
|
674
677
|
DD_TRACE_MEMCACHED_COMMAND_ENABLED,
|
|
678
|
+
DD_TRACE_MIDDLEWARE_TRACING_ENABLED,
|
|
675
679
|
DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP,
|
|
676
680
|
DD_TRACE_PARTIAL_FLUSH_MIN_SPANS,
|
|
677
681
|
DD_TRACE_PEER_SERVICE_MAPPING,
|
|
@@ -804,6 +808,7 @@ class Config {
|
|
|
804
808
|
this._setBoolean(env, 'logInjection', DD_LOGS_INJECTION)
|
|
805
809
|
// Requires an accompanying DD_APM_OBFUSCATION_MEMCACHED_KEEP_COMMAND=true in the agent
|
|
806
810
|
this._setBoolean(env, 'memcachedCommandEnabled', DD_TRACE_MEMCACHED_COMMAND_ENABLED)
|
|
811
|
+
this._setBoolean(env, 'middlewareTracingEnabled', DD_TRACE_MIDDLEWARE_TRACING_ENABLED)
|
|
807
812
|
this._setBoolean(env, 'openAiLogsEnabled', DD_OPENAI_LOGS_ENABLED)
|
|
808
813
|
this._setValue(env, 'openai.spanCharLimit', maybeInt(DD_OPENAI_SPAN_CHAR_LIMIT))
|
|
809
814
|
this._envUnprocessed.openaiSpanCharLimit = DD_OPENAI_SPAN_CHAR_LIMIT
|
|
@@ -895,6 +900,7 @@ class Config {
|
|
|
895
900
|
this._setString(env, 'version', DD_VERSION || tags.version)
|
|
896
901
|
this._setBoolean(env, 'inferredProxyServicesEnabled', DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED)
|
|
897
902
|
this._setString(env, 'aws.dynamoDb.tablePrimaryKeys', DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS)
|
|
903
|
+
this._setArray(env, 'graphqlErrorExtensions', DD_TRACE_GRAPHQL_ERROR_EXTENSIONS)
|
|
898
904
|
}
|
|
899
905
|
|
|
900
906
|
_applyOptions (options) {
|
|
@@ -986,6 +992,7 @@ class Config {
|
|
|
986
992
|
this._setString(opts, 'llmobs.mlApp', options.llmobs?.mlApp)
|
|
987
993
|
this._setBoolean(opts, 'logInjection', options.logInjection)
|
|
988
994
|
this._setString(opts, 'lookup', options.lookup)
|
|
995
|
+
this._setBoolean(opts, 'middlewareTracingEnabled', options.middlewareTracingEnabled)
|
|
989
996
|
this._setBoolean(opts, 'openAiLogsEnabled', options.openAiLogsEnabled)
|
|
990
997
|
this._setValue(opts, 'peerServiceMapping', options.peerServiceMapping)
|
|
991
998
|
this._setBoolean(opts, 'plugins', options.plugins)
|
|
@@ -1020,6 +1027,7 @@ class Config {
|
|
|
1020
1027
|
this._setBoolean(opts, 'traceId128BitLoggingEnabled', options.traceId128BitLoggingEnabled)
|
|
1021
1028
|
this._setString(opts, 'version', options.version || tags.version)
|
|
1022
1029
|
this._setBoolean(opts, 'inferredProxyServicesEnabled', options.inferredProxyServicesEnabled)
|
|
1030
|
+
this._setBoolean(opts, 'graphqlErrorExtensions', options.graphqlErrorExtensions)
|
|
1023
1031
|
|
|
1024
1032
|
// For LLMObs, we want the environment variable to take precedence over the options.
|
|
1025
1033
|
// This is reliant on environment config being set before options.
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const session = require('./session')
|
|
4
4
|
|
|
5
|
+
const WINDOWS_DRIVE_LETTER_REGEX = /[a-zA-Z]/
|
|
6
|
+
|
|
5
7
|
const scriptIds = []
|
|
6
8
|
const scriptUrls = new Map()
|
|
7
9
|
|
|
@@ -10,26 +12,74 @@ module.exports = {
|
|
|
10
12
|
breakpoints: new Map(),
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
|
-
* Find the
|
|
14
|
-
*
|
|
15
|
-
* Algorithm: Find the sortest url that ends in the requested path.
|
|
16
|
-
*
|
|
17
|
-
* Will identify the correct script as long as Node.js doesn't load a module from a `node_modules` folder outside the
|
|
18
|
-
* project root. If so, there's a risk that this path is shorter than the expected path inside the project root.
|
|
19
|
-
* Example of mismatch where path = `index.js`:
|
|
20
|
-
*
|
|
21
|
-
* Expected match: /www/code/my-projects/demo-project1/index.js
|
|
22
|
-
* Actual shorter match: /www/node_modules/dd-trace/index.js
|
|
15
|
+
* Find the script to inspect based on a partial or absolute path. Handles both Windows and POSIX paths.
|
|
23
16
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @returns {[string, string] | undefined}
|
|
17
|
+
* @param {string} path - Partial or absolute path to match against loaded scripts
|
|
18
|
+
* @returns {[string, string, string | undefined] | null} - Array containing [url, scriptId, sourceMapURL]
|
|
19
|
+
* or null if no match
|
|
28
20
|
*/
|
|
29
21
|
findScriptFromPartialPath (path) {
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
if (!path) return null // This shouldn't happen, but better safe than sorry
|
|
23
|
+
|
|
24
|
+
const bestMatch = new Array(3)
|
|
25
|
+
let maxMatchLength = -1
|
|
26
|
+
|
|
27
|
+
for (const [url, scriptId, sourceMapURL] of scriptIds) {
|
|
28
|
+
let i = url.length - 1
|
|
29
|
+
let j = path.length - 1
|
|
30
|
+
let matchLength = 0
|
|
31
|
+
let lastBoundaryPos = -1
|
|
32
|
+
let atBoundary = false
|
|
33
|
+
|
|
34
|
+
// Compare characters from the end
|
|
35
|
+
while (i >= 0 && j >= 0) {
|
|
36
|
+
const urlChar = url[i]
|
|
37
|
+
const pathChar = path[j]
|
|
38
|
+
|
|
39
|
+
// Check if both characters is a path boundary
|
|
40
|
+
const isBoundary = (urlChar === '/' || urlChar === '\\') && (pathChar === '/' || pathChar === '\\' ||
|
|
41
|
+
(j === 1 && pathChar === ':' && WINDOWS_DRIVE_LETTER_REGEX.test(path[0])))
|
|
42
|
+
|
|
43
|
+
// If both are boundaries, or if characters match exactly
|
|
44
|
+
if (isBoundary || urlChar === pathChar) {
|
|
45
|
+
if (isBoundary) {
|
|
46
|
+
lastBoundaryPos = matchLength
|
|
47
|
+
atBoundary = true
|
|
48
|
+
} else {
|
|
49
|
+
atBoundary = false
|
|
50
|
+
}
|
|
51
|
+
matchLength++
|
|
52
|
+
i--
|
|
53
|
+
j--
|
|
54
|
+
} else {
|
|
55
|
+
break
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// If we've matched the entire path pattern, ensure it starts at a path boundary
|
|
60
|
+
if (j === -1) {
|
|
61
|
+
if (i >= 0) {
|
|
62
|
+
// If there are more characters in the URL, the next one must be a slash
|
|
63
|
+
if (url[i] === '/' || url[i] === '\\') {
|
|
64
|
+
atBoundary = true
|
|
65
|
+
lastBoundaryPos = matchLength
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
atBoundary = true
|
|
69
|
+
lastBoundaryPos = matchLength
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// If we found a valid match and it's better than our previous best
|
|
74
|
+
if (atBoundary && lastBoundaryPos !== -1 && lastBoundaryPos > maxMatchLength) {
|
|
75
|
+
maxMatchLength = lastBoundaryPos
|
|
76
|
+
bestMatch[0] = url
|
|
77
|
+
bestMatch[1] = scriptId
|
|
78
|
+
bestMatch[2] = sourceMapURL
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return maxMatchLength > -1 ? bestMatch : null
|
|
33
83
|
},
|
|
34
84
|
|
|
35
85
|
getStackFromCallFrames (callFrames) {
|
|
@@ -15,7 +15,6 @@ let batch = 0
|
|
|
15
15
|
// Internal representation of a trace or span ID.
|
|
16
16
|
class Identifier {
|
|
17
17
|
constructor (value, radix = 16) {
|
|
18
|
-
this._isUint64BE = true // msgpack-lite compatibility
|
|
19
18
|
this._buffer = radix === 16
|
|
20
19
|
? createBuffer(value)
|
|
21
20
|
: fromString(value, radix)
|
|
@@ -31,7 +30,6 @@ class Identifier {
|
|
|
31
30
|
return this._buffer
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
// msgpack-lite compatibility
|
|
35
33
|
toArray () {
|
|
36
34
|
if (this._buffer.length === 8) {
|
|
37
35
|
return this._buffer
|
|
@@ -139,7 +139,8 @@ module.exports = class PluginManager {
|
|
|
139
139
|
memcachedCommandEnabled,
|
|
140
140
|
ciVisibilityTestSessionName,
|
|
141
141
|
ciVisAgentlessLogSubmissionEnabled,
|
|
142
|
-
isTestDynamicInstrumentationEnabled
|
|
142
|
+
isTestDynamicInstrumentationEnabled,
|
|
143
|
+
middlewareTracingEnabled
|
|
143
144
|
} = this._tracerConfig
|
|
144
145
|
|
|
145
146
|
const sharedConfig = {
|
|
@@ -170,6 +171,13 @@ module.exports = class PluginManager {
|
|
|
170
171
|
sharedConfig.clientIpEnabled = clientIpEnabled
|
|
171
172
|
}
|
|
172
173
|
|
|
174
|
+
// For the global setting, we use the name `middlewareTracingEnabled`, but
|
|
175
|
+
// for the plugin-specific setting, we use `middleware`. They mean the same
|
|
176
|
+
// to an individual plugin, so we normalize them here.
|
|
177
|
+
if (middlewareTracingEnabled !== undefined) {
|
|
178
|
+
sharedConfig.middleware = middlewareTracingEnabled
|
|
179
|
+
}
|
|
180
|
+
|
|
173
181
|
return sharedConfig
|
|
174
182
|
}
|
|
175
183
|
}
|