-
Notifications
You must be signed in to change notification settings - Fork 938
Add property to allow autoconfiguration of SDK telemetry version #8037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.exporter.otlp.internal; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; | ||
| import io.opentelemetry.sdk.common.InternalTelemetryVersion; | ||
| import java.util.Locale; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Reads the desired SDK internal telemetry version from {@link ConfigProperties}. | ||
| * | ||
| * <p>This is the same as {@code io.opentelemetry.sdk.autoconfigure.InternalTelemetryConfiguration}. | ||
| * Any changes should be reflected there as well. | ||
| */ | ||
| final class InternalTelemetryConfiguration { | ||
|
|
||
| @Nullable | ||
| static InternalTelemetryVersion getVersion(ConfigProperties config) { | ||
| String version = config.getString("otel.experimental.sdk.telemetry.version"); | ||
| if (version == null) { | ||
| return null; | ||
| } | ||
| switch (version.toLowerCase(Locale.ROOT)) { | ||
| case "legacy": | ||
| return InternalTelemetryVersion.LEGACY; | ||
| case "latest": | ||
| return InternalTelemetryVersion.LATEST; | ||
| default: | ||
| throw new ConfigurationException("Invalid sdk telemetry version: " + version); | ||
| } | ||
| } | ||
|
|
||
| private InternalTelemetryConfiguration() {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.autoconfigure; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; | ||
| import io.opentelemetry.sdk.common.InternalTelemetryVersion; | ||
| import java.util.Locale; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Reads the desired SDK internal telemetry version from {@link ConfigProperties}. | ||
| * | ||
| * <p>This is the same as {@code | ||
| * io.opentelemetry.exporter.otlp.internal.InternalTelemetryConfiguration}. Any changes should be | ||
| * reflected there as well. | ||
| */ | ||
| final class InternalTelemetryConfiguration { | ||
|
|
||
| @Nullable | ||
| static InternalTelemetryVersion getVersion(ConfigProperties config) { | ||
| String version = config.getString("otel.experimental.sdk.telemetry.version"); | ||
| if (version == null) { | ||
| return null; | ||
| } | ||
| switch (version.toLowerCase(Locale.ROOT)) { | ||
| case "legacy": | ||
| return InternalTelemetryVersion.LEGACY; | ||
| case "latest": | ||
| return InternalTelemetryVersion.LATEST; | ||
| default: | ||
| throw new ConfigurationException("Invalid sdk telemetry version: " + version); | ||
| } | ||
| } | ||
|
|
||
| private InternalTelemetryConfiguration() {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,13 +35,15 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import io.opentelemetry.proto.common.v1.AnyValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import io.opentelemetry.proto.common.v1.KeyValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import io.opentelemetry.proto.metrics.v1.Metric; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import io.opentelemetry.proto.metrics.v1.ScopeMetrics; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import io.opentelemetry.sdk.OpenTelemetrySdk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.ArrayList; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Collection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.concurrent.BlockingQueue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.concurrent.LinkedBlockingDeque; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.concurrent.TimeUnit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.stream.Collectors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.AfterEach; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.BeforeEach; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -220,6 +222,8 @@ void configures() throws Exception { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertHasKeyValue(span.getAttributesList(), "cat", "meow"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertHasKeyValue(span.getAttributesList(), "extra-key", "extra-value"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Flush again to get metric exporter metrics. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| openTelemetrySdk.getSdkMeterProvider().forceFlush().join(10, TimeUnit.SECONDS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // await on assertions since metrics may come in different order for BatchSpanProcessor, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // exporter, or the ones we created in the test. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -252,19 +256,62 @@ void configures() throws Exception { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This verifies that AutoConfigureListener was invoked and the OTLP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // span / log exporters received the autoconfigured OpenTelemetrySdk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // instance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // instance as well as setting telemetry version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .anySatisfy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(scopeMetrics.getScope().getName()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .isEqualTo("io.opentelemetry.exporters.otlp-grpc"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(scopeMetrics.getMetricsList()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .satisfiesExactlyInAnyOrder( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metric -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(metric.getName()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .isEqualTo("otlp.exporter.seen"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metric -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(metric.getName()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .isEqualTo("otlp.exporter.exported")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .isEqualTo( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "io.opentelemetry.exporters.otlp_grpc_metric_exporter"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertMetricNames( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.exporter.metric_data_point.inflight", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.exporter.operation.duration", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.exporter.metric_data_point.exported"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .anySatisfy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(scopeMetrics.getScope().getName()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .isEqualTo( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "io.opentelemetry.exporters.otlp_grpc_log_exporter"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertMetricNames( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.exporter.log.inflight", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.exporter.operation.duration", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.exporter.log.exported"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .anySatisfy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(scopeMetrics.getScope().getName()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .isEqualTo( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "io.opentelemetry.exporters.otlp_grpc_span_exporter"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertMetricNames( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.exporter.span.inflight", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.exporter.operation.duration", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.exporter.span.exported"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .anySatisfy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(scopeMetrics.getScope().getName()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .isEqualTo("io.opentelemetry.sdk.logs"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertMetricNames( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.log.created", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.processor.log.processed", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.processor.log.queue.capacity", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.processor.log.queue.size"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
293
to
303
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #nit if we're not going to assert on the attributes, maybe a more terse assert syntax
Suggested change
Or maybe even something like maintaining a Not critical, but this test does get pretty long with so many verbose asserts.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call - I added a helper too, it seems to be both much smaller and more readable |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .anySatisfy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat(scopeMetrics.getScope().getName()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .isEqualTo("io.opentelemetry.sdk.trace"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertMetricNames( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.span.live", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.span.started", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.processor.span.processed", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.processor.span.queue.capacity", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "otel.sdk.processor.span.queue.size"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -318,6 +365,12 @@ private static void assertHasKeyValue(List<KeyValue> keyValues, String key, Stri | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .build()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static void assertMetricNames(ScopeMetrics scopeMetrics, String... names) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertThat( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scopeMetrics.getMetricsList().stream().map(Metric::getName).collect(Collectors.toSet())) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .containsExactlyInAnyOrder(names); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static List<KeyValue> getFirstDataPointLabels(Metric metric) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (metric.getDataCase()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case GAUGE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too bad we need two copies of this code. Maybe each can have a note in the javadoc referencing the other to increase the chance of keeping changes in sync?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah added the references