Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dev,@eslint/eslintrc,MIT,Copyright OpenJS Foundation and other contributors, <ww
dev,@eslint/js,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
dev,@msgpack/msgpack,ISC,Copyright 2019 The MessagePack Community
dev,@stylistic/eslint-plugin-js,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
dev,application-config-path,MIT,Copyright (c) 2015, 2023 Linus Unnebäck
dev,autocannon,MIT,Copyright 2016 Matteo Collina
dev,aws-sdk,Apache 2.0,Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
dev,axios,MIT,Copyright 2014-present Matt Zabriskie
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dd-trace",
"version": "5.40.0",
"version": "5.41.0",
"description": "Datadog APM tracing client for JavaScript",
"main": "index.js",
"typings": "index.d.ts",
Expand Down Expand Up @@ -82,7 +82,7 @@
"node": ">=18"
},
"dependencies": {
"@datadog/libdatadog": "^0.4.0",
"@datadog/libdatadog": "^0.5.0",
"@datadog/native-appsec": "8.4.0",
"@datadog/native-iast-rewriter": "2.8.0",
"@datadog/native-iast-taint-tracking": "3.3.0",
Expand All @@ -95,7 +95,7 @@
"crypto-randomuuid": "^1.0.0",
"dc-polyfill": "^0.1.4",
"ignore": "^5.2.4",
"import-in-the-middle": "1.11.2",
"import-in-the-middle": "1.13.1",
"istanbul-lib-coverage": "3.2.0",
"jest-docblock": "^29.7.0",
"koalas": "^1.0.2",
Expand All @@ -122,6 +122,7 @@
"@msgpack/msgpack": "^3.0.0-beta3",
"@stylistic/eslint-plugin-js": "^3.0.1",
"@types/node": "^16.0.0",
"application-config-path": "^1.0.0",
"autocannon": "^4.5.2",
"aws-sdk": "^2.1446.0",
"axios": "^1.7.4",
Expand Down
4 changes: 1 addition & 3 deletions packages/datadog-plugin-express/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1350,9 +1350,7 @@ describe('Plugin', () => {
expect(spans[0].meta).to.have.property('http.status_code', '404')
expect(spans[0].meta).to.have.property('component', 'express')
expect(spans[0].meta).to.not.have.property('http.route')

done()
})
}).then(done).catch(done)

axios
.get(`http://localhost:${port}/does-not-exist`, {
Expand Down
4 changes: 1 addition & 3 deletions packages/datadog-plugin-graphql/src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class GraphQLParsePlugin extends TracingPlugin {
this.startSpan('graphql.parse', {
service: this.config.service,
type: 'graphql',
meta: {
'graphql.source': ''
}
meta: {}
})
}

Expand Down
5 changes: 4 additions & 1 deletion packages/datadog-plugin-mongodb-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class MongodbCorePlugin extends DatabasePlugin {
'out.port': options.port
}
})
ops.comment = this.injectDbmComment(span, ops.comment, service)
const comment = this.injectDbmComment(span, ops.comment, service)
if (comment) {
ops.comment = comment
}
}

getPeerService (tags) {
Expand Down
107 changes: 107 additions & 0 deletions packages/datadog-plugin-mongodb-core/test/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,113 @@ describe('Plugin', () => {
)
})

describe('with dbmPropagationMode disabled by default', () => {
before(() => {
return agent.load('mongodb-core')
})

after(() => {
return agent.close({ ritmReset: false })
})

beforeEach(done => {
const Server = getServer()

server = new Server({
host: '127.0.0.1',
port: 27017,
reconnect: false
})

server.on('connect', () => done())
server.on('error', done)

server.connect()

startSpy = sinon.spy(MongodbCorePlugin.prototype, 'start')
})

afterEach(() => {
startSpy?.restore()
})

it('DBM propagation should not inject comment', done => {
agent
.use(traces => {
expect(startSpy.called).to.be.true
const ops = startSpy.getCall(0).args[0].ops
expect(ops).to.not.have.property('comment')
})
.then(done)
.catch(done)

server.insert(`test.${collection}`, [{ a: 1 }], () => {})
})
})

describe('with dbmPropagationMode explicitly disabled', () => {
before(() => {
return agent.load('mongodb-core', { dbmPropagationMode: 'disabled' })
})

after(() => {
return agent.close({ ritmReset: false })
})

beforeEach(done => {
const Server = getServer()

server = new Server({
host: '127.0.0.1',
port: 27017,
reconnect: false
})

server.on('connect', () => done())
server.on('error', done)

server.connect()

startSpy = sinon.spy(MongodbCorePlugin.prototype, 'start')
})

afterEach(() => {
startSpy?.restore()
})

it('DBM propagation should not inject comment', done => {
agent
.use(traces => {
expect(startSpy.called).to.be.true
const { comment } = startSpy.getCall(0).args[0].ops
expect(comment).to.be.undefined
})
.then(done)
.catch(done)

server.insert(`test.${collection}`, [{ a: 1 }], () => {})
})

it('DBM propagation should not alter existing comment', done => {
agent
.use(traces => {
expect(startSpy.called).to.be.true
const { comment } = startSpy.getCall(0).args[0].ops
expect(comment).to.equal('test comment')
})
.then(done)
.catch(done)

server.command(`test.${collection}`, {
find: `test.${collection}`,
query: {
_id: Buffer.from('1234')
},
comment: 'test comment'
}, () => {})
})
})

describe('with dbmPropagationMode service', () => {
before(() => {
return agent.load('mongodb-core', { dbmPropagationMode: 'service' })
Expand Down
130 changes: 112 additions & 18 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const tagger = require('./tagger')
const get = require('../../datadog-core/src/utils/src/get')
const has = require('../../datadog-core/src/utils/src/has')
const set = require('../../datadog-core/src/utils/src/set')
const { isTrue, isFalse } = require('./util')
const { isTrue, isFalse, normalizeProfilingEnabledValue } = require('./util')
const { GIT_REPOSITORY_URL, GIT_COMMIT_SHA } = require('./plugins/util/tags')
const { getGitMetadataFromGitProperties, removeUserSensitiveInfo } = require('./git_properties')
const { updateConfig } = require('./telemetry')
Expand Down Expand Up @@ -236,6 +236,12 @@ function reformatSpanSamplingRules (rules) {

class Config {
constructor (options = {}) {
if (!isInServerlessEnvironment()) {
// Bail out early if we're in a serverless environment, stable config isn't supported
const StableConfig = require('./config_stable')
this.stableConfig = new StableConfig()
}

options = {
...options,
appsec: options.appsec != null ? options.appsec : options.experimental?.appsec,
Expand All @@ -244,13 +250,24 @@ class Config {

// Configure the logger first so it can be used to warn about other configs
const logConfig = log.getConfig()
this.debug = logConfig.enabled
this.debug = log.isEnabled(
this.stableConfig?.fleetEntries?.DD_TRACE_DEBUG,
this.stableConfig?.localEntries?.DD_TRACE_DEBUG
)
this.logger = coalesce(options.logger, logConfig.logger)
this.logLevel = coalesce(options.logLevel, logConfig.logLevel)

this.logLevel = log.getLogLevel(
options.logLevel,
this.stableConfig?.fleetEntries?.DD_TRACE_LOG_LEVEL,
this.stableConfig?.localEntries?.DD_TRACE_LOG_LEVEL
)
log.use(this.logger)
log.toggle(this.debug, this.logLevel)

// Process stable config warnings, if any
for (const warning of this.stableConfig?.warnings ?? []) {
log.warn(warning)
}

checkIfBothOtelAndDdEnvVarSet()

const DD_API_KEY = coalesce(
Expand Down Expand Up @@ -337,7 +354,9 @@ class Config {
}

this._applyDefaults()
this._applyLocalStableConfig()
this._applyEnvironment()
this._applyFleetStableConfig()
this._applyOptions(options)
this._applyCalculated()
this._applyRemote({})
Expand Down Expand Up @@ -576,6 +595,45 @@ class Config {
this._setValue(defaults, 'trace.dynamoDb.tablePrimaryKeys', undefined)
}

_applyLocalStableConfig () {
const obj = setHiddenProperty(this, '_localStableConfig', {})
this._applyStableConfig(this.stableConfig?.localEntries ?? {}, obj)
}

_applyFleetStableConfig () {
const obj = setHiddenProperty(this, '_fleetStableConfig', {})
this._applyStableConfig(this.stableConfig?.fleetEntries ?? {}, obj)
}

_applyStableConfig (config, obj) {
const {
DD_APPSEC_ENABLED,
DD_APPSEC_SCA_ENABLED,
DD_DATA_STREAMS_ENABLED,
DD_DYNAMIC_INSTRUMENTATION_ENABLED,
DD_ENV,
DD_IAST_ENABLED,
DD_LOGS_INJECTION,
DD_PROFILING_ENABLED,
DD_RUNTIME_METRICS_ENABLED,
DD_SERVICE,
DD_VERSION
} = config

this._setBoolean(obj, 'appsec.enabled', DD_APPSEC_ENABLED)
this._setBoolean(obj, 'appsec.sca.enabled', DD_APPSEC_SCA_ENABLED)
this._setBoolean(obj, 'dsmEnabled', DD_DATA_STREAMS_ENABLED)
this._setBoolean(obj, 'dynamicInstrumentation.enabled', DD_DYNAMIC_INSTRUMENTATION_ENABLED)
this._setString(obj, 'env', DD_ENV)
this._setBoolean(obj, 'iast.enabled', DD_IAST_ENABLED)
this._setBoolean(obj, 'logInjection', DD_LOGS_INJECTION)
const profilingEnabled = normalizeProfilingEnabledValue(DD_PROFILING_ENABLED)
this._setString(obj, 'profiling.enabled', profilingEnabled)
this._setBoolean(obj, 'runtimeMetrics', DD_RUNTIME_METRICS_ENABLED)
this._setString(obj, 'service', DD_SERVICE)
this._setString(obj, 'version', DD_VERSION)
}

_applyEnvironment () {
const {
AWS_LAMBDA_FUNCTION_NAME,
Expand Down Expand Up @@ -715,8 +773,8 @@ class Config {
const env = setHiddenProperty(this, '_env', {})
setHiddenProperty(this, '_envUnprocessed', {})

tagger.add(tags, OTEL_RESOURCE_ATTRIBUTES, true)
tagger.add(tags, DD_TAGS)
tagger.add(tags, parseSpaceSeparatedTags(handleOtel(OTEL_RESOURCE_ATTRIBUTES)))
tagger.add(tags, parseSpaceSeparatedTags(DD_TAGS))
tagger.add(tags, DD_TRACE_TAGS)
tagger.add(tags, DD_TRACE_GLOBAL_TAGS)

Expand Down Expand Up @@ -831,16 +889,13 @@ class Config {
this._envUnprocessed.peerServiceMapping = DD_TRACE_PEER_SERVICE_MAPPING
}
this._setString(env, 'port', DD_TRACE_AGENT_PORT)
const profilingEnabledEnv = coalesce(
DD_EXPERIMENTAL_PROFILING_ENABLED,
DD_PROFILING_ENABLED,
this._isInServerlessEnvironment() ? 'false' : undefined
const profilingEnabled = normalizeProfilingEnabledValue(
coalesce(
DD_EXPERIMENTAL_PROFILING_ENABLED,
DD_PROFILING_ENABLED,
this._isInServerlessEnvironment() ? 'false' : undefined
)
)
const profilingEnabled = isTrue(profilingEnabledEnv)
? 'true'
: isFalse(profilingEnabledEnv)
? 'false'
: profilingEnabledEnv === 'auto' ? 'auto' : undefined
this._setString(env, 'profiling.enabled', profilingEnabled)
this._setString(env, 'profiling.exporters', DD_PROFILING_EXPORTERS)
this._setBoolean(env, 'profiling.sourceMap', DD_PROFILING_SOURCE_MAP && !isFalse(DD_PROFILING_SOURCE_MAP))
Expand Down Expand Up @@ -1347,9 +1402,33 @@ class Config {
// eslint-disable-next-line @stylistic/js/max-len
// https://github.com/DataDog/dd-go/blob/prod/trace/apps/tracer-telemetry-intake/telemetry-payload/static/config_norm_rules.json
_merge () {
const containers = [this._remote, this._options, this._env, this._calculated, this._defaults]
const origins = ['remote_config', 'code', 'env_var', 'calculated', 'default']
const unprocessedValues = [this._remoteUnprocessed, this._optsUnprocessed, this._envUnprocessed, {}, {}]
const containers = [
this._remote,
this._options,
this._fleetStableConfig,
this._env,
this._localStableConfig,
this._calculated,
this._defaults
]
const origins = [
'remote_config',
'code',
'fleet_stable_config',
'env_var',
'local_stable_config',
'calculated',
'default'
]
const unprocessedValues = [
this._remoteUnprocessed,
this._optsUnprocessed,
{},
this._envUnprocessed,
{},
{},
{}
]
const changes = []

for (const name in this._defaults) {
Expand Down Expand Up @@ -1394,6 +1473,21 @@ class Config {
}
}

function handleOtel (tagString) {
return tagString
?.replace(/(^|,)deployment\.environment=/, '$1env:')
.replace(/(^|,)service\.name=/, '$1service:')
.replace(/(^|,)service\.version=/, '$1version:')
.replace(/=/g, ':')
}

function parseSpaceSeparatedTags (tagString) {
if (tagString && !tagString.includes(',')) {
tagString = tagString.replace(/\s+/g, ',')
}
return tagString
}

function maybeInt (number) {
const parsed = parseInt(number)
return isNaN(parsed) ? undefined : parsed
Expand Down
Loading
Loading