Skip to content
Closed
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
24 changes: 19 additions & 5 deletions packages/dd-trace/src/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ function parseDefaultByType (raw, type) {
case 'decimal': {
return Number(raw)
}
case 'json': {
return JSON.parse(raw)
}
case 'array': {
if (!raw || raw.length === 0) return []
// TODO: Make the parsing a helper that is reused.
Expand Down Expand Up @@ -86,14 +89,12 @@ for (const entries of Object.values(supportedConfigurations)) {
// The name of that method should be expressive for users.
// TODO: Add handling for all environment variable names. They should not
// need a configuration name for being listed with their default.
if (!Array.isArray(entry.configurationNames)) {
const defaultConfigurationName = entry.internalPropertyName ?? entry.configurationNames?.[0]
if (!defaultConfigurationName) {
continue
}

const parsedValue = parseDefaultByType(entry.default, entry.type)
for (const configurationName of entry.configurationNames) {
metadataDefaults[configurationName] = entry.default === null ? undefined : parsedValue
}
metadataDefaults[defaultConfigurationName] = parsedValue
}
}

Expand Down Expand Up @@ -174,4 +175,17 @@ const defaults = {
version: pkg.version,
}

// Keep legacy object defaults that the pre-runtime-refactor config merge still expects.
defaults.sampler = {
sampleRate: defaults.sampleRate,
rateLimit: defaults.rateLimit,
rules: defaults.samplingRules,
spanSamplingRules: defaults.spanSamplingRules,
}
defaults['sampler.rateLimit'] = defaults.rateLimit
defaults['sampler.rules'] = defaults.samplingRules
defaults['sampler.spanSamplingRules'] = defaults.spanSamplingRules
defaults['profiling.exporters'] = 'agent'
defaults['profiling.sourceMap'] = true

module.exports = defaults
15 changes: 13 additions & 2 deletions packages/dd-trace/src/config/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* @property {string|number|boolean|null|object|unknown[]} default
* @property {string[]} [aliases]
* @property {string[]} [configurationNames]
* @property {string} [internalPropertyName]
* @property {string} [transform]
* @property {string} [allowed]
* @property {string|boolean} [deprecated]
*/

Expand Down Expand Up @@ -57,6 +60,13 @@ for (const [canonical, configuration] of Object.entries(supportedConfigurations)
const aliasToCanonical = {}
for (const canonical of Object.keys(aliases)) {
for (const alias of aliases[canonical]) {
if (supportedConfigurations[alias]) {
// Allow 'fallback' aliases to be used for other configurations.
// This is used to handle the case where an alias could be used for multiple configurations.
// For example, OTEL_EXPORTER_OTLP_ENDPOINT is used for OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
// and OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.
continue
}
if (aliasToCanonical[alias]) {
throw new Error(`The alias ${alias} is already used for ${aliasToCanonical[alias]}.`)
}
Expand Down Expand Up @@ -113,8 +123,9 @@ function getValueFromSource (name, source) {
}

function validateAccess (name) {
if ((name.startsWith('DD_') || name.startsWith('OTEL_') || aliasToCanonical[name]) &&
!supportedConfigurations[name]) {
if ((name.startsWith('DD_') || name.startsWith('OTEL_')) &&
!supportedConfigurations[name] &&
!aliasToCanonical[name]) {
throw new Error(`Missing ${name} env/configuration in "supported-configurations.json" file.`)
}
}
Expand Down
26 changes: 17 additions & 9 deletions packages/dd-trace/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ const TELEMETRY_COUNTERS = new Map([
['otel.env.invalid', {}],
])
const OTEL_DD_ENV_MAPPING = new Map([
// eslint-disable-next-line eslint-rules/eslint-env-aliases
['OTEL_LOG_LEVEL', 'DD_TRACE_LOG_LEVEL'],
// eslint-disable-next-line eslint-rules/eslint-env-aliases
['OTEL_PROPAGATORS', 'DD_TRACE_PROPAGATION_STYLE'],
// eslint-disable-next-line eslint-rules/eslint-env-aliases
['OTEL_SERVICE_NAME', 'DD_SERVICE'],
['OTEL_TRACES_SAMPLER', 'DD_TRACE_SAMPLE_RATE'],
['OTEL_TRACES_SAMPLER_ARG', 'DD_TRACE_SAMPLE_RATE'],
Expand Down Expand Up @@ -405,7 +408,6 @@ class Config {
DD_TRACE_WEBSOCKET_MESSAGES_INHERIT_SAMPLING,
DD_TRACE_WEBSOCKET_MESSAGES_SEPARATE_TRACES,
DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH,
DD_TRACING_ENABLED,
DD_VERSION,
DD_VERTEXAI_SPAN_PROMPT_COMPLETION_SAMPLE_RATE,
DD_VERTEXAI_SPAN_CHAR_LIMIT,
Expand Down Expand Up @@ -462,6 +464,7 @@ class Config {
setString(target, 'otelLogsHeaders', OTEL_EXPORTER_OTLP_LOGS_HEADERS || target.otelHeaders)
setString(target, 'otelProtocol', OTEL_EXPORTER_OTLP_PROTOCOL)
setString(target, 'otelLogsProtocol', OTEL_EXPORTER_OTLP_LOGS_PROTOCOL || target.otelProtocol)
// eslint-disable-next-line eslint-rules/eslint-env-aliases
const otelTimeout = nonNegInt(OTEL_EXPORTER_OTLP_TIMEOUT, 'OTEL_EXPORTER_OTLP_TIMEOUT')
if (otelTimeout !== undefined) {
target.otelTimeout = otelTimeout
Expand Down Expand Up @@ -607,7 +610,8 @@ class Config {
target['experimental.flaggingProvider.initializationTimeoutMs'] =
maybeInt(DD_EXPERIMENTAL_FLAGGING_PROVIDER_INITIALIZATION_TIMEOUT_MS)
}
setBoolean(target, 'traceEnabled', DD_TRACE_ENABLED)
setString(target, 'logLevel', source.DD_TRACE_LOG_LEVEL ?? source.OTEL_LOG_LEVEL)
setBoolean(target, 'tracing', DD_TRACE_ENABLED)
setBoolean(target, 'experimental.aiguard.enabled', DD_AI_GUARD_ENABLED)
setString(target, 'experimental.aiguard.endpoint', DD_AI_GUARD_ENDPOINT)
target['experimental.aiguard.maxContentSize'] = maybeInt(DD_AI_GUARD_MAX_CONTENT_SIZE)
Expand Down Expand Up @@ -654,10 +658,9 @@ class Config {
setString(target, 'installSignature.id', DD_INSTRUMENTATION_INSTALL_ID)
setString(target, 'installSignature.time', DD_INSTRUMENTATION_INSTALL_TIME)
setString(target, 'installSignature.type', DD_INSTRUMENTATION_INSTALL_TYPE)
// TODO: Why is DD_INJECTION_ENABLED a comma separated list?
setArray(target, 'injectionEnabled', DD_INJECTION_ENABLED)
if (DD_INJECTION_ENABLED !== undefined) {
setString(target, 'instrumentationSource', DD_INJECTION_ENABLED ? 'ssi' : 'manual')
setString(target, 'injectionEnabled', DD_INJECTION_ENABLED)
if (DD_INJECTION_ENABLED) {
setString(target, 'instrumentationSource', 'ssi')
}
setBoolean(target, 'injectForce', DD_INJECT_FORCE)
setBoolean(target, 'isAzureFunction', getIsAzureFunction())
Expand Down Expand Up @@ -811,6 +814,7 @@ class Config {
for (const style of otelStyles || []) {
if (!VALID_PROPAGATION_STYLES.has(style)) {
log.warn('unexpected value %s for OTEL_PROPAGATORS environment variable', style)
// eslint-disable-next-line eslint-rules/eslint-env-aliases
getCounter('otel.env.invalid', 'DD_TRACE_PROPAGATION_STYLE', 'OTEL_PROPAGATORS').inc()
}
}
Expand All @@ -824,7 +828,6 @@ class Config {
setBoolean(target, 'traceWebsocketMessagesEnabled', DD_TRACE_WEBSOCKET_MESSAGES_ENABLED)
setBoolean(target, 'traceWebsocketMessagesInheritSampling', DD_TRACE_WEBSOCKET_MESSAGES_INHERIT_SAMPLING)
setBoolean(target, 'traceWebsocketMessagesSeparateTraces', DD_TRACE_WEBSOCKET_MESSAGES_SEPARATE_TRACES)
setBoolean(target, 'tracing', DD_TRACING_ENABLED)
setString(target, 'version', DD_VERSION || tags.version)
setBoolean(target, 'inferredProxyServicesEnabled', DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED)
setBoolean(target, 'trace.aws.addSpanPointers', DD_TRACE_AWS_ADD_SPAN_POINTERS)
Expand Down Expand Up @@ -987,6 +990,7 @@ class Config {
setBoolean(opts, 'llmobs.agentlessEnabled', options.llmobs?.agentlessEnabled)
setString(opts, 'llmobs.mlApp', options.llmobs?.mlApp)
setBoolean(opts, 'logInjection', options.logInjection)
setString(opts, 'logLevel', options.logLevel)
opts.lookup = options.lookup
setBoolean(opts, 'middlewareTracingEnabled', options.middlewareTracingEnabled)
setBoolean(opts, 'openAiLogsEnabled', options.openAiLogsEnabled)
Expand Down Expand Up @@ -1366,12 +1370,16 @@ function isInvalidOtelEnvironmentVariable (envVar, value) {
// Skip validation if the value is undefined (it was not set as environment variable)
if (value === undefined) return false

// eslint-disable-next-line eslint-rules/eslint-env-aliases
if (envVar === 'OTEL_PROPAGATORS' || envVar === 'OTEL_SERVICE_NAME') {
return typeof value !== 'string'
}

switch (envVar) {
// eslint-disable-next-line eslint-rules/eslint-env-aliases
case 'OTEL_LOG_LEVEL':
return !VALID_LOG_LEVELS.has(value)
case 'OTEL_PROPAGATORS':
case 'OTEL_RESOURCE_ATTRIBUTES':
case 'OTEL_SERVICE_NAME':
return typeof value !== 'string'
case 'OTEL_TRACES_SAMPLER':
return getFromOtelSamplerMap(value, getEnv('OTEL_TRACES_SAMPLER_ARG')) === undefined
Expand Down
Loading
Loading