|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.sdk.autoconfigure; |
| 7 | + |
| 8 | +import static java.util.Collections.singletonMap; |
| 9 | +import static org.assertj.core.api.Assertions.assertThat; |
| 10 | +import static org.assertj.core.api.Assertions.entry; |
| 11 | + |
| 12 | +import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | + |
| 15 | +class ConditionalResourceProviderTest { |
| 16 | + |
| 17 | + @Test |
| 18 | + void shouldConditionallyProvideResourceAttributes_skipBasedOnPreviousResource() { |
| 19 | + AutoConfiguredOpenTelemetrySdk sdk = |
| 20 | + AutoConfiguredOpenTelemetrySdk.builder() |
| 21 | + .setResultAsGlobal(false) |
| 22 | + .registerShutdownHook(false) |
| 23 | + .build(); |
| 24 | + |
| 25 | + assertThat(sdk.getResource().getAttributes().asMap()) |
| 26 | + .contains(entry(ResourceAttributes.SERVICE_NAME, "test-service")); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + void shouldConditionallyProvideResourceAttributes_skipBasedOnConfig() { |
| 31 | + AutoConfiguredOpenTelemetrySdk sdk = |
| 32 | + AutoConfiguredOpenTelemetrySdk.builder() |
| 33 | + .setResultAsGlobal(false) |
| 34 | + .registerShutdownHook(false) |
| 35 | + .addPropertiesSupplier(() -> singletonMap("skip-first-resource-provider", "true")) |
| 36 | + .build(); |
| 37 | + |
| 38 | + assertThat(sdk.getResource().getAttributes().asMap()) |
| 39 | + .contains(entry(ResourceAttributes.SERVICE_NAME, "test-service-2")); |
| 40 | + } |
| 41 | +} |
0 commit comments