Allow enabling receive telemetry in kafka library instrumentation (#9693)

This commit is contained in:
Lauri Tulmin 2023-10-17 16:47:11 +03:00 committed by GitHub
parent 48d3956bd8
commit e7db2c0246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -30,6 +30,7 @@ public final class KafkaTelemetryBuilder {
private List<String> capturedHeaders = emptyList();
private boolean captureExperimentalSpanAttributes = false;
private boolean propagationEnabled = true;
private boolean messagingReceiveInstrumentationEnabled = false;
KafkaTelemetryBuilder(OpenTelemetry openTelemetry) {
this.openTelemetry = Objects.requireNonNull(openTelemetry);
@ -85,11 +86,25 @@ public final class KafkaTelemetryBuilder {
return this;
}
/**
* Set whether to capture the consumer message receive telemetry in messaging instrumentation.
*
* <p>Note that this will cause the consumer side to start a new trace, with only a span link
* connecting it to the producer trace.
*/
@CanIgnoreReturnValue
public KafkaTelemetryBuilder setMessagingReceiveInstrumentationEnabled(
boolean messagingReceiveInstrumentationEnabled) {
this.messagingReceiveInstrumentationEnabled = messagingReceiveInstrumentationEnabled;
return this;
}
public KafkaTelemetry build() {
KafkaInstrumenterFactory instrumenterFactory =
new KafkaInstrumenterFactory(openTelemetry, INSTRUMENTATION_NAME)
.setCapturedHeaders(capturedHeaders)
.setCaptureExperimentalSpanAttributes(captureExperimentalSpanAttributes);
.setCaptureExperimentalSpanAttributes(captureExperimentalSpanAttributes)
.setMessagingReceiveInstrumentationEnabled(messagingReceiveInstrumentationEnabled);
return new KafkaTelemetry(
openTelemetry,

View File

@ -50,6 +50,12 @@ public final class SpringKafkaTelemetryBuilder {
return this;
}
/**
* Set whether to capture the consumer message receive telemetry in messaging instrumentation.
*
* <p>Note that this will cause the consumer side to start a new trace, with only a span link
* connecting it to the producer trace.
*/
@CanIgnoreReturnValue
public SpringKafkaTelemetryBuilder setMessagingReceiveInstrumentationEnabled(
boolean messagingReceiveInstrumentationEnabled) {