-
Notifications
You must be signed in to change notification settings - Fork 1k
Span kind for method instrumentation / Declarative configuration tooling #14014
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
Merged
trask
merged 23 commits into
open-telemetry:main
from
zeitlinger:span-kind-for-method-instrumentation
Jun 28, 2025
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9a49700
add span kind support for method instrumentation
zeitlinger df1f644
add span kind support for method instrumentation
zeitlinger 999230a
use declarative config
zeitlinger 6353239
format
zeitlinger 793826d
fix
zeitlinger 910d7fa
fix
zeitlinger cf5bdbe
add test brigde for exporters
zeitlinger 2b12173
add test bridge for exporters
zeitlinger 169aa08
separate test bridge for agent
zeitlinger a3214e1
reduce logging (gets it the way of tests)
zeitlinger 70d05d0
simplify
zeitlinger 5190da6
remove redundant imports
zeitlinger 002a78d
pr feedback
zeitlinger 013ff9c
cleanup
zeitlinger 6a86ced
simplify test
zeitlinger e1384ae
simplify bytecode transform
zeitlinger 64a18fe
revert change
zeitlinger a439e4b
Method instrumentation
laurit 51d3fc7
rename to memory provider - like https://github.com/open-telemetry/op…
zeitlinger 4ee030f
./gradlew spotlessApply
otelbot[bot] 76dde36
pr review
zeitlinger 0206024
pr review
zeitlinger 8b46f22
fix rebase
zeitlinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
|
|
||
| import static java.util.Collections.emptyList; | ||
|
|
||
| import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
| import java.time.Duration; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -107,4 +108,18 @@ default List<String> getList(String name) { | |
| * {@code key=value,anotherKey=anotherValue}. The returned map is unmodifiable. | ||
| */ | ||
| Map<String, String> getMap(String name, Map<String, String> defaultValue); | ||
|
|
||
| /** | ||
| * Returns a {@link DeclarativeConfigProperties} for the given instrumentation name, or {@code | ||
| * null} if no declarative configuration is available for that instrumentation. | ||
| * | ||
| * <p>Declarative configuration is used to configure instrumentation properties in a declarative | ||
| * way, such as through YAML or JSON files. | ||
| * | ||
| * @param instrumentationName the name of the instrumentation | ||
| * @return the declarative configuration properties for the given instrumentation name, or {@code | ||
| * null} if not available | ||
| */ | ||
| @Nullable | ||
| DeclarativeConfigProperties getDeclarativeConfig(String instrumentationName); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may want to rename this param name in the future since we've discussed it also being "vendor" node, or "common" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. created #14160 |
||
| } | ||
This file contains hidden or 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
45 changes: 45 additions & 0 deletions
45
...arativeConfigTest/java/io/opentelemetry/javaagent/instrumentation/methods/MethodTest.java
This file contains hidden or 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,45 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.methods; | ||
|
|
||
| import static io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil.codeFunctionAssertions; | ||
| import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; | ||
|
|
||
| import io.opentelemetry.api.trace.SpanKind; | ||
| import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
| import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
| import java.util.concurrent.Callable; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| @SuppressWarnings("deprecation") // using deprecated semconv | ||
| class MethodTest { | ||
zeitlinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @RegisterExtension | ||
| static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
|
||
| @SuppressWarnings("deprecation") // using deprecated semconv | ||
| @Test | ||
| void methodTraced() { | ||
| assertThat(new ConfigTracedCallable().call()).isEqualTo("Hello!"); | ||
| testing.waitAndAssertTraces( | ||
| trace -> | ||
| trace.hasSpansSatisfyingExactly( | ||
| span -> | ||
| span.hasName("ConfigTracedCallable.call") | ||
| .hasKind(SpanKind.SERVER) | ||
| .hasAttributesSatisfyingExactly( | ||
| codeFunctionAssertions(ConfigTracedCallable.class, "call")))); | ||
| } | ||
|
|
||
| static class ConfigTracedCallable implements Callable<String> { | ||
|
|
||
| @Override | ||
| public String call() { | ||
| return "Hello!"; | ||
| } | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
...rumentation/methods/javaagent/src/declarativeConfigTest/resources/declarative-config.yaml
This file contains hidden or 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,33 @@ | ||
| file_format: "0.4" | ||
| tracer_provider: | ||
| processors: | ||
| - simple: | ||
| exporter: | ||
| test: | ||
| - simple: | ||
| exporter: | ||
| console: | ||
|
|
||
| logger_provider: | ||
| processors: | ||
| - simple: | ||
| exporter: | ||
| test: | ||
|
|
||
| meter_provider: | ||
| readers: | ||
| - periodic: | ||
| # Set really long interval. We'll call forceFlush when we need the metrics | ||
| # instead of collecting them periodically. | ||
| interval: 1000000 | ||
| exporter: | ||
| test: | ||
|
|
||
| instrumentation/development: | ||
| java: | ||
| methods: | ||
| include: | ||
zeitlinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - class: io.opentelemetry.javaagent.instrumentation.methods.MethodTest$ConfigTracedCallable | ||
| methods: | ||
| - name: call | ||
| span_kind: SERVER | ||
31 changes: 31 additions & 0 deletions
31
...agent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodAndType.java
This file contains hidden or 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,31 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.methods; | ||
|
|
||
| import io.opentelemetry.api.trace.SpanKind; | ||
| import io.opentelemetry.instrumentation.api.incubator.semconv.util.ClassAndMethod; | ||
|
|
||
| public class MethodAndType { | ||
| private final ClassAndMethod classAndMethod; | ||
| private final SpanKind spanKind; | ||
|
|
||
| private MethodAndType(ClassAndMethod classAndMethod, SpanKind spanKind) { | ||
| this.classAndMethod = classAndMethod; | ||
| this.spanKind = spanKind; | ||
| } | ||
|
|
||
| public static MethodAndType create(ClassAndMethod classAndMethod, SpanKind spanKind) { | ||
| return new MethodAndType(classAndMethod, spanKind); | ||
| } | ||
|
|
||
| public ClassAndMethod getClassAndMethod() { | ||
| return classAndMethod; | ||
| } | ||
|
|
||
| public SpanKind getSpanKind() { | ||
| return spanKind; | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.