Skip to content

Commit

Permalink
lazily load SDK APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
bengl committed Jan 29, 2025
1 parent c0550a0 commit 8ff06d8
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions packages/dd-trace/src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,34 @@ const telemetry = require('./telemetry')
const nomenclature = require('./service-naming')
const PluginManager = require('./plugin_manager')
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')

const lazyClasses = {
_AppsecSdk: null,
get AppsecSdk () {
if (this._AppsecSdk) return this._AppsecSdk
return this._AppsecSdk = require('./appsec/sdk')

Check failure on line 23 in packages/dd-trace/src/proxy.js

View workflow job for this annotation

GitHub Actions / lint

Return statement should not contain assignment
},
_NoopAppsecSdk: null,
get NoopAppsecSdk () {
if (this._NoopAppsecSdk) return this._NoopAppsecSdk
return this._NoopAppsecSdk = require('./appsec/noop')

Check failure on line 28 in packages/dd-trace/src/proxy.js

View workflow job for this annotation

GitHub Actions / lint

Return statement should not contain assignment
},
_LLMObsSDK: null,
get LLMObsSDK () {
if (this._LLMObsSDK) return this._LLMObsSDK
return this._LLMObsSDK = require('./llmobs/sdk')

Check failure on line 33 in packages/dd-trace/src/proxy.js

View workflow job for this annotation

GitHub Actions / lint

Return statement should not contain assignment
},
_NoopLLMObsSDK: null,
get NoopLLMObsSDK () {
if (this._NoopLLMObsSDK) return this._NoopLLMObsSDK
return this._NoopLLMObsSDK = require('./llmobs/noop')

Check failure on line 38 in packages/dd-trace/src/proxy.js

View workflow job for this annotation

GitHub Actions / lint

Return statement should not contain assignment
}
}

class LazyModule {
constructor (provider) {
Expand Down Expand Up @@ -217,8 +238,16 @@ class Tracer extends NoopProxy {
const prioritySampler = appsecStandalone.configure(config)
this._tracer = new DatadogTracer(config, prioritySampler)
this.dataStreamsCheckpointer = this._tracer.dataStreamsCheckpointer
this.appsec = new AppsecSdk(this._tracer, config)
this.llmobs = new LLMObsSDK(this._tracer, this._modules.llmobs, config)
if (config.appsec.enabled) {
this.appsec = new lazyClasses.AppsecSdk(this._tracer, config)
} else {
this.appsec = new lazyClasses.NoopAppsecSdk()
}
if (config.llmobs.enabled) {
this.llmobs = new lazyClasses.LLMObsSDK(this._tracer, this._modules.llmobs, config)
} else {
this.llmobs = new lazyClasses.NoopLLMObsSDK()
}
this._tracingInitialized = true
}
if (config.iast.enabled) {
Expand Down

0 comments on commit 8ff06d8

Please sign in to comment.