From 029b69a86c1b14e026b3e5548748bf08ad2fed4e Mon Sep 17 00:00:00 2001 From: Karen Jureidini Date: Wed, 3 May 2023 10:46:27 -0600 Subject: [PATCH 1/5] Added resources as runtimeOnly dependency --- .gitignore | 1 + build.gradle | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 58c7e7c..d6a50a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .gradle/ build/ .env +.idea/ diff --git a/build.gradle b/build.gradle index 562d982..50b2c44 100644 --- a/build.gradle +++ b/build.gradle @@ -40,6 +40,7 @@ dependencies { implementation "io.opentelemetry:opentelemetry-exporter-otlp-logs:$otelVersion-alpha" implementation "io.opentelemetry:opentelemetry-exporter-logging" // only for debug runtimeOnly("io.opentelemetry.instrumentation:opentelemetry-logback-appender-1.0:$otelVersion-alpha") + runtimeOnly "io.opentelemetry.instrumentation:opentelemetry-resources:$otelVersion-alpha" implementation "io.opentelemetry.instrumentation:opentelemetry-micrometer-1.5:$otelVersion-alpha" implementation "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:$otelVersion-alpha" runtimeOnly 'io.micrometer:micrometer-tracing-bridge-otel' From 055d0560d324d5a1eee0cc49c77adf684f5be76c Mon Sep 17 00:00:00 2001 From: Karen Jureidini Date: Wed, 3 May 2023 21:27:59 -0600 Subject: [PATCH 2/5] Updated getEndpoint logging since default onprem endpoints are possible --- .../opentelemetry/OpenTelemetryConfig.java | 6 ++++-- .../OpenTelemetryConfigTest.java | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java b/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java index 270f928..72f5f45 100644 --- a/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java +++ b/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java @@ -117,13 +117,15 @@ static Optional getEndpoint(String endpoint, String zone, Optional basicAuthCases() { @ParameterizedTest(name = "{0}") @MethodSource("endpointCases") - void getEndpoint(String name, Optional expected, String expectedOutput, - String zone, String endpoint, Optional authHeader, CapturedOutput output) { + void getEndpoint(String name, + Optional expected, + String expectedOutput, + String zone, + String endpoint, + Optional authHeader, + CapturedOutput output) { Assertions.assertThat(OpenTelemetryConfig.getEndpoint(endpoint, zone, authHeader)).isEqualTo(expected); Assertions.assertThat(output).contains(expectedOutput); } @@ -85,24 +90,24 @@ private static Stream endpointCases() { Arguments.of("only zone", Optional.of("https://otlp-gateway-zone.grafana.net/otlp"), "", "zone", "", Optional.of("apiKey")), - Arguments.of("only endpoint", + Arguments.of("only onprem endpoint", Optional.of("endpoint"), "", "", "endpoint", Optional.empty()), Arguments.of("both with cloud", Optional.of("https://otlp-gateway-zone.grafana.net/otlp"), "ignoring grafana.otlp.onprem.endpoint, because grafana.otlp.cloud.instanceId was found", "zone", "endpoint", Optional.of("key")), - Arguments.of("both without cloud", + Arguments.of("zone without instanceId", Optional.of("endpoint"), - "ignoring grafana.otlp.cloud.zone, because grafana.otlp.onprem.endpoint was found", + "ignoring grafana.otlp.cloud.zone, because grafana.otlp.cloud.instanceId was not found", "zone", "endpoint", Optional.empty()), Arguments.of("missing zone", Optional.empty(), "please specify grafana.otlp.cloud.zone", " ", " ", Optional.of("key")), - Arguments.of("missing endpoint", + Arguments.of("onprem endpoint not set", Optional.empty(), - "please specify grafana.otlp.onprem.endpoint", + "grafana.otlp.onprem.endpoint not found, using default enpoint for otel.exporter.otlp.protocol", " ", " ", Optional.empty()) ); } From 6853fdc3f1fd30e77c68457795c641a6bdd16a46 Mon Sep 17 00:00:00 2001 From: Karen Jureidini Date: Thu, 4 May 2023 18:16:26 -0600 Subject: [PATCH 3/5] Add instrumentation resources - Updated method call for hostname to match call in Otel's HostResource - Fixed typo in log message --- .../opentelemetry/OpenTelemetryConfig.java | 18 +++++++++++++----- .../opentelemetry/OpenTelemetryConfigTest.java | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java b/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java index 72f5f45..37471b9 100644 --- a/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java +++ b/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java @@ -16,6 +16,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Base64; import java.util.HashMap; import java.util.Map; @@ -122,7 +124,7 @@ static Optional getEndpoint(String endpoint, String zone, Optional String.format("%s=%s", e.getKey(), e.getValue())) diff --git a/src/test/java/com/grafana/opentelemetry/OpenTelemetryConfigTest.java b/src/test/java/com/grafana/opentelemetry/OpenTelemetryConfigTest.java index 15d49d9..1955008 100644 --- a/src/test/java/com/grafana/opentelemetry/OpenTelemetryConfigTest.java +++ b/src/test/java/com/grafana/opentelemetry/OpenTelemetryConfigTest.java @@ -107,7 +107,7 @@ private static Stream endpointCases() { " ", " ", Optional.of("key")), Arguments.of("onprem endpoint not set", Optional.empty(), - "grafana.otlp.onprem.endpoint not found, using default enpoint for otel.exporter.otlp.protocol", + "grafana.otlp.onprem.endpoint not found, using default endpoint for otel.exporter.otlp.protocol", " ", " ", Optional.empty()) ); } From 463c7ef8b53ef44c8df3d18331d4bf4e39b82568 Mon Sep 17 00:00:00 2001 From: Karen Jureidini Date: Thu, 4 May 2023 21:17:41 -0600 Subject: [PATCH 4/5] Updated comments for globalAttributes prop --- .../opentelemetry/GrafanaProperties.java | 31 +++++++++++++------ .../opentelemetry/OpenTelemetryConfig.java | 2 -- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/grafana/opentelemetry/GrafanaProperties.java b/src/main/java/com/grafana/opentelemetry/GrafanaProperties.java index caae9f8..0865162 100644 --- a/src/main/java/com/grafana/opentelemetry/GrafanaProperties.java +++ b/src/main/java/com/grafana/opentelemetry/GrafanaProperties.java @@ -17,25 +17,38 @@ public class GrafanaProperties { *

* For example, you can add service.version to make it easier to see if a new version of the * application is causing a problem. + * *

* The attributes service.name, service.version, and service.instance.id - * are automatically detected as explained below, but if you set the value manually, it will be respected. + * are automatically detected as outlined below. + * *

- * "spring.application.name" in application.properties will be translated to service.name. - *

- * You can also add the application name and version to MANIFEST.MF, where they will be copied to - * service.name and service.version respectively. - *

- * In gradle, the application name and version can be set as follows: + * For service.name the order of precedence is: + *

    + *
  1. environment variable OTEL_SERVICE_NAME
  2. + *
  3. Manually set service_name in grafana.otlp.globalAttributes
  4. + *
  5. spring.application.name" in application.properties
  6. + *
  7. 'Implementation-Title' in jar's MANIFEST.MF
  8. + *
+ * + *

+ * The following block can be added to build.gradle to set the application name and version + * in the jar's MANIFEST.MF: *

      * bootJar {
      *     manifest {
      *         attributes('Implementation-Title':   'Demo Application',
-     *                    'Implementation-Version': version)
+     *                    'Implementation-Version':  version)
      *     }
      * }
      * 
- * The environment variables HOST or HOSTNAME will be translated to service.instance.id. + * The service.instance.id attribute will be set if any of the following return a value. + * The list is in order of precedence. + *
    + *
  1. InetAddress.getLocalHost().getHostName()
  2. + *
  3. environment variable HOSTNAME
  4. + *
  5. environment variable HOST
  6. + *
*/ private final Map globalAttributes = new HashMap<>(); diff --git a/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java b/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java index 37471b9..48e6e8d 100644 --- a/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java +++ b/src/main/java/com/grafana/opentelemetry/OpenTelemetryConfig.java @@ -126,8 +126,6 @@ static Optional getEndpoint(String endpoint, String zone, Optional Date: Fri, 5 May 2023 09:02:31 -0600 Subject: [PATCH 5/5] Update src/main/java/com/grafana/opentelemetry/GrafanaProperties.java Co-authored-by: Gregor Zeitlinger --- src/main/java/com/grafana/opentelemetry/GrafanaProperties.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/grafana/opentelemetry/GrafanaProperties.java b/src/main/java/com/grafana/opentelemetry/GrafanaProperties.java index 0865162..b1f62b4 100644 --- a/src/main/java/com/grafana/opentelemetry/GrafanaProperties.java +++ b/src/main/java/com/grafana/opentelemetry/GrafanaProperties.java @@ -26,6 +26,7 @@ public class GrafanaProperties { * For service.name the order of precedence is: *
    *
  1. environment variable OTEL_SERVICE_NAME
  2. + *
  3. environment variable OTEL_RESOURCE_ATTRIBUTES
  4. *
  5. Manually set service_name in grafana.otlp.globalAttributes
  6. *
  7. spring.application.name" in application.properties
  8. *
  9. 'Implementation-Title' in jar's MANIFEST.MF