-
Notifications
You must be signed in to change notification settings - Fork 870
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Spring boot distro version (#10276)
- Loading branch information
1 parent
35ec443
commit 9c8644c
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...lemetry/instrumentation/spring/autoconfigure/resources/DistroVersionResourceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.resources; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
|
||
public class DistroVersionResourceProvider implements ResourceProvider { | ||
|
||
public static final String VERSION = | ||
EmbeddedInstrumentationProperties.findVersion("io.opentelemetry.spring-boot-autoconfigure"); | ||
|
||
private static final AttributeKey<String> TELEMETRY_DISTRO_NAME = | ||
AttributeKey.stringKey("telemetry.distro.name"); | ||
private static final AttributeKey<String> TELEMETRY_DISTRO_VERSION = | ||
AttributeKey.stringKey("telemetry.distro.version"); | ||
|
||
@Override | ||
public Resource createResource(ConfigProperties config) { | ||
return Resource.create( | ||
Attributes.of( | ||
TELEMETRY_DISTRO_NAME, | ||
"opentelemetry-spring-boot-starter", | ||
TELEMETRY_DISTRO_VERSION, | ||
VERSION)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...try/instrumentation/spring/autoconfigure/resources/DistroVersionResourceProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.resources; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; | ||
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
public class DistroVersionResourceProviderTest { | ||
private final ApplicationContextRunner contextRunner = | ||
new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(OtelResourceAutoConfiguration.class)); | ||
|
||
@Test | ||
@DisplayName("distro version should be set") | ||
void hasAttributes() { | ||
|
||
this.contextRunner.run( | ||
context -> { | ||
ResourceProvider resource = | ||
context.getBean("otelDistroVersionResourceProvider", ResourceProvider.class); | ||
|
||
assertThat( | ||
resource | ||
.createResource(DefaultConfigProperties.createFromMap(ImmutableMap.of())) | ||
.getAttributes() | ||
.asMap()) | ||
.containsEntry( | ||
AttributeKey.stringKey("telemetry.distro.name"), | ||
"opentelemetry-spring-boot-starter") | ||
.anySatisfy( | ||
(key, val) -> { | ||
assertThat(key.getKey()).isEqualTo("telemetry.distro.version"); | ||
assertThat(val).asString().isNotBlank(); | ||
}); | ||
}); | ||
} | ||
} |