-
Notifications
You must be signed in to change notification settings - Fork 1k
Add Helidon Instrumentation #13776
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
Merged
Add Helidon Instrumentation #13776
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9678009
start
SentryMan 6ec80d0
use matching
SentryMan 14e2725
update route
SentryMan 87963ba
update docs
SentryMan 6644c39
use filter directly
SentryMan e0bbc55
working agent test
SentryMan 2b4d6d4
M1
SentryMan b2dbe62
./gradlew spotlessApply
otelbot[bot] 4c7d96c
Revert "M1"
SentryMan c1f1277
Merge branch 'main' into feature/helidon
SentryMan 59d9cb1
Create metadata.yaml
SentryMan f8b5963
Merge branch 'main' into feature/helidon
SentryMan 6ddd3ac
pr comments
SentryMan 7fa94ef
Update build.gradle.kts
SentryMan 778c3fc
Update build.gradle.kts
SentryMan c1ed23c
review
laurit bb51f06
review
laurit 2033b03
fix link
laurit d170dd4
Merge branch 'main' into feature/helidon
SentryMan f310771
Merge branch 'main' into feature/helidon
SentryMan cfcfeff
Merge branch 'main' into feature/helidon
laurit fe66ac1
review
laurit 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
22 changes: 22 additions & 0 deletions
22
instrumentation/helidon/helidon-4.3.0/javaagent/build.gradle.kts
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,22 @@ | ||
plugins { | ||
id("otel.javaagent-instrumentation") | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group.set("io.helidon.webserver") | ||
module.set("helidon-webserver") | ||
versions.set("[4.3.0,)") | ||
assertInverse.set(true) | ||
} | ||
} | ||
|
||
otelJava { | ||
minJavaVersionSupported.set(JavaVersion.VERSION_21) | ||
} | ||
|
||
dependencies { | ||
library("io.helidon.webserver:helidon-webserver:4.3.0") | ||
implementation(project(":instrumentation:helidon:helidon-4.3.0:library")) | ||
testImplementation(project(":instrumentation:helidon:helidon-4.3.0:testing")) | ||
} |
42 changes: 42 additions & 0 deletions
42
.../main/java/io/opentelemetry/javaagent/instrumentation/helidon/HelidonInstrumentation.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,42 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.helidon; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.isStatic; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
||
import io.helidon.webserver.http.HttpRouting; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class HelidonInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("io.helidon.webserver.http.HttpRouting"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isMethod().and(isPublic()).and(isStatic()).and(named("builder")), | ||
HelidonInstrumentation.class.getName() + "$BuildAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class BuildAdvice { | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void onExit(@Advice.Return HttpRouting.Builder httpContext) { | ||
HelidonSingletons.FILTERS.forEach(httpContext::addFilter); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...java/io/opentelemetry/javaagent/instrumentation/helidon/HelidonInstrumentationModule.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,25 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.helidon; | ||
|
||
import static java.util.Collections.singletonList; | ||
|
||
import com.google.auto.service.AutoService; | ||
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import java.util.List; | ||
|
||
@AutoService(InstrumentationModule.class) | ||
public class HelidonInstrumentationModule extends InstrumentationModule { | ||
public HelidonInstrumentationModule() { | ||
super("helidon", "helidon-4.3.0"); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return singletonList(new HelidonInstrumentation()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...java/io/opentelemetry/javaagent/instrumentation/helidon/HelidonServerResponseMutator.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,18 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.helidon; | ||
|
||
import io.helidon.webserver.http.ServerResponse; | ||
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseMutator; | ||
|
||
enum HelidonServerResponseMutator implements HttpServerResponseMutator<ServerResponse> { | ||
INSTANCE; | ||
|
||
@Override | ||
public void appendHeader(ServerResponse res, String name, String value) { | ||
res.header(name, value); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...t/src/main/java/io/opentelemetry/javaagent/instrumentation/helidon/HelidonSingletons.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,32 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.helidon; | ||
|
||
import io.helidon.webserver.http.Filter; | ||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.instrumentation.helidon.HelidonTelemetry; | ||
import io.opentelemetry.instrumentation.helidon.internal.HelidonInstrumenterBuilderUtil; | ||
import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; | ||
import java.util.List; | ||
|
||
public final class HelidonSingletons { | ||
|
||
public static final List<Filter> FILTERS; | ||
|
||
static { | ||
var config = AgentCommonConfig.get(); | ||
|
||
var serverBuilder = HelidonTelemetry.builder(GlobalOpenTelemetry.get()); | ||
HelidonInstrumenterBuilderUtil.getServerBuilderExtractor() | ||
.apply(serverBuilder) | ||
.configure(config); | ||
var serverTelemetry = serverBuilder.build(); | ||
|
||
FILTERS = List.of(serverTelemetry.createFilter(), new ResponseCustomizingFilter()); | ||
} | ||
|
||
private HelidonSingletons() {} | ||
} |
27 changes: 27 additions & 0 deletions
27
...in/java/io/opentelemetry/javaagent/instrumentation/helidon/ResponseCustomizingFilter.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,27 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.helidon; | ||
|
||
import io.helidon.webserver.http.Filter; | ||
import io.helidon.webserver.http.FilterChain; | ||
import io.helidon.webserver.http.RoutingRequest; | ||
import io.helidon.webserver.http.RoutingResponse; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseCustomizerHolder; | ||
|
||
final class ResponseCustomizingFilter implements Filter { | ||
|
||
ResponseCustomizingFilter() {} | ||
|
||
@Override | ||
public void filter(FilterChain chain, RoutingRequest req, RoutingResponse res) { | ||
|
||
var context = Context.current(); | ||
HttpServerResponseCustomizerHolder.getCustomizer() | ||
.customize(context, res, HelidonServerResponseMutator.INSTANCE); | ||
chain.proceed(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...t/src/test/java/io/opentelemetry/javaagent/instrumentation/helidon/HelidonServerTest.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,26 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.helidon; | ||
|
||
import io.opentelemetry.instrumentation.helidon.AbstractHelidonTest; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class HelidonServerTest extends AbstractHelidonTest { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent(); | ||
|
||
@Override | ||
protected void configure(HttpServerTestOptions options) { | ||
super.configure(options); | ||
options.setHasResponseCustomizer(serverEndpoint -> true); | ||
|
||
options.setTestNotFound(false); | ||
} | ||
} |
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,55 @@ | ||
# Library Instrumentation for Helidon | ||
|
||
Provides OpenTelemetry instrumentation for [Helidon](https://helidon.io/). | ||
|
||
## Quickstart | ||
|
||
### Add these dependencies to your project | ||
|
||
Replace `OPENTELEMETRY_VERSION` with the [latest | ||
release](https://search.maven.org/search?q=g:io.opentelemetry.instrumentation%20AND%20a:opentelemetry-helidon-4.3.0). | ||
|
||
For Maven, add to your `pom.xml` dependencies: | ||
|
||
```xml | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.opentelemetry.instrumentation</groupId> | ||
<artifactId>opentelemetry-helidon-4.3.0</artifactId> | ||
<version>OPENTELEMETRY_VERSION</version> | ||
</dependency> | ||
</dependencies> | ||
``` | ||
|
||
For Gradle, add to your dependencies: | ||
|
||
```groovy | ||
implementation("io.opentelemetry.instrumentation:opentelemetry-helidon-4.3.0:OPENTELEMETRY_VERSION") | ||
``` | ||
|
||
### Usage | ||
|
||
The instrumentation library contains an `HttpFeature` that provides OpenTelemetry-based spans | ||
and context propagation. | ||
|
||
```java | ||
import java.io.IOException; | ||
|
||
import io.helidon.webserver.WebServer; | ||
import io.helidon.webserver.http.HttpRouting; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
|
||
public class Application { | ||
|
||
static void main(String args) throws IOException { | ||
|
||
OpenTelemetry openTelemetry = // ... | ||
WebServer.builder() | ||
.addRouting( | ||
HttpRouting.builder() | ||
.addFeature(HelidonTelemetry.create(openTelemetry)) | ||
.get("/greet", (req, res) -> res.send("Hello World!"))) | ||
.build(); | ||
} | ||
} | ||
``` |
12 changes: 12 additions & 0 deletions
12
instrumentation/helidon/helidon-4.3.0/library/build.gradle.kts
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,12 @@ | ||
plugins { | ||
id("otel.library-instrumentation") | ||
} | ||
|
||
otelJava { | ||
minJavaVersionSupported.set(JavaVersion.VERSION_21) | ||
} | ||
|
||
dependencies { | ||
implementation("io.helidon.webserver:helidon-webserver:4.3.0") | ||
testImplementation(project(":instrumentation:helidon:helidon-4.3.0:testing")) | ||
} |
89 changes: 89 additions & 0 deletions
89
...brary/src/main/java/io/opentelemetry/instrumentation/helidon/HelidonAttributesGetter.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,89 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.helidon; | ||
|
||
import io.helidon.http.HeaderNames; | ||
import io.helidon.webserver.http.ServerRequest; | ||
import io.helidon.webserver.http.ServerResponse; | ||
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter; | ||
import java.net.InetSocketAddress; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import javax.annotation.Nullable; | ||
|
||
enum HelidonAttributesGetter implements HttpServerAttributesGetter<ServerRequest, ServerResponse> { | ||
INSTANCE; | ||
|
||
@Override | ||
public String getHttpRequestMethod(ServerRequest req) { | ||
return req.prologue().method().text(); | ||
} | ||
|
||
@Override | ||
public String getUrlScheme(ServerRequest req) { | ||
return req.requestedUri().scheme(); | ||
} | ||
|
||
@Override | ||
public String getUrlPath(ServerRequest req) { | ||
return req.path().rawPath(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getUrlQuery(ServerRequest req) { | ||
return req.query().rawValue(); | ||
} | ||
|
||
@Override | ||
public List<String> getHttpRequestHeader(ServerRequest req, String name) { | ||
return req.headers().values(HeaderNames.create(name)); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Integer getHttpResponseStatusCode( | ||
ServerRequest req, @Nullable ServerResponse res, @Nullable Throwable error) { | ||
|
||
return Objects.requireNonNull(res).status().code(); | ||
} | ||
|
||
@Override | ||
public List<String> getHttpResponseHeader( | ||
ServerRequest req, @Nullable ServerResponse res, String name) { | ||
return Objects.requireNonNull(res).headers().values(HeaderNames.create(name)); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getHttpRoute(ServerRequest req) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getNetworkProtocolName(ServerRequest req, @Nullable ServerResponse res) { | ||
return req.prologue().protocol(); | ||
} | ||
|
||
@Override | ||
public String getNetworkProtocolVersion(ServerRequest req, @Nullable ServerResponse res) { | ||
return req.prologue().protocolVersion(); | ||
} | ||
|
||
@Override | ||
public InetSocketAddress getNetworkPeerInetSocketAddress( | ||
ServerRequest req, @Nullable ServerResponse res) { | ||
var address = req.remotePeer().address(); | ||
return address instanceof InetSocketAddress s ? s : null; | ||
} | ||
|
||
@Override | ||
public InetSocketAddress getNetworkLocalInetSocketAddress( | ||
ServerRequest req, @Nullable ServerResponse res) { | ||
var address = req.localPeer().address(); | ||
return address instanceof InetSocketAddress s ? s : null; | ||
} | ||
} |
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.