Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -8,11 +8,13 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.Arrays;
import java.util.List;

@AutoService(InstrumentationModule.class)
public class RestletInstrumentationModule extends InstrumentationModule {
public class RestletInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {

public RestletInstrumentationModule() {
super("restlet", "restlet-1.1");
Expand All @@ -22,4 +24,9 @@ public RestletInstrumentationModule() {
public List<TypeInstrumentation> typeInstrumentations() {
return Arrays.asList(new ServerInstrumentation(), new RouteInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package io.opentelemetry.javaagent.instrumentation.restlet.v1_1;

import static io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource.CONTROLLER;
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
import static io.opentelemetry.javaagent.instrumentation.restlet.v1_1.RestletSingletons.instrumenter;
import static io.opentelemetry.javaagent.instrumentation.restlet.v1_1.RestletSingletons.serverSpanName;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
Expand All @@ -19,6 +18,7 @@
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseCustomizerHolder;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand All @@ -45,53 +45,64 @@ public void transform(TypeTransformer transformer) {
@SuppressWarnings("unused")
public static class ServerHandleAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void beginRequest(
@Advice.Argument(0) Request request,
@Advice.Argument(1) Response response,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
public static class AdviceScope {
private final Context context;
private final Scope scope;

Context parentContext = currentContext();

if (!instrumenter().shouldStart(parentContext, request)) {
return;
private AdviceScope(Context context, Scope scope) {
this.context = context;
this.scope = scope;
}

context = instrumenter().start(parentContext, request);
scope = context.makeCurrent();
}
@Nullable
public static AdviceScope start(Request request) {
Context parentContext = Context.current();

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void finishRequest(
@Advice.Argument(0) Request request,
@Advice.Argument(1) Response response,
@Advice.Thrown Throwable exception,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (!instrumenter().shouldStart(parentContext, request)) {
return null;
}

if (scope == null) {
return;
Context context = instrumenter().start(parentContext, request);
return new AdviceScope(context, context.makeCurrent());
}

scope.close();
public void end(Throwable exception, Request request, Response response) {
scope.close();

if (Status.CLIENT_ERROR_NOT_FOUND.equals(response.getStatus())) {
HttpServerRoute.update(context, CONTROLLER, serverSpanName(), "/*");
}
if (Status.CLIENT_ERROR_NOT_FOUND.equals(response.getStatus())) {
HttpServerRoute.update(context, CONTROLLER, serverSpanName(), "/*");
}

HttpServerResponseCustomizerHolder.getCustomizer()
.customize(context, response, RestletResponseMutator.INSTANCE);
HttpServerResponseCustomizerHolder.getCustomizer()
.customize(context, response, RestletResponseMutator.INSTANCE);

if (exception != null) {
instrumenter().end(context, request, response, exception);
return;
if (exception != null) {
instrumenter().end(context, request, response, exception);
return;
}

// Restlet suppresses exceptions and sets the throwable in status
Throwable statusThrowable = response.getStatus().getThrowable();

instrumenter().end(context, request, response, statusThrowable);
}
}

// Restlet suppresses exceptions and sets the throwable in status
Throwable statusThrowable = response.getStatus().getThrowable();
@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AdviceScope beginRequest(@Advice.Argument(0) Request request) {
return AdviceScope.start(request);
}

instrumenter().end(context, request, response, statusThrowable);
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void finishRequest(
@Advice.Argument(0) Request request,
@Advice.Argument(1) Response response,
@Advice.Thrown @Nullable Throwable exception,
@Advice.Enter @Nullable AdviceScope adviceScope) {
if (adviceScope != null) {
adviceScope.end(exception, request, response);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.Arrays;
import java.util.List;

@AutoService(InstrumentationModule.class)
public class RestletInstrumentationModule extends InstrumentationModule {
public class RestletInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {

public RestletInstrumentationModule() {
super("restlet", "restlet-2.0");
Expand All @@ -22,4 +24,9 @@ public RestletInstrumentationModule() {
public List<TypeInstrumentation> typeInstrumentations() {
return Arrays.asList(new ServerInstrumentation(), new RouteInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseCustomizerHolder;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand All @@ -44,54 +45,66 @@ public void transform(TypeTransformer transformer) {

@SuppressWarnings("unused")
public static class ServerHandleAdvice {
public static class AdviceScope {
private final Context context;
private final Scope scope;

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void beginRequest(
@Advice.Argument(0) Request request,
@Advice.Argument(1) Response response,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {

Context parentContext = currentContext();

if (!instrumenter().shouldStart(parentContext, request)) {
return;
private AdviceScope(Context context, Scope scope) {
this.context = context;
this.scope = scope;
}

context = instrumenter().start(parentContext, request);
scope = context.makeCurrent();
}
@Nullable
public static AdviceScope start(Request request) {
Context parentContext = currentContext();

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void finishRequest(
@Advice.Argument(0) Request request,
@Advice.Argument(1) Response response,
@Advice.Thrown Throwable exception,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
if (!instrumenter().shouldStart(parentContext, request)) {
return null;
}

if (scope == null) {
return;
Context context = instrumenter().start(parentContext, request);
return new AdviceScope(context, context.makeCurrent());
}

scope.close();
public void end(Throwable exception, Request request, Response response) {
scope.close();

if (Status.CLIENT_ERROR_NOT_FOUND.equals(response.getStatus())) {
HttpServerRoute.update(context, CONTROLLER, serverSpanName(), "/*");
}
if (Status.CLIENT_ERROR_NOT_FOUND.equals(response.getStatus())) {
HttpServerRoute.update(context, CONTROLLER, serverSpanName(), "/*");
}

HttpServerResponseCustomizerHolder.getCustomizer()
.customize(context, response, RestletResponseMutator.INSTANCE);
HttpServerResponseCustomizerHolder.getCustomizer()
.customize(context, response, RestletResponseMutator.INSTANCE);

if (exception != null) {
instrumenter().end(context, request, response, exception);
return;
if (exception != null) {
instrumenter().end(context, request, response, exception);
return;
}

// Restlet suppresses exceptions and sets the throwable in status
Throwable statusThrowable = response.getStatus().getThrowable();

instrumenter().end(context, request, response, statusThrowable);
}
}

// Restlet suppresses exceptions and sets the throwable in status
Throwable statusThrowable = response.getStatus().getThrowable();
@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AdviceScope beginRequest(
@Advice.Argument(0) Request request, @Advice.Argument(1) Response response) {
return AdviceScope.start(request);
}

instrumenter().end(context, request, response, statusThrowable);
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void finishRequest(
@Advice.Argument(0) Request request,
@Advice.Argument(1) Response response,
@Advice.Thrown @Nullable Throwable exception,
@Advice.Enter @Nullable AdviceScope adviceScope) {

if (adviceScope != null) {
adviceScope.end(exception, request, response);
}
}
}
}
Loading