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
14 changes: 12 additions & 2 deletions packages/dd-trace/src/opentracing/span.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const log = require('../log')
const { storage } = require('../../../datadog-core')
const telemetryMetrics = require('../telemetry/metrics')
const { channel } = require('dc-polyfill')
const spanleak = require('../spanleak')
const util = require('util')

const tracerMetrics = telemetryMetrics.manager.namespace('tracers')
Expand Down Expand Up @@ -99,7 +98,18 @@ class DatadogSpan {

unfinishedRegistry.register(this, operationName, this)
}
spanleak.addSpan(this, operationName)

// Nullish operator is used here because both `tracer` and `tracer._config`
// can be null and there are tests passing invalid values to the `Span`
// constructor which still succeed today. Part of the problem is that `Span`
// stores only the tracer and not the config, so anything that needs the
// config has to read it from the tracer stored on the span, including
// even `Span` itself in this case.
//
// TODO: Refactor Tracer/Span + tests to avoid having to do nullish checks.
if (tracer?._config?.spanLeakDebug > 0) {
Comment thread
BridgeAR marked this conversation as resolved.
require('../spanleak').addSpan(this, operationName)
}

if (startCh.hasSubscribers) {
startCh.publish({ span: this, fields })
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const remoteConfig = require('./appsec/remote_config')
const AppsecSdk = require('./appsec/sdk')
const dogstatsd = require('./dogstatsd')
const NoopDogStatsDClient = require('./noop/dogstatsd')
const spanleak = require('./spanleak')
const { SSIHeuristics } = require('./profiling/ssi-heuristics')
const appsecStandalone = require('./appsec/standalone')
const LLMObsSDK = require('./llmobs/sdk')
Expand Down Expand Up @@ -80,6 +79,7 @@ class Tracer extends NoopProxy {
}

if (config.spanLeakDebug > 0) {
const spanleak = require('./spanleak')
if (config.spanLeakDebug === spanleak.MODES.LOG) {
spanleak.enableLogging()
} else if (config.spanLeakDebug === spanleak.MODES.GC_AND_LOG) {
Expand Down