Skip to content
Open
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
2 changes: 1 addition & 1 deletion benchmark/sirun/exporting-pipeline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const SpanProcessor = require('../../../packages/dd-trace/src/span_processor')
const Exporter = require('../../../packages/dd-trace/src/exporters/agent/index')
const PrioritySampler = require('../../../packages/dd-trace/src/priority_sampler')
const id = require('../../../packages/dd-trace/src/id')
const defaults = require('../../../packages/dd-trace/src/config/defaults')
const { defaults } = require('../../../packages/dd-trace/src/config/defaults')

const config = {
url: `http://${defaults.hostname}:${defaults.port}`,
Expand Down
2 changes: 1 addition & 1 deletion benchmark/sirun/statsd.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const dgram = require('dgram')
const defaults = require('../../packages/dd-trace/src/config/defaults')
const { defaults } = require('../../packages/dd-trace/src/config/defaults')
const port = process.env.SIRUN_STATSD_PORT || defaults['dogstatsd.port']

class StatsD {
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ describe('init.js', () => {
// or on 18.0.0 in particular.
if (semver.satisfies(process.versions.node, '>=14.13.1')) {
describe('initialize.mjs', () => {
setShouldKill(false)
// Node 20.0.0 can leave short-lived loader-based children alive after they
// print the expected output, so terminate them after a short grace period.
setShouldKill(process.versions.node === '20.0.0')
useSandbox()
stubTracerIfNeeded()

Expand Down
145 changes: 49 additions & 96 deletions integration-tests/opentelemetry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ function nearNow (ts, now = Date.now(), range = 1000) {
return delta < range && delta >= 0
}

describe('opentelemetry', () => {
let agent
describe('opentelemetry', function () {
this.timeout(20000)

let agent = /** @type {FakeAgent | null} */ (null)
let proc
let cwd
let cwd = /** @type {string} */ ('')
const timeout = 5000
const dependencies = [
'@opentelemetry/api@1.8.0',
Expand All @@ -75,14 +77,14 @@ describe('opentelemetry', () => {

after(async () => {
await stopProc(proc)
await agent.stop()
await agent?.stop()
})

it("should not capture telemetry DD and OTEL vars don't conflict", async () => {
proc = fork(join(cwd, 'opentelemetry/basic.js'), {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_TRACE_AGENT_PORT: agent?.port,
DD_TRACE_OTEL_ENABLED: '1',
DD_TELEMETRY_HEARTBEAT_INTERVAL: '1',
TIMEOUT: '1500',
Expand Down Expand Up @@ -114,7 +116,7 @@ describe('opentelemetry', () => {
proc = fork(join(cwd, 'opentelemetry/basic.js'), {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_TRACE_AGENT_PORT: agent?.port,
DD_TRACE_OTEL_ENABLED: '1',
DD_TELEMETRY_HEARTBEAT_INTERVAL: '1',
TIMEOUT: '1500',
Expand Down Expand Up @@ -147,42 +149,20 @@ describe('opentelemetry', () => {

const otelHiding = metrics.series.filter(({ metric }) => metric === 'otel.env.hiding')
const otelInvalid = metrics.series.filter(({ metric }) => metric === 'otel.env.invalid')
assert.strictEqual(otelHiding.length, 9)
assert.strictEqual(otelInvalid.length, 0)

assert.deepStrictEqual(otelHiding[0].tags, [
'config_datadog:dd_trace_log_level', 'config_opentelemetry:otel_log_level',
])
assert.deepStrictEqual(otelHiding[1].tags, [
'config_datadog:dd_trace_propagation_style', 'config_opentelemetry:otel_propagators',
])
assert.deepStrictEqual(otelHiding[2].tags, [
'config_datadog:dd_service', 'config_opentelemetry:otel_service_name',
])

assert.deepStrictEqual(otelHiding[3].tags, [
'config_datadog:dd_trace_sample_rate', 'config_opentelemetry:otel_traces_sampler',
])

assert.deepStrictEqual(otelHiding[4].tags, [
'config_datadog:dd_trace_sample_rate', 'config_opentelemetry:otel_traces_sampler_arg',
])

assert.deepStrictEqual(otelHiding[5].tags, [
'config_datadog:dd_trace_enabled', 'config_opentelemetry:otel_traces_exporter',
])

assert.deepStrictEqual(otelHiding[6].tags, [
'config_datadog:dd_runtime_metrics_enabled', 'config_opentelemetry:otel_metrics_exporter',
])

assert.deepStrictEqual(otelHiding[7].tags, [
'config_datadog:dd_tags', 'config_opentelemetry:otel_resource_attributes',
])
assert.deepStrictEqual(sortMetricTags(otelHiding), sortMetricTags([
['config_datadog:dd_trace_log_level', 'config_opentelemetry:otel_log_level'],
['config_datadog:dd_trace_propagation_style', 'config_opentelemetry:otel_propagators'],
['config_datadog:dd_service', 'config_opentelemetry:otel_service_name'],
['config_datadog:dd_trace_sample_rate', 'config_opentelemetry:otel_traces_sampler'],
['config_datadog:dd_trace_sample_rate', 'config_opentelemetry:otel_traces_sampler_arg'],
['config_datadog:dd_trace_enabled', 'config_opentelemetry:otel_traces_exporter'],
['config_datadog:dd_runtime_metrics_enabled', 'config_opentelemetry:otel_metrics_exporter'],
['config_datadog:dd_tags', 'config_opentelemetry:otel_resource_attributes'],
['config_datadog:dd_trace_otel_enabled', 'config_opentelemetry:otel_sdk_disabled'],
]))

assert.deepStrictEqual(otelHiding[8].tags, [
'config_datadog:dd_trace_otel_enabled', 'config_opentelemetry:otel_sdk_disabled',
])
assert.deepStrictEqual(sortMetricTags(otelInvalid), [])

for (const metric of otelHiding) {
assert.strictEqual(metric.points[0][1], 1)
Expand All @@ -194,7 +174,7 @@ describe('opentelemetry', () => {
proc = fork(join(cwd, 'opentelemetry/basic.js'), {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_TRACE_AGENT_PORT: agent?.port,
DD_TRACE_OTEL_ENABLED: '1',
DD_TELEMETRY_HEARTBEAT_INTERVAL: '1',
TIMEOUT: '1500',
Expand All @@ -221,47 +201,20 @@ describe('opentelemetry', () => {
const otelHiding = metrics.series.filter(({ metric }) => metric === 'otel.env.hiding')
const otelInvalid = metrics.series.filter(({ metric }) => metric === 'otel.env.invalid')

assert.strictEqual(otelHiding.length, 1)
assert.strictEqual(otelInvalid.length, 8)

assert.deepStrictEqual(otelHiding[0].tags, [
'config_datadog:dd_trace_otel_enabled', 'config_opentelemetry:otel_sdk_disabled',
])

assert.deepStrictEqual(otelInvalid[0].tags, [
'config_datadog:dd_trace_log_level', 'config_opentelemetry:otel_log_level',
])

assert.deepStrictEqual(otelInvalid[1].tags, [
'config_datadog:dd_trace_sample_rate',
'config_opentelemetry:otel_traces_sampler',
])

assert.deepStrictEqual(otelInvalid[2].tags, [
'config_datadog:dd_trace_sample_rate',
'config_opentelemetry:otel_traces_sampler_arg',
])
assert.deepStrictEqual(otelInvalid[3].tags, [
'config_datadog:dd_trace_enabled', 'config_opentelemetry:otel_traces_exporter',
])

assert.deepStrictEqual(otelInvalid[4].tags, [
'config_datadog:dd_runtime_metrics_enabled',
'config_opentelemetry:otel_metrics_exporter',
])

assert.deepStrictEqual(otelInvalid[5].tags, [
'config_datadog:dd_trace_otel_enabled', 'config_opentelemetry:otel_sdk_disabled',
])

assert.deepStrictEqual(otelInvalid[6].tags, [
'config_opentelemetry:otel_logs_exporter',
])

assert.deepStrictEqual(otelInvalid[7].tags, [
'config_datadog:dd_trace_propagation_style',
'config_opentelemetry:otel_propagators',
])
assert.deepStrictEqual(sortMetricTags(otelHiding), sortMetricTags([
['config_datadog:dd_trace_otel_enabled', 'config_opentelemetry:otel_sdk_disabled'],
]))

assert.deepStrictEqual(sortMetricTags(otelInvalid), sortMetricTags([
['config_datadog:dd_trace_log_level', 'config_opentelemetry:otel_log_level'],
['config_datadog:dd_trace_propagation_style', 'config_opentelemetry:otel_propagators'],
['config_opentelemetry:otel_logs_exporter'],
['config_datadog:dd_trace_sample_rate', 'config_opentelemetry:otel_traces_sampler'],
['config_datadog:dd_trace_sample_rate', 'config_opentelemetry:otel_traces_sampler_arg'],
['config_datadog:dd_trace_enabled', 'config_opentelemetry:otel_traces_exporter'],
['config_datadog:dd_runtime_metrics_enabled', 'config_opentelemetry:otel_metrics_exporter'],
['config_datadog:dd_trace_otel_enabled', 'config_opentelemetry:otel_sdk_disabled'],
]))

for (const metric of otelInvalid) {
assert.strictEqual(metric.points[0][1], 1)
Expand All @@ -273,7 +226,7 @@ describe('opentelemetry', () => {
proc = fork(join(cwd, 'opentelemetry/basic.js'), {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_TRACE_AGENT_PORT: agent?.port,
},
})
await check(agent, proc, timeout, ({ payload }) => {
Expand All @@ -292,7 +245,7 @@ describe('opentelemetry', () => {
proc = fork(join(cwd, 'opentelemetry/basic.js'), {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_TRACE_AGENT_PORT: agent?.port,
DD_TRACE_OTEL_ENABLED: '1',
DD_TELEMETRY_HEARTBEAT_INTERVAL: '1',
TIMEOUT: '1500',
Expand Down Expand Up @@ -334,7 +287,7 @@ describe('opentelemetry', () => {
proc = fork(join(cwd, 'opentelemetry/auto-instrumentation.js'), {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_TRACE_AGENT_PORT: agent?.port,
DD_TRACE_OTEL_ENABLED: '1',
SERVER_PORT,
DD_TRACE_DISABLED_INSTRUMENTATIONS: 'http,dns,express,net',
Expand Down Expand Up @@ -378,7 +331,7 @@ describe('opentelemetry', () => {
proc = fork(join(cwd, 'opentelemetry/server.js'), {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_TRACE_AGENT_PORT: agent?.port,
},
})
await check(agent, proc, timeout, ({ payload }) => {
Expand Down Expand Up @@ -407,7 +360,7 @@ describe('opentelemetry', () => {
proc = fork(join(cwd, 'opentelemetry/auto-instrumentation.js'), {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_TRACE_AGENT_PORT: agent?.port,
DD_TRACE_OTEL_ENABLED: '1',
SERVER_PORT,
DD_TRACE_DISABLED_INSTRUMENTATIONS: 'http,dns,express,net',
Expand Down Expand Up @@ -456,18 +409,12 @@ describe('opentelemetry', () => {
proc = fork(join(cwd, 'opentelemetry/env-var.js'), {
cwd,
env: {
DD_TRACE_AGENT_PORT: agent.port,
DD_TRACE_AGENT_PORT: agent?.port,
},
})
await check(agent, proc, timeout, ({ payload }) => {
// Should have a single trace with a single span
assert.strictEqual(payload.length, 1)
const [trace] = payload
assert.strictEqual(trace.length, 1)
const [span] = trace

// Should be the expected otel span
assert.strictEqual(span.name, 'otel-sub')
const trace = payload.find(trace => trace.length === 1 && trace[0].name === 'otel-sub')
assert.ok(trace)
})
})
})
Expand All @@ -477,3 +424,9 @@ function isChildOf (childSpan, parentSpan) {
assert.notStrictEqual(childSpan.span_id.toString(), parentSpan.span_id.toString())
assert.strictEqual(childSpan.parent_id.toString(), parentSpan.span_id.toString())
}

function sortMetricTags (metrics) {
return metrics
.map(metric => Array.isArray(metric) ? metric : metric.tags)
.sort((a, b) => a.join(',').localeCompare(b.join(',')))
}
2 changes: 1 addition & 1 deletion integration-tests/package-guardrails.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
const NODE_OPTIONS = '--require dd-trace/init.js'
const DD_TRACE_DEBUG = 'true'
const DD_INJECTION_ENABLED = 'tracing'
const DD_LOG_LEVEL = 'error'
const DD_LOG_LEVEL = 'info'
const NODE_MAJOR = Number(process.versions.node.split('.')[0])
const FASTIFY_DEP = NODE_MAJOR < 20 ? 'fastify@4' : 'fastify'

Expand Down
8 changes: 4 additions & 4 deletions integration-tests/telemetry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('telemetry', () => {
proc = await spawnProc(startupTestFile, {
cwd,
env: {
AGENT_PORT: agent.port,
AGENT_PORT: String(agent.port),
DD_LOGS_INJECTION: 'true',
},
})
Expand Down Expand Up @@ -66,9 +66,9 @@ describe('telemetry', () => {
await agent.assertTelemetryReceived(msg => {
const { configuration } = msg.payload.payload
assertObjectContains(configuration, [
{ name: 'DD_LOG_INJECTION', value: true, origin: 'default' },
{ name: 'DD_LOG_INJECTION', value: true, origin: 'env_var' },
{ name: 'DD_LOG_INJECTION', value: false, origin: 'code' },
{ name: 'DD_LOGS_INJECTION', value: true, origin: 'default' },
{ name: 'DD_LOGS_INJECTION', value: true, origin: 'env_var' },
{ name: 'DD_LOGS_INJECTION', value: false, origin: 'code' },
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to commit message

])
}, 'app-started', 5_000, 1)
})
Expand Down
7 changes: 4 additions & 3 deletions packages/datadog-plugin-aws-sdk/src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ class BaseAwsSdkPlugin extends ClientPlugin {
return id
}

/** @type {import('../../dd-trace/src/config/config-types').ConfigProperties['cloudPayloadTagging']} */
get cloudTaggingConfig () {
return this._tracerConfig.cloudPayloadTagging
}

get payloadTaggingRules () {
return this.cloudTaggingConfig.rules.aws?.[this.constructor.id]
return this.cloudTaggingConfig.rules?.aws?.[this.constructor.id]
}

constructor (...args) {
Expand Down Expand Up @@ -78,7 +79,7 @@ class BaseAwsSdkPlugin extends ClientPlugin {
this.requestInject(span, request)
})

if (this.constructor.isPayloadReporter && this.cloudTaggingConfig.requestsEnabled) {
if (this.constructor.isPayloadReporter && this.cloudTaggingConfig.request) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's explain (broadly/generally, not specifically for each such change) that this is a simplification, etc.

const maxDepth = this.cloudTaggingConfig.maxDepth
const requestTags = tagsFromRequest(this.payloadTaggingRules, request.params, { maxDepth })
span.addTags(requestTags)
Expand Down Expand Up @@ -215,7 +216,7 @@ class BaseAwsSdkPlugin extends ClientPlugin {

span.addTags(tags)

if (this.constructor.isPayloadReporter && this.cloudTaggingConfig.responsesEnabled) {
if (this.constructor.isPayloadReporter && this.cloudTaggingConfig.response) {
const maxDepth = this.cloudTaggingConfig.maxDepth
const responseBody = this.extractResponseBody(response)
const responseTags = tagsFromResponse(this.payloadTaggingRules, responseBody, { maxDepth })
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-plugin-grpc/test/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const loader = require('../../../versions/@grpc/proto-loader').get()
const { withNamingSchema, withPeerService, withVersions } = require('../../dd-trace/test/setup/mocha')
const agent = require('../../dd-trace/test/plugins/agent')
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
const defaults = require('../../dd-trace/src/config/defaults')
const { defaults } = require('../../dd-trace/src/config/defaults')
const { NODE_MAJOR } = require('../../../version')
const getService = require('./service')

Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-plugin-grpc/test/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { assertObjectContains } = require('../../../integration-tests/helpers')
const { withNamingSchema, withVersions } = require('../../dd-trace/test/setup/mocha')
const agent = require('../../dd-trace/test/plugins/agent')
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
const defaults = require('../../dd-trace/src/config/defaults')
const { defaults } = require('../../dd-trace/src/config/defaults')
const { NODE_MAJOR } = require('../../../version')

const GRPC_SERVER_ERROR_STATUSES = defaults['grpc.server.error.statuses']
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/agent/url.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { URL, format } = require('url')
const defaults = require('../config/defaults')
const { defaults } = require('../config/defaults')

module.exports = { getAgentUrl }

Expand All @@ -12,7 +12,7 @@ module.exports = { getAgentUrl }

/**
* Gets the agent URL from config, constructing it from hostname/port if needed
* @param {ReturnType<import('../config')>} config - Tracer configuration object
* @param {Partial<import('../config/config-base')>} config - Tracer configuration object
* @returns {URL} The agent URL
*/
function getAgentUrl (config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const log = require('../../../../log')
const vulnerabilities = require('../../vulnerabilities')
const defaults = require('../../../../config/defaults')
const { defaults } = require('../../../../config/defaults')

const { contains, intersects, remove } = require('./range-utils')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const crypto = require('crypto')

const defaults = require('../../../config/defaults')
const { defaults } = require('../../../config/defaults')

const STRINGIFY_RANGE_KEY = 'DD_' + crypto.randomBytes(20).toString('hex')
const STRINGIFY_SENSITIVE_KEY = STRINGIFY_RANGE_KEY + 'SENSITIVE'
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/appsec/remote_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function enableOrDisableAppsec (action, rcConfig, config, appsec) {
appsec.disable()
}

// TODO: Use configWithOrigin /generateTelemetry instead of manually constructing the change.
updateConfig([
{
name: 'appsec.enabled',
Expand Down
Loading
Loading