Skip to content

Commit

Permalink
Respect jaeger.service-name property (#57)
Browse files Browse the repository at this point in the history
* Respect jaeger.service-name property

JAEGER_SERVICE_NAME is an environment variable set by e.g. the
jaeger-operator when it injects environment variables into containers.

This change means that Spring apps can use the auto-container inject
feature of the operator and be identified correctly by default.

See https://www.jaegertracing.io/docs/1.13/client-features/

See #56
  • Loading branch information
camelpunch authored and geoand committed Aug 21, 2019
1 parent ed37e7c commit 4af8d85
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public class JaegerConfigurationProperties {

/**
* Service name to be used
* By default it will be the value of the 'spring.application.name' property name
* and if that is not set, it falls back to 'unknown-spring-boot'
* Expect certain properties in order, falling back to 'unknown-spring-boot'.
*/
@Value("${spring.application.name:unknown-spring-boot}")
@Value("${jaeger.service-name:${spring.application.name:unknown-spring-boot}}")
private String serviceName;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"opentracing.jaeger.enabled=true",
"spring.application.name=foo",
"app.env=stage",
"jaeger.service-name=please-override",
"opentracing.jaeger.service-name=${spring.application.name}-${app.env}"
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright 2018-2019 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package io.opentracing.contrib.java.spring.jaeger.starter.basic;

import static org.assertj.core.api.Java6Assertions.assertThat;

import io.opentracing.contrib.java.spring.jaeger.starter.AbstractTracerSpringTest;
import org.junit.Test;
import org.springframework.test.context.TestPropertySource;

@TestPropertySource(
properties = {
"spring.main.banner-mode=off",
"opentracing.jaeger.enabled=true",
"jaeger.service-name=foo",
"spring.application.name=bar"
}
)
public class JaegerTracerServiceNameSetWithoutOpentracingPrefixTest extends AbstractTracerSpringTest {

@Test
public void testNameIsAsExpected() {
assertThat(tracer).isNotNull();
assertThat(tracer).isInstanceOf(io.jaegertracing.internal.JaegerTracer.class);

// 'jaeger.service-name' should take priority over 'spring.application.name'
assertThat((getTracer()).getServiceName()).isEqualTo("foo");
}
}

0 comments on commit 4af8d85

Please sign in to comment.