Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cf9d250
add missing declarative config resource providers
zeitlinger Jul 10, 2025
70cc64c
add missing declarative config resource providers
zeitlinger Jul 10, 2025
cadc237
add missing declarative config resource providers
zeitlinger Jul 10, 2025
a128a8f
prevent that view config file is loaded
zeitlinger Jul 10, 2025
677bf18
pr review
zeitlinger Jul 16, 2025
b594dfb
add docs
zeitlinger Jul 16, 2025
6219ad9
pr feedback
zeitlinger Jul 17, 2025
9ffb655
pr review
zeitlinger Aug 16, 2025
acce028
fix
zeitlinger Aug 20, 2025
e082955
pr feedback
zeitlinger Aug 21, 2025
27d6dc7
pr feedback
zeitlinger Aug 21, 2025
582adac
separate resource extraction from supported interfaces
zeitlinger Aug 22, 2025
e242758
separate resource extraction from supported interfaces
zeitlinger Aug 22, 2025
40a3106
separate resource extraction from supported interfaces
zeitlinger Aug 22, 2025
7a0a61e
separate resource extraction from supported interfaces
zeitlinger Aug 22, 2025
850a699
./gradlew spotlessApply
otelbot[bot] Aug 22, 2025
a33147f
fix
zeitlinger Aug 22, 2025
550bc66
fix rebase
zeitlinger Aug 29, 2025
77f3fbc
./gradlew spotlessApply
otelbot[bot] Aug 29, 2025
dd20147
set enabled in test
zeitlinger Sep 2, 2025
b2b21db
add smoke test
zeitlinger Sep 5, 2025
194d2cb
add smoke test
zeitlinger Sep 5, 2025
03ef3ed
pr review
zeitlinger Sep 11, 2025
db3a54a
pr review
zeitlinger Sep 11, 2025
c69a836
pr review
zeitlinger Sep 11, 2025
a47828c
pr review
zeitlinger Sep 11, 2025
48a4105
pr review
zeitlinger Sep 11, 2025
b808538
pr review
zeitlinger Sep 11, 2025
3a44358
pr review
zeitlinger Sep 11, 2025
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
Expand Up @@ -21,11 +21,11 @@ public Class<Resource> getType() {

@Override
public String getName() {
return "distribution";
return "opentelemetry-javaagent-distribution";
}

@Override
public Resource create(DeclarativeConfigProperties config) {
return DistroResourceProvider.get();
return DistroResourceProvider.get("opentelemetry-javaagent");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ public class DistroResourceProvider implements ResourceProvider {

@Override
public Resource createResource(ConfigProperties config) {
return get();
return get("opentelemetry-java-instrumentation");
Copy link
Member

Choose a reason for hiding this comment

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

can you open an issue to change this in 3.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

}

static Resource get() {
static Resource get(String distroName) {
return AgentVersion.VERSION == null
? Resource.empty()
: Resource.create(
Attributes.of(
TELEMETRY_DISTRO_NAME,
"opentelemetry-java-instrumentation",
TELEMETRY_DISTRO_VERSION,
AgentVersion.VERSION));
TELEMETRY_DISTRO_NAME, distroName, TELEMETRY_DISTRO_VERSION, AgentVersion.VERSION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalResourceDetectionModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalResourceDetectorModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ResourceModel;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand All @@ -24,11 +24,10 @@
@AutoService(DeclarativeConfigurationCustomizerProvider.class)
public class ResourceCustomizerProvider implements DeclarativeConfigurationCustomizerProvider {

// distribution: adds "distro.name" and "distro.version" attributes
// opentelemetry-javaagent-distribution: adds "distro.name" and "distro.version" attributes
// (DistroComponentProvider in this package)
// service: adds "service.name" and "service.instance.id" attributes
// (https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.java)
private static final List<String> REQUIRED_DETECTORS = Arrays.asList("distribution", "service");
private static final List<String> REQUIRED_DETECTORS =
Collections.singletonList("opentelemetry-javaagent-distribution");

@Override
public void customize(DeclarativeConfigurationCustomizer customizer) {
Expand All @@ -55,7 +54,9 @@ public void customize(DeclarativeConfigurationCustomizer customizer) {
if (!names.contains(name)) {
ExperimentalResourceDetectorModel detector = new ExperimentalResourceDetectorModel();
detector.getAdditionalProperties().put(name, null);
detectors.add(detector);
// add first (the least precedence)
// so that the user can add a differently named detector that takes precedence
detectors.add(0, detector);
}
}
return model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,20 @@ class DeclarativeConfigurationSmokeTest extends SmokeTest {
then: "There is one trace"
traces.size() > 0

then: "declarative config is applied"
def serviceName = findResourceAttribute(traces, "service.name")
.map { it.stringValue }
.findAny()
serviceName.isPresent()
serviceName.get() == "declarative-config-smoke-test"

then: "service detector is added by customizer"
def serviceInstanceId = findResourceAttribute(traces, "service.instance.id")
.map { it.stringValue }
.findAny()
serviceInstanceId.isPresent()
then: "explicitly set attribute is present"
hasResourceAttribute(traces, "service.name", "declarative-config-smoke-test")

then: "explicitly set container detector is used"
findResourceAttribute(traces, "container.id").findAny().isPresent()

then: "explicitly set container process detector is used"
findResourceAttribute(traces, "process.executable.path").findAny().isPresent()

then: "explicitly set container host detector is used"
findResourceAttribute(traces, "host.name").findAny().isPresent()

then: "distro detector is added by customizer"
def distroName = findResourceAttribute(traces, "telemetry.distro.name")
.map { it.stringValue }
.findAny()
distroName.isPresent()
distroName.get() == "opentelemetry-java-instrumentation"
hasResourceAttribute(traces, "telemetry.distro.name", "opentelemetry-javaagent")

cleanup:
stopTarget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ abstract class SmokeTest extends Specification {
.map { it.value }
}

protected static boolean hasResourceAttribute(Collection<ExportTraceServiceRequest> traces,
String attributeKey,
String attributeValue) {
return findResourceAttribute(traces, attributeKey)
.filter { it.stringValue == attributeValue }
.findAny()
.isPresent()
}

protected static int countSpansByName(Collection<ExportTraceServiceRequest> traces, String spanName) {
return getSpanStream(traces).filter { it.name == spanName }.count()
}
Expand Down
5 changes: 5 additions & 0 deletions smoke-tests/src/test/resources/declarative-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ tracer_provider:

# add extra resource attributes to verify that declarative config is picked up
resource:
detection/development:
detectors:
- container:
- host:
- process:
attributes:
- name: service.name
value: declarative-config-smoke-test
Loading