how to get attribute in Sampler?
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?
Hey @kelystor ,
What version of lettuce are you using?
The instrumentation that adds the span (lettuce-5.1) actually sets the attribute when the span ends; I think that this behavior could be improved for at least some versions (>=6.0, with the new start(RedisCommand) method)
I'm using lettuce 5.3.1.RELEASE. I have tried to upgrade to 6.1.8.RELEASE, but the result is same, there is no db.statement attribute neither.
I replace lettuce with redisson, and there is db.operation/db.statement attribute:
attributes.asMap() = AttributesMap{data={db.operation=PING, db.statement=PING, db.system=redis}, capacity=128, totalAddedValues=3}
but there are no net.peer.ip、net.peer.port attributes in Sampler.
the attributes in Sampler is different from final trace
I replace lettuce with redisson, and there is
db.operation/db.statementattribute:attributes.asMap() = AttributesMap{data={db.operation=PING, db.statement=PING, db.system=redis}, capacity=128, totalAddedValues=3}but there are no
net.peer.ip、net.peer.portattributes in Sampler.
Yeah, unlike Lettuce Redisson does not expose the information needed to populate the net.peer.* attributes.
I'm using lettuce 5.3.1.RELEASE. I have tried to upgrade to 6.1.8.RELEASE, but the result is same, there is no
db.statementattribute neither.
I think this could actually be fixed for 6.x: current instrumentation first starts the span, and later sets the statement (well, captures it): https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/82118868bfcebb24856e14ad88692d461643b1a1/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java#L220-L230
This could be changed so that the db.statement is set before the span is started.
I replace lettuce with redisson, and there is
db.operation/db.statementattribute:attributes.asMap() = AttributesMap{data={db.operation=PING, db.statement=PING, db.system=redis}, capacity=128, totalAddedValues=3}but there are no
net.peer.ip、net.peer.portattributes in Sampler.Yeah, unlike Lettuce Redisson does not expose the information needed to populate the
net.peer.*attributes.I'm using lettuce 5.3.1.RELEASE. I have tried to upgrade to 6.1.8.RELEASE, but the result is same, there is no
db.statementattribute neither.I think this could actually be fixed for 6.x: current instrumentation first starts the span, and later sets the statement (well, captures it):
https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/82118868bfcebb24856e14ad88692d461643b1a1/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java#L220-L230
This could be changed so that the
db.statementis set before the span is started.
@mateuszrzeszutek At present, I also encounter the same problem when using agent2.4.0. I want to get db.statement condition filter span in Sampler. Is there any good processing method for me to get it
Since there has been no activity on this enhancement for the past year we are closing it to help maintain our backlog. Anyone who would like to work on it is still welcome to do so, and we can re-open it at that time.