Skip to content

Commit f10e4cd

Browse files
authored
Allow disabling global fetch and cache instrumentation (#130)
1 parent 922ba72 commit f10e4cd

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@microlabs/otel-cf-workers": minor
3+
---
4+
5+
Add option to disable auto-instrumentation of global fetch and cache API

src/sdk.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ function isSpanExporter(exporterConfig: ExporterConfig): exporterConfig is SpanE
7676
let initialised = false
7777
function init(config: ResolvedTraceConfig): void {
7878
if (!initialised) {
79-
instrumentGlobalCache()
80-
instrumentGlobalFetch()
79+
if (config.instrumentation.instrumentGlobalCache) {
80+
instrumentGlobalCache()
81+
}
82+
if (config.instrumentation.instrumentGlobalFetch) {
83+
instrumentGlobalFetch()
84+
}
8185
propagation.setGlobalPropagator(config.propagator)
8286
const resource = createResource(config)
8387

@@ -135,6 +139,10 @@ function parseConfig(supplied: TraceConfig): ResolvedTraceConfig {
135139
service: supplied.service,
136140
spanProcessors,
137141
propagator: supplied.propagator || new W3CTraceContextPropagator(),
142+
instrumentation: {
143+
instrumentGlobalCache: supplied.instrumentation?.instrumentGlobalCache ?? true,
144+
instrumentGlobalFetch: supplied.instrumentation?.instrumentGlobalFetch ?? true,
145+
},
138146
}
139147
} else {
140148
const exporter = isSpanExporter(supplied.exporter) ? supplied.exporter : new OTLPExporter(supplied.exporter)

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ export interface SamplingConfig<HS extends HeadSamplerConf = HeadSamplerConf> {
2929
tailSampler?: TailSampleFn
3030
}
3131

32+
export interface InstrumentationOptions {
33+
instrumentGlobalFetch?: boolean
34+
instrumentGlobalCache?: boolean
35+
}
36+
3237
interface TraceConfigBase {
3338
service: ServiceConfig
3439
handlers?: HandlerConfig
3540
fetch?: FetcherConfig
3641
postProcessor?: PostProcessorFn
3742
sampling?: SamplingConfig
3843
propagator?: TextMapPropagator
44+
instrumentation?: InstrumentationOptions
3945
}
4046

4147
interface TraceConfigExporter extends TraceConfigBase {
@@ -59,6 +65,7 @@ export interface ResolvedTraceConfig extends TraceConfigBase {
5965
sampling: Required<SamplingConfig<Sampler>>
6066
spanProcessors: SpanProcessor[]
6167
propagator: TextMapPropagator
68+
instrumentation: InstrumentationOptions
6269
}
6370

6471
export interface DOConstructorTrigger {

0 commit comments

Comments
 (0)