diff --git a/jaeger-core/src/main/java/io/jaegertracing/Configuration.java b/jaeger-core/src/main/java/io/jaegertracing/Configuration.java index c4a6933d9..70c83abad 100644 --- a/jaeger-core/src/main/java/io/jaegertracing/Configuration.java +++ b/jaeger-core/src/main/java/io/jaegertracing/Configuration.java @@ -631,12 +631,10 @@ public SenderConfiguration withAuthPassword(String password) { * @return the sender passed via the constructor or a properly configured sender */ public Sender getSender() { - // if we have a sender, that's the one we return - if (null != sender) { - return sender; + if (sender == null) { + sender = SenderResolver.resolve(this); } - - return SenderResolver.resolve(this); + return sender; } /** diff --git a/jaeger-core/src/test/java/io/jaegertracing/ConfigurationTest.java b/jaeger-core/src/test/java/io/jaegertracing/ConfigurationTest.java index c2472de62..1b7db3572 100644 --- a/jaeger-core/src/test/java/io/jaegertracing/ConfigurationTest.java +++ b/jaeger-core/src/test/java/io/jaegertracing/ConfigurationTest.java @@ -23,6 +23,7 @@ import io.jaegertracing.Configuration.CodecConfiguration; import io.jaegertracing.Configuration.ReporterConfiguration; import io.jaegertracing.Configuration.SamplerConfiguration; +import io.jaegertracing.Configuration.SenderConfiguration; import io.jaegertracing.internal.JaegerSpanContext; import io.jaegertracing.internal.JaegerTracer; import io.jaegertracing.internal.metrics.InMemoryMetricsFactory; @@ -183,6 +184,12 @@ public void testSenderBackwardsCompatibilityGettingAgentHostAndPort() { .getSenderConfiguration().getAgentPort()); } + @Test + public void testSenderInstanceIsCached() { + SenderConfiguration senderConfiguration = SenderConfiguration.fromEnv(); + assertEquals(senderConfiguration.getSender(), senderConfiguration.getSender()); + } + @Test public void testPropagationB3Only() { System.setProperty(Configuration.JAEGER_PROPAGATION, "b3");