-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Lauri Tulmin <ltulmin@splunk.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
- Loading branch information
1 parent
26591ea
commit 7f30056
Showing
25 changed files
with
1,049 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
25 changes: 25 additions & 0 deletions
25
instrumentation/jetty-httpclient/jetty-httpclient-12.0/javaagent/build.gradle.kts
This file contains 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 @@ | ||
plugins { | ||
id("otel.javaagent-instrumentation") | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group.set("org.eclipse.jetty") | ||
module.set("jetty-client") | ||
versions.set("[12,)") | ||
} | ||
} | ||
|
||
otelJava { | ||
minJavaVersionSupported.set(JavaVersion.VERSION_17) | ||
} | ||
|
||
dependencies { | ||
implementation(project(":instrumentation:jetty-httpclient:jetty-httpclient-12.0:library")) | ||
|
||
library("org.eclipse.jetty:jetty-client:12.0.0") | ||
|
||
testInstrumentation(project(":instrumentation:jetty-httpclient:jetty-httpclient-9.2:javaagent")) | ||
|
||
testImplementation(project(":instrumentation:jetty-httpclient:jetty-httpclient-12.0:testing")) | ||
} |
108 changes: 108 additions & 0 deletions
108
...instrumentation/jetty/httpclient/v12_0/JettyClient12ResponseListenersInstrumentation.java
This file contains 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,108 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jetty.httpclient.v12_0; | ||
|
||
import static io.opentelemetry.javaagent.instrumentation.jetty.httpclient.v12_0.JettyHttpClientSingletons.JETTY_CLIENT_CONTEXT_KEY; | ||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.nameContains; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
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; | ||
import org.eclipse.jetty.client.Response; | ||
import org.eclipse.jetty.client.Result; | ||
|
||
public class JettyClient12ResponseListenersInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("org.eclipse.jetty.client.transport.ResponseListeners"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
// for response listeners | ||
transformer.applyAdviceToMethod( | ||
isMethod() | ||
.and( | ||
nameContains("notify") | ||
.and(isPublic()) | ||
.and(takesArgument(0, named("org.eclipse.jetty.client.Response")))), | ||
JettyClient12ResponseListenersInstrumentation.class.getName() | ||
+ "$JettyHttpClient12RespListenersNotifyAdvice"); | ||
|
||
// for complete listeners | ||
transformer.applyAdviceToMethod( | ||
isMethod() | ||
.and( | ||
nameContains("notifyComplete") | ||
.and(isPublic()) | ||
.and(takesArgument(0, named("org.eclipse.jetty.client.Result")))), | ||
JettyClient12ResponseListenersInstrumentation.class.getName() | ||
+ "$JettyHttpClient12CompleteListenersNotifyAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class JettyHttpClient12RespListenersNotifyAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnterNotify( | ||
@Advice.Argument(0) Response response, | ||
@Advice.Local("otelContext") Context context, | ||
@Advice.Local("otelScope") Scope scope) { | ||
context = (Context) response.getRequest().getAttributes().get(JETTY_CLIENT_CONTEXT_KEY); | ||
if (context != null) { | ||
scope = context.makeCurrent(); | ||
} | ||
} | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) | ||
public static void onExitNotify( | ||
@Advice.Argument(0) Response response, | ||
@Advice.Thrown Throwable throwable, | ||
@Advice.Local("otelContext") Context context, | ||
@Advice.Local("otelScope") Scope scope) { | ||
if (scope == null) { | ||
return; | ||
} | ||
|
||
scope.close(); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class JettyHttpClient12CompleteListenersNotifyAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnterComplete( | ||
@Advice.Argument(0) Result result, | ||
@Advice.Local("otelContext") Context context, | ||
@Advice.Local("otelScope") Scope scope) { | ||
context = (Context) result.getRequest().getAttributes().get(JETTY_CLIENT_CONTEXT_KEY); | ||
if (context != null) { | ||
scope = context.makeCurrent(); | ||
} | ||
} | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) | ||
public static void onExitComplete( | ||
@Advice.Argument(0) Result result, | ||
@Advice.Thrown Throwable throwable, | ||
@Advice.Local("otelContext") Context context, | ||
@Advice.Local("otelScope") Scope scope) { | ||
if (scope == null) { | ||
return; | ||
} | ||
|
||
scope.close(); | ||
} | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...ry/javaagent/instrumentation/jetty/httpclient/v12_0/JettyHttpClient12Instrumentation.java
This file contains 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,107 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jetty.httpclient.v12_0; | ||
|
||
import static io.opentelemetry.javaagent.instrumentation.jetty.httpclient.v12_0.JettyHttpClientSingletons.JETTY_CLIENT_CONTEXT_KEY; | ||
import static io.opentelemetry.javaagent.instrumentation.jetty.httpclient.v12_0.JettyHttpClientSingletons.instrumenter; | ||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.nameContains; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.instrumentation.jetty.httpclient.v12_0.internal.JettyClientTracingListener; | ||
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; | ||
import org.eclipse.jetty.client.transport.HttpRequest; | ||
|
||
public class JettyHttpClient12Instrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("org.eclipse.jetty.client.transport.HttpRequest"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isMethod() | ||
.and(named("send")) | ||
.and(takesArgument(0, named("org.eclipse.jetty.client.Response$CompleteListener"))), | ||
JettyHttpClient12Instrumentation.class.getName() + "$JettyHttpClient12SendAdvice"); | ||
// For request listeners | ||
transformer.applyAdviceToMethod( | ||
isMethod().and(nameContains("notify")), | ||
JettyHttpClient12Instrumentation.class.getName() + "$JettyHttpClient12NotifyAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class JettyHttpClient12SendAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnterSend( | ||
@Advice.This HttpRequest request, | ||
@Advice.Local("otelContext") Context context, | ||
@Advice.Local("otelScope") Scope scope) { | ||
// start span | ||
Context parentContext = Context.current(); | ||
context = JettyClientTracingListener.handleRequest(parentContext, request, instrumenter()); | ||
if (context == null) { | ||
return; | ||
} | ||
// set context for responseListeners | ||
request.attribute(JETTY_CLIENT_CONTEXT_KEY, parentContext); | ||
|
||
scope = context.makeCurrent(); | ||
} | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) | ||
public static void onExitSend( | ||
@Advice.This HttpRequest request, | ||
@Advice.Thrown Throwable throwable, | ||
@Advice.Local("otelContext") Context context, | ||
@Advice.Local("otelScope") Scope scope) { | ||
if (scope == null) { | ||
return; | ||
} | ||
|
||
// not ending span here unless error, span ended in the interceptor | ||
scope.close(); | ||
if (throwable != null) { | ||
instrumenter().end(context, request, null, throwable); | ||
} | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class JettyHttpClient12NotifyAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnterNotify( | ||
@Advice.This HttpRequest request, | ||
@Advice.Local("otelContext") Context context, | ||
@Advice.Local("otelScope") Scope scope) { | ||
context = (Context) request.getAttributes().get(JETTY_CLIENT_CONTEXT_KEY); | ||
if (context == null) { | ||
return; | ||
} | ||
scope = context.makeCurrent(); | ||
} | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) | ||
public static void onExitNotify( | ||
@Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { | ||
if (scope == null) { | ||
return; | ||
} | ||
|
||
scope.close(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...aagent/instrumentation/jetty/httpclient/v12_0/JettyHttpClient12InstrumentationModule.java
This file contains 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.jetty.httpclient.v12_0; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
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 JettyHttpClient12InstrumentationModule extends InstrumentationModule { | ||
public JettyHttpClient12InstrumentationModule() { | ||
super("jetty-httpclient", "jetty-httpclient-12.0"); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return asList( | ||
new JettyHttpClient12Instrumentation(), | ||
new JettyClient12ResponseListenersInstrumentation()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...telemetry/javaagent/instrumentation/jetty/httpclient/v12_0/JettyHttpClientSingletons.java
This file contains 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,28 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jetty.httpclient.v12_0; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import io.opentelemetry.instrumentation.jetty.httpclient.v12_0.internal.JettyHttpClientInstrumenterBuilderFactory; | ||
import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpClientInstrumenters; | ||
import org.eclipse.jetty.client.Request; | ||
import org.eclipse.jetty.client.Response; | ||
|
||
public final class JettyHttpClientSingletons { | ||
|
||
static final String JETTY_CLIENT_CONTEXT_KEY = "otel-jetty-client-context"; | ||
|
||
private static final Instrumenter<Request, Response> INSTRUMENTER = | ||
JavaagentHttpClientInstrumenters.create( | ||
JettyHttpClientInstrumenterBuilderFactory.create(GlobalOpenTelemetry.get())); | ||
|
||
public static Instrumenter<Request, Response> instrumenter() { | ||
return INSTRUMENTER; | ||
} | ||
|
||
private JettyHttpClientSingletons() {} | ||
} |
31 changes: 31 additions & 0 deletions
31
...elemetry/javaagent/instrumentation/jetty/httpclient/v12_0/JettyHttpClient12AgentTest.java
This file contains 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.jetty.httpclient.v12_0; | ||
|
||
import io.opentelemetry.instrumentation.jetty.httpclient.v12_0.AbstractJettyClient12Test; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; | ||
import org.eclipse.jetty.client.HttpClient; | ||
import org.eclipse.jetty.util.ssl.SslContextFactory; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class JettyHttpClient12AgentTest extends AbstractJettyClient12Test { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent(); | ||
|
||
@Override | ||
protected HttpClient createStandardClient() { | ||
return new HttpClient(); | ||
} | ||
|
||
@Override | ||
protected HttpClient createHttpsClient(SslContextFactory.Client sslContextFactory) { | ||
HttpClient httpClient = new HttpClient(); | ||
httpClient.setSslContextFactory(sslContextFactory); | ||
return httpClient; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/build.gradle.kts
This file contains 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,13 @@ | ||
plugins { | ||
id("otel.library-instrumentation") | ||
} | ||
|
||
otelJava { | ||
minJavaVersionSupported.set(JavaVersion.VERSION_17) | ||
} | ||
|
||
dependencies { | ||
library("org.eclipse.jetty:jetty-client:12.0.0") | ||
|
||
testImplementation(project(":instrumentation:jetty-httpclient::jetty-httpclient-12.0:testing")) | ||
} |
37 changes: 37 additions & 0 deletions
37
...in/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetry.java
This file contains 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,37 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.jetty.httpclient.v12_0; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import org.eclipse.jetty.client.HttpClient; | ||
|
||
/** Entrypoint for instrumenting Jetty client. */ | ||
public final class JettyClientTelemetry { | ||
|
||
/** Returns a new {@link JettyClientTelemetry} configured with the given {@link OpenTelemetry}. */ | ||
public static JettyClientTelemetry create(OpenTelemetry openTelemetry) { | ||
JettyClientTelemetryBuilder builder = builder(openTelemetry); | ||
return builder.build(); | ||
} | ||
|
||
/** | ||
* Returns a new {@link JettyClientTelemetryBuilder} configured with the given {@link | ||
* OpenTelemetry}. | ||
*/ | ||
public static JettyClientTelemetryBuilder builder(OpenTelemetry openTelemetry) { | ||
return new JettyClientTelemetryBuilder(openTelemetry); | ||
} | ||
|
||
private final HttpClient httpClient; | ||
|
||
JettyClientTelemetry(HttpClient httpClient) { | ||
this.httpClient = httpClient; | ||
} | ||
|
||
public HttpClient getHttpClient() { | ||
return httpClient; | ||
} | ||
} |
Oops, something went wrong.