Skip to content

Suppressing Auto Instrumentation Conditionally #6887

Answered by trask
hcelaloner asked this question in Q&A
Discussion options

You must be logged in to vote

check out open-telemetry/opentelemetry-specification#530

as a short-term solution, if you are using (the default) parent-based sampler, I think you can do

public List<Price> getPricesByIds(List<String> ids) {
  SpanContext current = Span.current().getSpanContext();
  SpanContext suppressing = SpanContext.create(current.getTraceId(), current.getSpanId(), TraceFlags.getDefault(), current.getTraceState());
  try (Scope scope = Span.wrap(suppressing).makeCurrent()) {
    return ids.stream().map(priceRepository::getByID).collect(Collectors.toList());
  }
}

the key above is TraceFlags.getDefault() is non-recording (compared to TraceFlags.getSampled()

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hcelaloner
Comment options

Answer selected by hcelaloner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants