Skip to content

Commit

Permalink
Use OTEL_SERVICE_NAME instead of LS_SERVICE_NAME. (#115)
Browse files Browse the repository at this point in the history
* Use OTEL_SERVICE_NAME instead of LS_SERVICE_NAME.
  • Loading branch information
carlosalberto authored Dec 10, 2021
1 parent 8da5102 commit 667809a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 17 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ as environment variables. [Full list of supported parameters](#system-properties
export LS_ACCESS_TOKEN=your-token

java -javaagent:path/to/lightstep-opentelemetry-javaagent.jar \
-Dls.service.name=your-service-name
-Dotel.service.name=your-service-name
-Dotel.exporter.otlp.traces.endpoint=https://ingest.lightstep.com:443 \
-jar myapp.jar
```
Expand All @@ -30,7 +30,7 @@ java -javaagent:path/to/lightstep-opentelemetry-javaagent.jar \

```shell script
export LS_ACCESS_TOKEN=your-token
export LS_SERVICE_NAME=your-service-name
export OTEL_SERVICE_NAME=your-service-name
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://ingest.lightstep.com:443

java -javaagent:path/to/lightstep-opentelemetry-javaagent.jar \
Expand Down Expand Up @@ -98,7 +98,7 @@ Supported system properties and environmental variables:

| System property | Environment variable | Purpose | Default |
|------------------------------------|------------------------------------|-----------------------------------------------------------------------------------|----------------------|
| ls.service.name | LS_SERVICE_NAME | Service name | |
| otel.service.name | OTEL_SERVICE_NAME | Service name | |
| ls.service.version | LS_SERVICE_VERSION | Service version | |
| ls.access.token | LS_ACCESS_TOKEN | Token for Lightstep access | |
| otel.exporter.otlp.traces.endpoint | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | Satellite URL, should start with _http://_ or _https://_ | https://ingest.lightstep.com:443 |
Expand All @@ -112,6 +112,7 @@ Supported system properties and environmental variables:
|------------------------------------|----------------------------------|
| otel.exporter.otlp.span.insecure | OTEL_EXPORTER_OTLP_SPAN_INSECURE |
| otel.exporter.otlp.span.endpoint | OTEL_EXPORTER_OTLP_SPAN_ENDPOINT |
| ls.service.name | LS_SERVICE_NAME |

## License

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class VariablesConverter {
public static final String DEFAULT_PROPAGATOR = "b3multi";
public static final String DEFAULT_OTEL_LOG_LEVEL = "info";

static final String OTEL_SERVICE_NAME = "OTEL_SERVICE_NAME";
@Deprecated
static final String LS_ACCESS_TOKEN = "LS_ACCESS_TOKEN";
static final String LS_SERVICE_NAME = "LS_SERVICE_NAME";
static final String LS_SERVICE_VERSION = "LS_SERVICE_VERSION";
Expand Down Expand Up @@ -58,7 +60,7 @@ public static void setSystemProperties(Configuration configuration, boolean isAg

if (configuration.serviceName == null || configuration.serviceName.isEmpty()) {
String msg = "Invalid configuration: service name missing. Set environment variable "
+ LS_SERVICE_NAME;
+ OTEL_SERVICE_NAME;
if (isAgent) {
msg += ".";
} else {
Expand Down Expand Up @@ -199,7 +201,8 @@ public static String getAccessToken() {
}

public static String getServiceName() {
return getProperty(LS_SERVICE_NAME, null);
return getProperty(OTEL_SERVICE_NAME,
getProperty(LS_SERVICE_NAME, null));
}

public static String getServiceVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void before() {
System.clearProperty(toSystemProperty(VariablesConverter.LS_ACCESS_TOKEN));
System.clearProperty(toSystemProperty(VariablesConverter.LS_SERVICE_NAME));
System.clearProperty(toSystemProperty(VariablesConverter.LS_SERVICE_VERSION));
System.clearProperty(toSystemProperty(VariablesConverter.OTEL_SERVICE_NAME));
System.clearProperty(toSystemProperty(VariablesConverter.OTEL_LOG_LEVEL));
System.clearProperty(toSystemProperty(VariablesConverter.OTEL_EXPORTER_OTLP_SPAN_ENDPOINT));
System.clearProperty(toSystemProperty(VariablesConverter.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT));
Expand All @@ -37,7 +38,7 @@ public void before() {

@Test
public void convertFromEnv() {
System.setProperty(toSystemProperty(VariablesConverter.LS_SERVICE_NAME), "service-1");
System.setProperty(toSystemProperty(VariablesConverter.OTEL_SERVICE_NAME), "service-1");
System.setProperty(toSystemProperty(VariablesConverter.LS_ACCESS_TOKEN),
StringUtils.repeat("s", 32));
System.setProperty(toSystemProperty(VariablesConverter.LS_SERVICE_VERSION), "1.0");
Expand All @@ -54,7 +55,7 @@ public void convertFromEnv() {

@Test
public void convertFromEnv_withAttributes() {
System.setProperty(toSystemProperty(VariablesConverter.LS_SERVICE_NAME), "service-1");
System.setProperty(toSystemProperty(VariablesConverter.OTEL_SERVICE_NAME), "service-1");
System.setProperty(toSystemProperty(VariablesConverter.LS_ACCESS_TOKEN),
StringUtils.repeat("s", 32));
System.setProperty(toSystemProperty(VariablesConverter.OTEL_RESOURCE_ATTRIBUTES),
Expand All @@ -75,7 +76,7 @@ public void convertFromEnv_withAttributes() {

@Test
public void convertFromEnv_InsecureFalse() {
System.setProperty(toSystemProperty(VariablesConverter.LS_SERVICE_NAME), "service-1");
System.setProperty(toSystemProperty(VariablesConverter.OTEL_SERVICE_NAME), "service-1");
System.setProperty(toSystemProperty(VariablesConverter.LS_ACCESS_TOKEN),
StringUtils.repeat("s", 32));
System.setProperty(toSystemProperty(VariablesConverter.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT),
Expand All @@ -90,7 +91,7 @@ public void convertFromEnv_InsecureFalse() {

@Test
public void convertFromEnv_InsecureTrue() {
System.setProperty(toSystemProperty(VariablesConverter.LS_SERVICE_NAME), "service-1");
System.setProperty(toSystemProperty(VariablesConverter.OTEL_SERVICE_NAME), "service-1");
System.setProperty(toSystemProperty(VariablesConverter.LS_ACCESS_TOKEN),
StringUtils.repeat("s", 32));
System.setProperty(toSystemProperty(VariablesConverter.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT),
Expand Down Expand Up @@ -147,17 +148,23 @@ public void getServiceName_Default() {

@Test
public void getServiceName_fromSystemProperty() {
System.setProperty(toSystemProperty(VariablesConverter.LS_SERVICE_NAME), "service-prop");
System.setProperty(toSystemProperty(VariablesConverter.OTEL_SERVICE_NAME), "service-prop");
assertEquals("service-prop", VariablesConverter.getServiceName());
}

@Test
public void getServiceName_fromEnvVariable() {
mockSystem();
Mockito.when(System.getenv(VariablesConverter.LS_SERVICE_NAME)).thenReturn("service-env");
Mockito.when(System.getenv(VariablesConverter.OTEL_SERVICE_NAME)).thenReturn("service-env");
assertEquals("service-env", VariablesConverter.getServiceName());
}

@Test
public void getServiceName_legacy() {
System.setProperty(toSystemProperty(VariablesConverter.LS_SERVICE_NAME), "service-prop");
assertEquals("service-prop", VariablesConverter.getServiceName());
}

@Test
public void getServiceVersion_Default() {
assertNull(VariablesConverter.getServiceVersion());
Expand Down
4 changes: 2 additions & 2 deletions examples/agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Build and Run
```shell script
export LS_ACCESS_TOKEN=your-token
export LS_SERVICE_NAME=your-service-name
export OTEL_SERVICE_NAME=your-service-name

make buid
make run
Expand Down Expand Up @@ -38,7 +38,7 @@ make run

1. Manually get tracer and create span
```java
Tracer tracer = GlobalOpenTelemetry.getTracer(System.getenv("LS_SERVICE_NAME"));
Tracer tracer = GlobalOpenTelemetry.getTracer(System.getenv("OTEL_SERVICE_NAME"));
Span span = tracer.spanBuilder("name").startSpan();
span.end();
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void nestedMethod() throws Exception {
}

public static void firstMethod() throws Exception {
Tracer tracer = GlobalOpenTelemetry.getTracer(System.getenv("LS_SERVICE_NAME"));
Tracer tracer = GlobalOpenTelemetry.getTracer(System.getenv("OTEL_SERVICE_NAME"));
Span span = tracer.spanBuilder("firstMethod").startSpan();
try (Scope ignored = span.makeCurrent()) {
nestedMethod();
Expand Down
2 changes: 1 addition & 1 deletion examples/launcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Configuration

Update [config.properties](./config.properties) file with correct values for
- _ls.service.name_
- _otel.service.name_
- _ls.access.token_
- _otel.exporter.otlp.traces.endpoint_

Expand Down
2 changes: 1 addition & 1 deletion examples/launcher/config.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ls.service.name=test
otel.service.name=test
ls.access.token=XXXXXX
otel.exporter.otlp.traces.endpoint=https://ingest.lightstep.com:443
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void main(String[] args) throws Exception {
Properties properties = loadConfig();

OpenTelemetry openTelemetry = OpenTelemetryConfiguration.newBuilder()
.setServiceName(properties.getProperty("ls.service.name"))
.setServiceName(properties.getProperty("otel.service.name"))
.setAccessToken(properties.getProperty("ls.access.token"))
.setTracesEndpoint(properties.getProperty("otel.exporter.otlp.traces.endpoint"))
.buildOpenTelemetry();
Expand Down

0 comments on commit 667809a

Please sign in to comment.