-
Notifications
You must be signed in to change notification settings - Fork 964
feat(kafka-clients): add messaging.kafka.bootstrap.servers
attribute
#14032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add VirtualFieldStore for managing bootstrap servers storage - Instrument KafkaConsumer and KafkaProducer constructors - Include bootstrap.servers attribute in all relevant spans Addresses part of open-telemetry#14031 open-telemetry#10647
- library instrumentation test
🔧 The result from spotlessApply was committed to the PR branch. |
Hi @laurit , Could you review this PR? Thanks! |
Thanks! It would be nice if the new attribute would be proposed in https://github.com/open-telemetry/semantic-conventions/blob/main/docs/messaging/kafka.md as well...just sayin'. |
...try/instrumentation/kafkaclients/common/v0_11/internal/KafkaProducerAttributesExtractor.java
Outdated
Show resolved
Hide resolved
if (configs instanceof Map) { | ||
Object servers = ((Map<?, ?>) configs).get(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG); | ||
if (servers != null) { | ||
bootstrapServers = servers.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be an obvious question -- but it also speaks to how backends may want to use these bootstrap servers: should we have the attribute type be a list of strings instead of a comma separated string? The comma separated could imply more work over time for some backends, but I have no idea how it's intended on being used/indexed/searched/whatever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I will uniformly convert it from string to list.
Thanks for the suggestion! I will first place this attribute in |
if (servers != null) { | ||
bootstrapServers = servers.toString(); | ||
} | ||
} else if (configs instanceof Properties) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this branch is unreachable, java.util.Properties is a subtype of java.util.Map
VirtualField<Consumer<?, ?>, String> consumerStringVirtualField = | ||
VirtualField.find(Consumer.class, String.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move virtual field access to a helper class (for example KafkaSingletons
) and keep the VirtualField
instance in a static field
@@ -38,6 +43,14 @@ public ElementMatcher<TypeDescription> typeMatcher() { | |||
|
|||
@Override | |||
public void transform(TypeTransformer transformer) { | |||
transformer.applyAdviceToMethod( | |||
isConstructor().and(takesArgument(0, Map.class)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could use isConstructor().and(takesArgument(0, Map.class).or(takesArgument(0, Properties.class)))
to combine the advices
String bootstrapServers = request.getBootstrapServers(); | ||
if (bootstrapServers != null) { | ||
attributes.put(MESSAGING_KAFKA_BOOTSTRAP_SERVERS, bootstrapServers); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default we emit only attributes that are in spec. Either get it added to spec or move to KafkaConsumerExperimentalAttributesExtractor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will create a new KafkaExperimentalAttributesExtractor
to include this attribute. Additionally, I will extract a parent class AbstractKafkaRequest
from xxxRequest
.
bootstrap.servers
through constructor instrumentationbootstrap.servers
through reflection and kafka-clients interceptorsbootstrap servers
storage#14031 #10647