Skip to content
Draft
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
4 changes: 4 additions & 0 deletions packages/dd-trace/src/aiguard/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class AIGuard extends NoopAIGuard {
#maxContentSize
#meta

/**
* @param {import('../tracer')} tracer - Tracer instance
* @param {import('../config/config-base')} config - Tracer configuration
*/
constructor (tracer, config) {
super()

Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/appsec/blocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ function getBlockingAction (actions) {
return actions?.redirect_request || actions?.block_request
}

/**
* @param {import('../config/config-base')} config - Tracer configuration
*/
function setTemplates (config) {
templateHtml = config.appsec.blockedTemplateHtml || blockedTemplates.html

Expand Down
4 changes: 4 additions & 0 deletions packages/dd-trace/src/appsec/sdk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class EventTrackingV2 {
}

class AppsecSdk {
/**
* @param {import('../../tracer')} tracer - Tracer instance
* @param {import('../../config/config-base')} config - Tracer configuration
*/
constructor (tracer, config) {
this._tracer = tracer
if (config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class TestApiManualPlugin extends CiPlugin {
})
}

/**
* @param {import('../../config/config-base')} config - Tracer configuration
* @param {boolean} shouldGetEnvironmentData - Whether to get environment data
*/
configure (config, shouldGetEnvironmentData) {
this._config = config
super.configure(config, shouldGetEnvironmentData)
Expand Down
7 changes: 3 additions & 4 deletions packages/dd-trace/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,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
4 changes: 2 additions & 2 deletions packages/dd-trace/src/config/supported-configurations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1066,8 +1066,8 @@
"DD_INJECTION_ENABLED": [
{
"implementation": "A",
"type": "array",
"default": "",
"type": "string",
"default": null,
"configurationNames": [
"injectionEnabled"
]
Expand Down
8 changes: 7 additions & 1 deletion packages/dd-trace/src/crashtracking/crashtracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class Crashtracker {
}
}

/**
* @param {import('../config/config-base')} config - Tracer configuration
*/
start (config) {
if (this.#started) return this.configure(config)

Expand All @@ -35,7 +38,7 @@ class Crashtracker {
this.#getMetadata(config)
)
} catch (e) {
log.error('Error initialising crashtracker', e)
log.error('Error initializing crashtracker', e)
}
}

Expand All @@ -49,6 +52,9 @@ class Crashtracker {
}

// TODO: Send only configured values when defaults are fixed.
/**
* @param {import('../config/config-base')} config - Tracer configuration
*/
#getConfig (config) {
const url = getAgentUrl(config)

Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/debugger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function start (config, rcInstance) {
* Sends the new configuration to the worker thread via the config channel.
* Does nothing if the worker is not started.
*
* @param {Config} config - The updated tracer configuration object
* @param {import('../config/config-base')} config - The updated tracer configuration object
*/
function configure (config) {
if (configChannel === null) return
Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/heap_snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ function getName (destination) {
}

module.exports = {
/**
* @param {import('./config/config-base')} config - Tracer configuration
*/
async start (config) {
const destination = config.heapSnapshot.destination

Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/opentelemetry/logs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const OtlpHttpLogExporter = require('./otlp_http_log_exporter')

/**
* Initializes OpenTelemetry Logs support
* @param {Config} config - Tracer configuration instance
* @param {import('../../config/config-base')} config - Tracer configuration instance
*/
function initializeOpenTelemetryLogs (config) {
// Build resource attributes
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/opentelemetry/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const OtlpHttpMetricExporter = require('./otlp_http_metric_exporter')

/**
* Initializes OpenTelemetry Metrics support
* @param {Config} config - Tracer configuration instance
* @param {import('../../config/config-base')} config - Tracer configuration instance
*/
function initializeOpenTelemetryMetrics (config) {
const resourceAttributes = {
Expand Down
11 changes: 6 additions & 5 deletions packages/dd-trace/src/payload-tagging/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
const aws = require('./aws.json')
const sdks = { aws }

/** @typedef {Record<string, { request: string[], response: string[], expand: string[] }>} SDKRules */
/**
* Builds rules per service for a given SDK, appending user-provided rules.
*
* @param {Record<string, { request: string[], response: string[], expand: string[] }>} sdk
* @param {SDKRules} sdk
* @param {string[]} requestInput
* @param {string[]} responseInput
* @returns {Record<string, { request: string[], response: string[], expand: string[] }>}
* @returns {SDKRules}
*/
function getSDKRules (sdk, requestInput, responseInput) {
const sdkServiceRules = {}
const sdkServiceRules = /** @type {SDKRules} */ ({})
for (const [service, serviceRules] of Object.entries(sdk)) {
sdkServiceRules[service] = {
// Make a copy. Otherwise calling the function multiple times would append
Expand All @@ -31,10 +32,10 @@ function getSDKRules (sdk, requestInput, responseInput) {
*
* @param {string[]} [requestInput=[]]
* @param {string[]} [responseInput=[]]
* @returns {Record<string, Record<string, { request: string[], response: string[], expand: string[] }>>}
* @returns {Record<string, SDKRules>}
*/
function appendRules (requestInput = [], responseInput = []) {
const sdkRules = {}
const sdkRules = /** @type {Record<string, SDKRules>} */ ({})
for (const [name, sdk] of Object.entries(sdks)) {
sdkRules[name] = getSDKRules(sdk, requestInput, responseInput)
}
Expand Down
9 changes: 6 additions & 3 deletions packages/dd-trace/src/plugin_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function getEnabled (Plugin) {
module.exports = class PluginManager {
constructor (tracer) {
this._tracer = tracer
this._tracerConfig = null
this._tracerConfig = /** @type {import('./config/config-base')} */ (null)
this._pluginsByName = {}
this._configsByName = {}

Expand Down Expand Up @@ -121,8 +121,11 @@ module.exports = class PluginManager {
this.loadPlugin(name)
}

// like instrumenter.enable()
configure (config = {}) {
/**
* Like instrumenter.enable()
* @param {import('./config/config-base')} config - Tracer configuration
*/
configure (config) {
this._tracerConfig = config
this._tracer._nomenclature.configure(config)

Expand Down
4 changes: 4 additions & 0 deletions packages/dd-trace/src/plugins/ci_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ module.exports = class CiPlugin extends Plugin {
return getSessionRequestErrorTags(this.testSessionSpan)
}

/**
* @param {import('../config/config-base')} config - Tracer configuration
* @param {boolean} shouldGetEnvironmentData - Whether to get environment data
*/
configure (config, shouldGetEnvironmentData = true) {
super.configure(config)

Expand Down
7 changes: 4 additions & 3 deletions packages/dd-trace/src/plugins/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ module.exports = class Plugin {
/**
* Enable or disable the plugin and (re)apply its configuration.
*
* @param {boolean|object} config Either a boolean to enable/disable or a configuration object
* containing at least `{ enabled: boolean }`.
* @returns {void}
* TODO: Remove the overloading with `enabled` and use the config object directly.
*
* @param {boolean|import('../config/config-base')} config Either a boolean to enable/disable
* or a configuration object containing at least `{ enabled: boolean }`.
*/
configure (config) {
if (typeof config === 'boolean') {
Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/process-tags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ function buildProcessTags (config) {

// Singleton with constant defaults so pre-init reads don't blow up
const processTags = module.exports = {
/**
* @param {import('../config/config-base')} config
*/
initialize (config) {
// check if one of the properties added during build exist and if so return
if (processTags.tags) return
Expand Down
7 changes: 5 additions & 2 deletions packages/dd-trace/src/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ const { profiler } = require('./profiling')
globalThis[Symbol.for('dd-trace')].beforeExitHandlers.add(() => { profiler.stop() })

module.exports = {
start: config => {
/**
* @param {import('./config/config-base')} config - Tracer configuration
*/
start (config) {
// Forward the full tracer config to the profiling layer.
// Profiling code is responsible for deriving the specific options it needs.
return profiler.start(config)
},

stop: () => {
stop () {
profiler.stop()
},
}
5 changes: 1 addition & 4 deletions packages/dd-trace/src/profiling/exporter_cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ function exporterFromURL (url) {
if (url.protocol === 'file:') {
return new FileExporter({ pprofPrefix: fileURLToPath(url) })
}
// TODO: Why is DD_INJECTION_ENABLED a comma separated list?
const injectionEnabled = (getValueFromEnvSources('DD_INJECTION_ENABLED') ?? '').split(',')
const libraryInjected = injectionEnabled.length > 0
const profilingEnabled = (getValueFromEnvSources('DD_PROFILING_ENABLED') ?? '').toLowerCase()
const activation = ['true', '1'].includes(profilingEnabled)
? 'manual'
Expand All @@ -30,7 +27,7 @@ function exporterFromURL (url) {
url,
logger,
uploadTimeout: timeoutMs,
libraryInjected,
libraryInjected: !!getValueFromEnvSources('DD_INJECTION_ENABLED'),
activation,
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/profiling/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Profiler extends EventEmitter {
error (...args) { log.error(...args) },
}

const libraryInjected = injectionEnabled.length > 0
const libraryInjected = !!injectionEnabled
let activation
if (enabled === 'auto') {
activation = 'auto'
Expand Down
5 changes: 4 additions & 1 deletion packages/dd-trace/src/profiling/ssi-heuristics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const dc = require('dc-polyfill')
const dc = /** @type {typeof import('diagnostics_channel')} */ (require('dc-polyfill'))
const log = require('../log')

// If the process lives for at least 30 seconds, it's considered long-lived
Expand All @@ -10,6 +10,9 @@ const DEFAULT_LONG_LIVED_THRESHOLD = 30_000
* This class embodies the SSI profiler-triggering heuristics under SSI.
*/
class SSIHeuristics {
/**
* @param {import('../config/config-base')} config - Tracer configuration
*/
constructor (config) {
const longLivedThreshold = config.profiling.longLivedThreshold || DEFAULT_LONG_LIVED_THRESHOLD
if (typeof longLivedThreshold !== 'number' || longLivedThreshold <= 0) {
Expand Down
3 changes: 2 additions & 1 deletion packages/dd-trace/src/propagation-hash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ class PropagationHashManager {
_cachedHash = null
_cachedHashString = null
_cachedHashBase64 = null
/** @type {import('../config/config-base') | null} */
_config = null

/**
* Configure the propagation hash manager with tracer config
* @param {object} config - Tracer configuration
* @param {import('../config/config-base')} config - Tracer configuration
*/
configure (config) {
this._config = config
Expand Down
16 changes: 13 additions & 3 deletions packages/dd-trace/src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ class LazyModule {
this.provider = provider
}

enable (...args) {
/**
* @param {import('./config/config-base')} config - Tracer configuration
*/
enable (config, ...args) {
this.module = this.provider()
this.module.enable(...args)
this.module.enable(config, ...args)
}

disable () {
Expand Down Expand Up @@ -237,12 +240,16 @@ class Tracer extends NoopProxy {
getDynamicInstrumentationClient(config)
}
} catch (e) {
log.error('Error initialising tracer', e)
log.error('Error initializing tracer', e)
// TODO: Should we stop everything started so far?
}

return this
}

/**
* @param {import('./config/config-base')} config - Tracer configuration
*/
_startProfiler (config) {
// do not stop tracer initialization if the profiler fails to be imported
try {
Expand All @@ -256,6 +263,9 @@ class Tracer extends NoopProxy {
}
}

/**
* @param {import('./config/config-base')} config - Tracer configuration
*/
#updateTracing (config) {
if (config.tracing !== false) {
if (config.appsec.enabled) {
Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/remote_config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class RemoteConfig {
#products = new Set()
#batchHandlers = new Map()

/**
* @param {import('../config/config-base')} config - Tracer configuration
*/
constructor (config) {
const pollInterval = Math.floor(config.remoteConfig.pollInterval * 1000)

Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/runtime_metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const noop = runtimeMetrics = {
}

module.exports = {
/**
* @param {import('../config/config-base')} config - Tracer configuration
*/
start (config) {
if (!config?.runtimeMetrics.enabled) return

Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/runtime_metrics/runtime_metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ let eventLoopDelayObserver = null
// https://github.com/DataDog/dogweb/blob/prod/integration/node/node_metadata.csv

module.exports = {
/**
* @param {import('../config/config-base')} config - Tracer configuration
*/
start (config) {
this.stop()
const clientConfig = DogStatsDClient.generateClientConfig(config)
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Sampler {
/**
* Determines whether a trace/span should be sampled based on the configured sampling rate.
*
* @param {Span|SpanContext} span - The span or span context to evaluate.
* @param {import("../../..").Span|import("../../..").SpanContext} span - The span or span context to evaluate.
* @returns {boolean} `true` if the trace/span should be sampled, otherwise `false`.
*/
isSampled (span) {
Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/standalone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const startCh = channel('dd-trace:span:start')
const injectCh = channel('dd-trace:span:inject')
const extractCh = channel('dd-trace:span:extract')

/**
* @param {import('../config/config-base')} config - Tracer configuration
*/
function configure (config) {
if (startCh.hasSubscribers) startCh.unsubscribe(onSpanStart)
if (injectCh.hasSubscribers) injectCh.unsubscribe(onSpanInject)
Expand Down
Loading
Loading