opentelemetry-js
opentelemetry-js copied to clipboard
Allow libraries to suppress tracing without taking a dependency on core
I'm instrumenting one of my libraries with opentelemetry and am running into a scenario where I'd like to suppress instrumentation to ensure my users don't incur undue costs by using my library. In particular I have a loop that polls for new data from a database and forwards the data to a handler
while (!signal.aborted) {
const batch = await nextBatch()
await handler(batch.items)
if (!batch.hasMore) await sleep(100)
}
under the hood nextBatch
makes a database call and therefore creates a span.
In this case I'd be emitting a span every 100ms or so, but this span would have little to no value. What I'd like to do is some form of head sampling, only emitting one of these spans every 5 minutes
let lastSampledSpan = Date.now()
const updateTime = x => { lastSampledSpan = Date.now(); return x }
while (!signal.aborted) {
const batch = Date.now() - lastSampledSpan > 3e5
? await nextBatch().then(updateTime)
: await context.with(suppressTracing(context.active()), nextBatch)
await handler(batch.items)
if (!batch.hasMore) await sleep(100)
}
But this forces me to take a dependency on @opentelemetry/core
rather than just the API.
Describe the solution you'd like
I'd like suppressTracing
to be exposed through the api rather than the core package
There is an "ongoing" discussion in API spec regarding this: see https://github.com/open-telemetry/opentelemetry-specification/issues/530 and https://github.com/open-telemetry/opentelemetry-specification/pull/3103
I fear as long as spec part is not finished it's hard to get this into API.
@open-telemetry/javascript-maintainers Has there anything changed regarding this? Not sure but I think there were discussions regarding adding some sort of "experimental"/"unstable" area in API which would be a fit for quite some parts of core.
I think following the discussion here https://github.com/open-telemetry/opentelemetry-js/issues/3827#issuecomment-1612525131 is a good path forward to merge this feature into the api package.
It looks like #3827 is not being worked on for now, so anyone who wants to pick this up would have to lay the groundwork for adding such an experimental API area (see https://github.com/open-telemetry/opentelemetry-js/issues/3827#issuecomment-1612525131). Having this feature in an experimental API area would be a great step forward while the spec discussion is still pending.
I'll mark this as up for grabs in case someone wants to pick this up.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.
This issue was closed because it has been stale for 14 days with no activity.