Fix deprecations for OpenTelemetry in tests

This commit is contained in:
Moritz Halbritter 2024-09-06 08:30:44 +02:00
parent 2144a159f2
commit dc428e3fc9
2 changed files with 3 additions and 5 deletions

View File

@ -24,7 +24,6 @@ import io.opentelemetry.sdk.logs.SdkLoggerProvider;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.semconv.ResourceAttributes;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfiguration;
@ -86,7 +85,7 @@ class OpenTelemetryAutoConfigurationTests {
this.runner.withPropertyValues("spring.application.name=my-application").run((context) -> {
Resource resource = context.getBean(Resource.class);
assertThat(resource.getAttributes().asMap())
.contains(entry(ResourceAttributes.SERVICE_NAME, "my-application"));
.contains(entry(AttributeKey.stringKey("service.name"), "my-application"));
});
}
@ -112,7 +111,7 @@ class OpenTelemetryAutoConfigurationTests {
this.runner.run((context) -> {
Resource resource = context.getBean(Resource.class);
assertThat(resource.getAttributes().asMap())
.contains(entry(ResourceAttributes.SERVICE_NAME, "unknown_service"));
.contains(entry(AttributeKey.stringKey("service.name"), "unknown_service"));
});
}

View File

@ -53,7 +53,6 @@ import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.semconv.ResourceAttributes;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -195,7 +194,7 @@ class OpenTelemetryAutoConfigurationTests {
exporter.await(Duration.ofSeconds(10));
SpanData spanData = exporter.getExportedSpans().get(0);
Map<AttributeKey<?>, Object> expectedAttributes = Resource.getDefault()
.merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "unknown_service")))
.merge(Resource.create(Attributes.of(AttributeKey.stringKey("service.name"), "unknown_service")))
.getAttributes()
.asMap();
assertThat(spanData.getResource().getAttributes().asMap()).isEqualTo(expectedAttributes);