Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added support for opentelemetry #83

Conversation

OwenCorrigan76
Copy link
Contributor

Incorporates Opentelemetry alongside OpenTracing to read traces on Producer, Consumer and Streams.

Added OpenTelemetry dependencies as instructed here: [1]

Required Environmental Variables:

TRACING_SYSTEM - String for activating tracing. accepted values are `jaeger`,  `opentelemetry`.

[1] https://github.com/ppatierno/kafka-opentelemetry

Copy link
Member

@kyguy kyguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just one nit!

@kyguy kyguy requested a review from scholzj September 27, 2022 14:36
@@ -34,12 +34,14 @@ public class KafkaConsumerConfig {
private final String oauthTokenEndpointUri;
private final String additionalConfig;
private final String saslLoginCallbackClass = "io.strimzi.kafka.oauth.client.JaasClientOauthLoginCallbackHandler";
private final String tracingSystem;
private static final String DEFAULT_TRACING_SYSTEM = null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings are null by default so you can remove = null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without initialising to null, I'm getting the following error - Variable 'DEFAULT_TRACING_SYSTEM' might not have been initialized

@@ -89,14 +93,14 @@ public static Properties createProperties(KafkaConsumerConfig config) {
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");

if (config.getSslTruststoreCertificates() != null) {
if (config.getSslTruststoreCertificates() != null) {
Copy link

@mimaison mimaison Sep 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If we're removing extra spaces, let's remove them all! Otherwise undo this change.
Same below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undone

Tracer tracer = Configuration.fromEnv().getTracer();
GlobalTracer.registerIfAbsent(tracer);
TracingSystem tracingSystem;
tracingSystem = TracingSystem.forValue(config.getTracingSystem());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge these 2 lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged


props.put(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG, TracingConsumerInterceptor.class.getName());
props.put(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG, io.opentracing.contrib.kafka.TracingConsumerInterceptor.class.getName());
} else if (tracingSystem == KafkaConsumerExample.TracingSystem.OPENTELEMETRY) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to drop the KafkaConsumerExample. prefix here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped without any issues.

@@ -62,4 +87,4 @@ public static void main(String[] args) {
}
log.info("Received {} messages", receivedMsgs);
}
}
}
Copy link

@mimaison mimaison Sep 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can keep the newline. Same in a few other files below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean an extra empty line at the bottom? If so, added.

@@ -95,6 +97,8 @@ spec:
value: const
- name: JAEGER_SAMPLER_PARAM
value: "1"
- name: TRACING_SYSTEM
value: "jaeger"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the quotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quotes removed


props.put(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG, TracingConsumerInterceptor.class.getName());
props.put(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG, io.opentracing.contrib.kafka.TracingConsumerInterceptor.class.getName());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the import and use the short name instead of this.

Copy link
Contributor Author

@OwenCorrigan76 OwenCorrigan76 Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason the import prefix is added here instead of keeping the import is: Jaeger (opentracing) and opentelemetry use the same class name and the only way i could differencieate between the two is to add the import in the lines of code. Is there another way to do this? Thanks. See below:
props.put(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG,io.opentracing.contrib.kafka.TracingConsumerInterceptor.class.getName());
props.put(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG,io.opentelemetry.instrumentation.kafkaclients.TracingConsumerInterceptor.class.getName());

@@ -26,6 +25,21 @@
public class KafkaProducerExample {
private static final Logger log = LogManager.getLogger(KafkaProducerExample.class);

public enum TracingSystem {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating this logic, can we extract it into its own class?

@OwenCorrigan76 OwenCorrigan76 force-pushed the strimzi-client-examples-opentracing-and-opentelemetry branch from c9adda3 to f82401c Compare October 7, 2022 15:47
Signed-off-by: Owen <owencorrigan76@gmail.com>
@OwenCorrigan76 OwenCorrigan76 force-pushed the strimzi-client-examples-opentracing-and-opentelemetry branch from f82401c to c167192 Compare October 7, 2022 15:57
Signed-off-by: Owen <owencorrigan76@gmail.com>
@OwenCorrigan76 OwenCorrigan76 requested review from mimaison, ppatierno, kyguy and scholzj and removed request for mimaison, ppatierno, kyguy and scholzj October 10, 2022 08:46
Signed-off-by: Owen <owencorrigan76@gmail.com>
Signed-off-by: Owen <owencorrigan76@gmail.com>
Signed-off-by: Owen <owencorrigan76@gmail.com>
Signed-off-by: Owen <owencorrigan76@gmail.com>
Signed-off-by: Owen <owencorrigan76@gmail.com>
Copy link
Member

@ppatierno ppatierno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for this work!

Copy link
Member

@scholzj scholzj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pro-tip: If you resolve the addressed comments, the PR will be much more readable.

Signed-off-by: Owen <owencorrigan76@gmail.com>
Copy link
Member

@scholzj scholzj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the PR.

@ppatierno @mimaison Do you need another pass through it? Or can it be merged?

@ppatierno
Copy link
Member

It's fine with me

@scholzj scholzj merged commit 205d594 into strimzi:main Oct 18, 2022
OwenCorrigan76 added a commit to OwenCorrigan76/client-examples that referenced this pull request Jan 30, 2024
* Add OpenTelemetry support

Signed-off-by: Owen <owencorrigan76@gmail.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants