Skip to content

Commit adf85eb

Browse files
committed
ref(kafka): [Queue Instrumentation 20] Log Kafka instrumentation failures
Previously `SentryKafkaProducerInterceptor.onSend(...)` and `SentryKafkaConsumerTracing` silently swallowed any `Throwable` thrown while instrumenting a Kafka record. That protects customer Kafka I/O from breakage, but makes instrumentation bugs invisible. Log each caught `Throwable` to the SDK logger at `SentryLevel.ERROR` (matching the existing pattern in `RequestPayloadExtractor`) before continuing the fail-open path: - `SentryKafkaProducerInterceptor`: producer span creation / header injection - `SentryKafkaConsumerTracing`: scope fork + `makeCurrent`, transaction start, transaction finish No behavior change for customer callbacks or Kafka send/receive: the catches still swallow the throwable, they now just surface it via the SDK's own logger. `SentryKafkaRecordInterceptor` (Spring) was reviewed and intentionally left as-is — it does not wrap its instrumentation in `catch (Throwable)` blocks, so there is nothing silent to log. The `NumberFormatException` branches on malformed `sentry-task-enqueued-time` headers are expected input, not instrumentation faults, and remain silent.
1 parent 118d244 commit adf85eb

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

sentry-kafka/src/main/java/io/sentry/kafka/SentryKafkaConsumerTracing.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.sentry.ISentryLifecycleToken;
77
import io.sentry.ITransaction;
88
import io.sentry.ScopesAdapter;
9+
import io.sentry.SentryLevel;
910
import io.sentry.SentryTraceHeader;
1011
import io.sentry.SpanDataConvention;
1112
import io.sentry.SpanStatus;
@@ -83,7 +84,11 @@ <K, V, U> U withTracingImpl(
8384
try {
8485
forkedScopes = scopes.forkedRootScopes(CREATOR);
8586
lifecycleToken = forkedScopes.makeCurrent();
86-
} catch (Throwable ignored) {
87+
} catch (Throwable t) {
88+
scopes
89+
.getOptions()
90+
.getLogger()
91+
.log(SentryLevel.ERROR, "Failed to fork scopes for Kafka consumer tracing.", t);
8792
return callable.call();
8893
}
8994

@@ -175,7 +180,11 @@ private boolean isIgnored() {
175180
}
176181

177182
return transaction;
178-
} catch (Throwable ignored) {
183+
} catch (Throwable t) {
184+
scopes
185+
.getOptions()
186+
.getLogger()
187+
.log(SentryLevel.ERROR, "Failed to start Kafka consumer tracing transaction.", t);
179188
return null;
180189
}
181190
}
@@ -194,8 +203,12 @@ private void finishTransaction(
194203
transaction.setThrowable(throwable);
195204
}
196205
transaction.finish();
197-
} catch (Throwable ignored) {
206+
} catch (Throwable t) {
198207
// Instrumentation must never break customer processing.
208+
scopes
209+
.getOptions()
210+
.getLogger()
211+
.log(SentryLevel.ERROR, "Failed to finish Kafka consumer tracing transaction.", t);
199212
}
200213
}
201214

sentry-kafka/src/main/java/io/sentry/kafka/SentryKafkaProducerInterceptor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.sentry.IScopes;
66
import io.sentry.ISpan;
77
import io.sentry.ScopesAdapter;
8+
import io.sentry.SentryLevel;
89
import io.sentry.SentryTraceHeader;
910
import io.sentry.SpanDataConvention;
1011
import io.sentry.SpanOptions;
@@ -71,8 +72,11 @@ public SentryKafkaProducerInterceptor(
7172

7273
span.setStatus(SpanStatus.OK);
7374
span.finish();
74-
} catch (Throwable ignored) {
75-
// Instrumentation must never break the customer's Kafka send.
75+
} catch (Throwable t) {
76+
scopes
77+
.getOptions()
78+
.getLogger()
79+
.log(SentryLevel.ERROR, "Failed to instrument Kafka producer record.", t);
7680
}
7781

7882
return record;

0 commit comments

Comments
 (0)