open-telemetry / open-telemetry/opentelemetry-java-instrumentation

how to get attribute in Sampler?

Open
#6,251 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
2.6k
Forks
1.2k
Avg merge
2d 18h
Merged PRs (30d)
228

Description

I am developing a sampler to drop some traces that I don't need, e.g: redis ping/pong heartbeat connection.
But I found I can't get the attribute I need in Sampler.shouldSample method:

public class XxxSampler implements Sampler {
SamplingResult shouldSample(
      Context parentContext,
      String traceId,
      String name,
      SpanKind spanKind,
      Attributes attributes,
      List<LinkData> parentLinks) {
            System.out.println("attributes.asMap() = " + attributes.asMap());
      }
}

I print all attributes, the output is:

attributes.asMap() = AttributesMap{data={db.system=redis, net.peer.name=localhost, net.transport=ip_tcp, net.peer.ip=127.0.0.1, net.peer.port=6379}, capacity=128, totalAddedValues=5}

there is no db.statement attribute, but there is db.statement attribute in final trace, jaeger snapshot:

image

I can't drop redis ping operation trace without db.statement attribute.

how can I get the missing attribute?any suggestion?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Sampler.shouldSample entry point and compare the Attributes available there with the later final trace shown in Jaeger. Determine when db.statement is added for the Redis ping operation and whether it is expected to be available during sampling; document the supported way to make that decision, or identify the instrumentation change needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis
Domain
databases, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.