From 667809ab5bd71fda14a4cf02af3f71cfed740d6f Mon Sep 17 00:00:00 2001 From: Carlos Alberto Cortez Date: Sat, 11 Dec 2021 00:34:40 +0100 Subject: [PATCH] Use OTEL_SERVICE_NAME instead of LS_SERVICE_NAME. (#115) * Use OTEL_SERVICE_NAME instead of LS_SERVICE_NAME. --- README.md | 7 ++++--- .../common/VariablesConverter.java | 7 +++++-- .../common/VariablesConverterTest.java | 19 +++++++++++++------ examples/agent/README.md | 4 ++-- .../opentelemetry/launcher/example/App.java | 2 +- examples/launcher/README.md | 2 +- examples/launcher/config.properties | 2 +- .../opentelemetry/launcher/example/Main.java | 2 +- 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index cf9f26e..de9c44d 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 \ @@ -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 | @@ -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 diff --git a/common/src/main/java/com/lightstep/opentelemetry/common/VariablesConverter.java b/common/src/main/java/com/lightstep/opentelemetry/common/VariablesConverter.java index 8a24139..7e075d2 100644 --- a/common/src/main/java/com/lightstep/opentelemetry/common/VariablesConverter.java +++ b/common/src/main/java/com/lightstep/opentelemetry/common/VariablesConverter.java @@ -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"; @@ -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 { @@ -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() { diff --git a/common/src/test/java/com/lightstep/opentelemetry/common/VariablesConverterTest.java b/common/src/test/java/com/lightstep/opentelemetry/common/VariablesConverterTest.java index 444719a..cdb3487 100644 --- a/common/src/test/java/com/lightstep/opentelemetry/common/VariablesConverterTest.java +++ b/common/src/test/java/com/lightstep/opentelemetry/common/VariablesConverterTest.java @@ -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)); @@ -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"); @@ -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), @@ -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), @@ -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), @@ -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()); diff --git a/examples/agent/README.md b/examples/agent/README.md index 74df651..033275d 100644 --- a/examples/agent/README.md +++ b/examples/agent/README.md @@ -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 @@ -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(); ``` diff --git a/examples/agent/src/main/java/com/lightstep/opentelemetry/launcher/example/App.java b/examples/agent/src/main/java/com/lightstep/opentelemetry/launcher/example/App.java index 5cb7a7b..40c50d8 100644 --- a/examples/agent/src/main/java/com/lightstep/opentelemetry/launcher/example/App.java +++ b/examples/agent/src/main/java/com/lightstep/opentelemetry/launcher/example/App.java @@ -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(); diff --git a/examples/launcher/README.md b/examples/launcher/README.md index 651c6ef..bed7b02 100644 --- a/examples/launcher/README.md +++ b/examples/launcher/README.md @@ -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_ diff --git a/examples/launcher/config.properties b/examples/launcher/config.properties index 5efd1e0..bda3295 100644 --- a/examples/launcher/config.properties +++ b/examples/launcher/config.properties @@ -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 diff --git a/examples/launcher/src/main/java/com/lightstep/opentelemetry/launcher/example/Main.java b/examples/launcher/src/main/java/com/lightstep/opentelemetry/launcher/example/Main.java index f18d4f5..72f8d72 100644 --- a/examples/launcher/src/main/java/com/lightstep/opentelemetry/launcher/example/Main.java +++ b/examples/launcher/src/main/java/com/lightstep/opentelemetry/launcher/example/Main.java @@ -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();