Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling global fetch and cache instrumentation #130

Merged
merged 2 commits into from
Apr 29, 2024
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
5 changes: 5 additions & 0 deletions .changeset/violet-bananas-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@microlabs/otel-cf-workers": minor
---

Add option to disable auto-instrumentation of global fetch and cache API
12 changes: 10 additions & 2 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ function isSpanExporter(exporterConfig: ExporterConfig): exporterConfig is SpanE
let initialised = false
function init(config: ResolvedTraceConfig): void {
if (!initialised) {
instrumentGlobalCache()
instrumentGlobalFetch()
if (config.instrumentation.instrumentGlobalCache) {
instrumentGlobalCache()
}
if (config.instrumentation.instrumentGlobalFetch) {
instrumentGlobalFetch()
}
propagation.setGlobalPropagator(config.propagator)
const resource = createResource(config)

Expand Down Expand Up @@ -135,6 +139,10 @@ function parseConfig(supplied: TraceConfig): ResolvedTraceConfig {
service: supplied.service,
spanProcessors,
propagator: supplied.propagator || new W3CTraceContextPropagator(),
instrumentation: {
instrumentGlobalCache: supplied.instrumentation?.instrumentGlobalCache ?? true,
instrumentGlobalFetch: supplied.instrumentation?.instrumentGlobalFetch ?? true,
},
}
} else {
const exporter = isSpanExporter(supplied.exporter) ? supplied.exporter : new OTLPExporter(supplied.exporter)
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ export interface SamplingConfig<HS extends HeadSamplerConf = HeadSamplerConf> {
tailSampler?: TailSampleFn
}

export interface InstrumentationOptions {
instrumentGlobalFetch?: boolean
instrumentGlobalCache?: boolean
}

interface TraceConfigBase {
service: ServiceConfig
handlers?: HandlerConfig
fetch?: FetcherConfig
postProcessor?: PostProcessorFn
sampling?: SamplingConfig
propagator?: TextMapPropagator
instrumentation?: InstrumentationOptions
}

interface TraceConfigExporter extends TraceConfigBase {
Expand All @@ -59,6 +65,7 @@ export interface ResolvedTraceConfig extends TraceConfigBase {
sampling: Required<SamplingConfig<Sampler>>
spanProcessors: SpanProcessor[]
propagator: TextMapPropagator
instrumentation: InstrumentationOptions
}

export interface DOConstructorTrigger {
Expand Down