open-telemetry / open-telemetry/opentelemetry-java-instrumentation
how to get attribute in Sampler?
Nobody has claimed this yet.
- 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:
I can't drop redis ping operation trace without db.statement attribute.
how can I get the missing attribute?any suggestion?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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