diff --git a/jaeger-core/src/main/java/io/jaegertracing/Configuration.java b/jaeger-core/src/main/java/io/jaegertracing/Configuration.java index 83ddc574..be29ced0 100644 --- a/jaeger-core/src/main/java/io/jaegertracing/Configuration.java +++ b/jaeger-core/src/main/java/io/jaegertracing/Configuration.java @@ -111,6 +111,12 @@ public class Configuration { */ public static final String JAEGER_REPORTER_FLUSH_INTERVAL = JAEGER_PREFIX + "REPORTER_FLUSH_INTERVAL"; + /** + * Whether the reporter should ignore sender errors. + */ + public static final String JAEGER_REPORTER_IGNORE_SENDER_ERRORS = JAEGER_PREFIX + "REPORTER_IGNORE_SENDER_ERRORS"; + + /** * The sampler type. */ @@ -552,6 +558,7 @@ protected void registerBinaryCodec(JaegerTracer.Builder builder, Format public static class ReporterConfiguration { private Boolean logSpans; + private Boolean ignoreSenderErrors; private Integer flushIntervalMs; private Integer maxQueueSize; private SenderConfiguration senderConfiguration = new SenderConfiguration(); @@ -564,6 +571,7 @@ public static ReporterConfiguration fromEnv() { .withLogSpans(getPropertyAsBool(JAEGER_REPORTER_LOG_SPANS)) .withFlushInterval(getPropertyAsInt(JAEGER_REPORTER_FLUSH_INTERVAL)) .withMaxQueueSize(getPropertyAsInt(JAEGER_REPORTER_MAX_QUEUE_SIZE)) + .withIgnoreSenderErrors(getPropertyAsBool(JAEGER_REPORTER_IGNORE_SENDER_ERRORS)) .withSender(SenderConfiguration.fromEnv()); } @@ -572,6 +580,11 @@ public ReporterConfiguration withLogSpans(Boolean logSpans) { return this; } + public ReporterConfiguration withIgnoreSenderErrors(Boolean ignoreSenderErrors) { + this.ignoreSenderErrors = ignoreSenderErrors; + return this; + } + public ReporterConfiguration withFlushInterval(Integer flushIntervalMs) { this.flushIntervalMs = flushIntervalMs; return this; @@ -593,6 +606,8 @@ private Reporter getReporter(Metrics metrics) { .withSender(senderConfiguration.getSender()) .withFlushInterval(numberOrDefault(this.flushIntervalMs, RemoteReporter.DEFAULT_FLUSH_INTERVAL_MS).intValue()) .withMaxQueueSize(numberOrDefault(this.maxQueueSize, RemoteReporter.DEFAULT_MAX_QUEUE_SIZE).intValue()) + .withIgnoreSenderErrors( + booleanOrDefault(this.ignoreSenderErrors, RemoteReporter.DEFAULT_IGNORE_SENDER_ERRORS)) .build(); if (Boolean.TRUE.equals(this.logSpans)) { @@ -727,6 +742,10 @@ private static Number numberOrDefault(Number value, Number defaultValue) { return value != null ? value : defaultValue; } + private static Boolean booleanOrDefault(Boolean value, Boolean defaultValue) { + return value != null ? value : defaultValue; + } + private static String getProperty(String name) { return System.getProperty(name, System.getenv(name)); } diff --git a/jaeger-core/src/main/java/io/jaegertracing/internal/reporters/RemoteReporter.java b/jaeger-core/src/main/java/io/jaegertracing/internal/reporters/RemoteReporter.java index 8f644df9..cf1d8ef5 100644 --- a/jaeger-core/src/main/java/io/jaegertracing/internal/reporters/RemoteReporter.java +++ b/jaeger-core/src/main/java/io/jaegertracing/internal/reporters/RemoteReporter.java @@ -41,6 +41,7 @@ public class RemoteReporter implements Reporter { public static final int DEFAULT_FLUSH_INTERVAL_MS = 1000; public static final int DEFAULT_MAX_QUEUE_SIZE = 100; + public static final Boolean DEFAULT_IGNORE_SENDER_ERRORS = Boolean.FALSE; private final Sender sender; private final int closeEnqueueTimeout; @@ -50,11 +51,13 @@ public class RemoteReporter implements Reporter { @ToString.Exclude private final Thread queueProcessorThread; @ToString.Exclude private final QueueProcessor queueProcessor; @ToString.Exclude private final Metrics metrics; + @ToString.Exclude private final boolean ignoreSenderErrors; private RemoteReporter(Sender sender, int flushInterval, int maxQueueSize, int closeEnqueueTimeout, - Metrics metrics) { + Metrics metrics, boolean ignoreSenderErrors) { this.sender = sender; this.metrics = metrics; + this.ignoreSenderErrors = ignoreSenderErrors; this.closeEnqueueTimeout = closeEnqueueTimeout; commandQueue = new ArrayBlockingQueue(maxQueueSize); @@ -187,8 +190,13 @@ public void run() { } catch (SenderException e) { metrics.reporterFailure.inc(e.getDroppedSpanCount()); if (!failedBefore) { - log.warn(commandClass.getSimpleName() - + " execution failed! Repeated errors of this command will not be logged.", e); + if (ignoreSenderErrors) { + log.debug(commandClass.getSimpleName() + + " execution failed! Repeated errors of this command will not be logged.", e); + } else { + log.warn(commandClass.getSimpleName() + + " execution failed! Repeated errors of this command will not be logged.", e); + } commandFailedBefore.add(commandClass); } } @@ -209,6 +217,7 @@ public static class Builder { private int flushInterval = DEFAULT_FLUSH_INTERVAL_MS; private int maxQueueSize = DEFAULT_MAX_QUEUE_SIZE; private int closeEnqueTimeout = DEFAULT_CLOSE_ENQUEUE_TIMEOUT_MILLIS; + private boolean ignoreSenderErrors = DEFAULT_IGNORE_SENDER_ERRORS; private Metrics metrics; public Builder withFlushInterval(int flushInterval) { @@ -236,6 +245,11 @@ public Builder withCloseEnqueueTimeout(int closeEnqueueTimeoutMs) { return this; } + public Builder withIgnoreSenderErrors(Boolean ignoreSenderErrors) { + this.ignoreSenderErrors = ignoreSenderErrors; + return this; + } + public RemoteReporter build() { if (sender == null) { sender = SenderResolver.resolve(); @@ -243,7 +257,8 @@ public RemoteReporter build() { if (metrics == null) { metrics = new Metrics(new InMemoryMetricsFactory()); } - return new RemoteReporter(sender, flushInterval, maxQueueSize, closeEnqueTimeout, metrics); + return new RemoteReporter(sender, flushInterval, maxQueueSize, closeEnqueTimeout, metrics, ignoreSenderErrors); } + } }