opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

Allow libraries to suppress tracing without taking a dependency on core

Open nordfjord opened this issue 1 year ago • 5 comments

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

nordfjord avatar Jul 27 '23 20:07 nordfjord

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.

Flarna avatar Jul 30 '23 19:07 Flarna

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.

legendecas avatar Jul 31 '23 06:07 legendecas

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.

pichlermarc avatar Sep 28 '23 07:09 pichlermarc

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.

github-actions[bot] avatar Dec 04 '23 06:12 github-actions[bot]

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.

github-actions[bot] avatar Feb 12 '24 06:02 github-actions[bot]

This issue was closed because it has been stale for 14 days with no activity.

github-actions[bot] avatar Jul 29 '24 06:07 github-actions[bot]