Skip to content
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

add Spring boot distro version #10276

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public ResourceProvider otelResourceProvider(
return new SpringResourceProvider(otelSpringResourceProperties, otelResourceProperties);
}

@Bean
public ResourceProvider otelDistroVersionResourceProvider() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return new DistroVersionResourceProvider();
}

@Bean
@ConditionalOnClass(OsResource.class)
public ResourceProvider otelOsResourceProvider() {
Expand Down
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();
});
});
}
}
Loading