Java Code Examples for net.bytebuddy.asm.Advice#Thrown

The following examples show how to use net.bytebuddy.asm.Advice#Thrown . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerCallListenerInstrumentation.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
private static void onExit(@Advice.Thrown @Nullable Throwable thrown,
                           @Advice.This ServerCall.Listener<?> listener,
                           @Advice.Local("transaction") @Nullable Transaction transaction) {

    if (null == tracer || grpcHelperManager == null || transaction == null) {
        return;
    }

    GrpcHelper helper = grpcHelperManager.getForClassLoaderOfClass(ServerCall.Listener.class);
    if (helper == null) {
        return;
    }

    helper.exitServerListenerMethod(thrown, listener, transaction, false);
}
 
Example 2
Source File: KafkaProducerInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void afterSend(@Advice.Enter @Nullable final Span span,
                             @Advice.Argument(0) final ProducerRecord record,
                             @Advice.This final KafkaProducer thiz,
                             @Advice.Local("helper") @Nullable KafkaInstrumentationHelper<Callback, ProducerRecord, KafkaProducer> helper,
                             @Advice.Thrown final Throwable throwable) {

    if (helper != null && span != null) {
        helper.onSendEnd(span, record, thiz, throwable);
    }
}
 
Example 3
Source File: ClassLoaderAgent.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
    @Advice.OnMethodExit(onThrowable = ClassNotFoundException.class)
    public static void exit(final @Advice.This ClassLoader thiz, final @Advice.Argument(0) String name, @Advice.Return(readOnly=false, typing=Typing.DYNAMIC) Class<?> returned, @Advice.Thrown(readOnly = false, typing = Typing.DYNAMIC) ClassNotFoundException thrown) {
      if (returned != null || isExcluded(thiz))
        return;

      final Set<String> visited;
      if (!(visited = mutex.get()).add(name))
        return;

      try {
        final Class<?> bootstrapClass = BootProxyClassLoader.INSTANCE.loadClassOrNull(name, false);
        if (bootstrapClass != null) {
//          log(">>>>>>>> BootLoader#loadClassOrNull(\"" + name + "\"): " + bootstrapClass, null, DefaultLevel.FINEST);

          returned = bootstrapClass;
          thrown = null;
          return;
        }

        final byte[] bytecode = SpecialAgent.findClass(thiz, name);
        if (bytecode == null)
          return;

//        log("<<<<<<<< defineClass(\"" + name + "\")", null, DefaultLevel.FINEST);

        if (defineClass == null)
          defineClass = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class, ProtectionDomain.class);

        returned = (Class<?>)defineClass.invoke(thiz, name, bytecode, 0, bytecode.length, null);
        thrown = null;
      }
      catch (final Throwable t) {
        log("<><><><> ClassLoaderAgent.LoadClass#exit(\"" + name + "\")", t, DefaultLevel.SEVERE);
      }
      finally {
        visited.remove(name);
      }
    }
 
Example 4
Source File: JdbcAgentRule.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(@Advice.Return(readOnly = false, typing = Typing.DYNAMIC) Boolean returned, @Advice.Thrown(readOnly = false, typing = Typing.DYNAMIC) Throwable thrown) {
  if (thrown instanceof EarlyReturnException) {
    thrown = null;
    returned = Boolean.TRUE;
  }
}
 
Example 5
Source File: ConnectionInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
public static void onExit(@Nullable @Advice.Enter Span span, @Advice.Thrown Throwable thrown) {
    if (span != null) {
        span.deactivate().captureException(thrown);
        span.end();
    }
}
 
Example 6
Source File: JdbcAgentRule.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(@Advice.Return(readOnly = false, typing = Typing.DYNAMIC) Object returned, @Advice.Thrown(readOnly = false, typing = Typing.DYNAMIC) Throwable thrown) throws Exception {
  if (thrown instanceof EarlyReturnException) {
    returned = WrapperProxy.wrap(returned, ((EarlyReturnException)thrown).getReturnValue());
    thrown = null;
  }
}
 
Example 7
Source File: TraceMethodInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
public static void onMethodExit(@Advice.Local("span") @Nullable AbstractSpan<?> span,
                                @Advice.Thrown @Nullable Throwable t) {
    if (span != null) {
        span.captureException(t);
        final long endTime = span.getTraceContext().getClock().getEpochMicros();
        if (span instanceof Span) {
            long durationMicros = endTime - span.getTimestamp();
            if (traceMethodThresholdMicros > 0 && durationMicros < traceMethodThresholdMicros && t == null) {
                span.requestDiscarding();
            }
        }
        span.deactivate().end(endTime);
    }
}
 
Example 8
Source File: ClientCallImplInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
private static void onExit(@Advice.Argument(0) ClientCall.Listener<?> listener,
                           @Advice.Thrown @Nullable Throwable thrown,
                           @Advice.Local("span") @Nullable Span span) {

    if (span == null) {
        return;
    }
    GrpcHelper helper = grpcHelperManager.getForClassLoaderOfClass(ClientCall.class);
    if (helper != null) {
        helper.clientCallStartExit(listener, thrown);
    }
}
 
Example 9
Source File: AlibabaResponseCallbackInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
private static void onExit(@Advice.Thrown Throwable thrown,
                           @Nullable @Advice.Local("span") AbstractSpan<?> span,
                           @Nullable @Advice.Argument(0) Object response) {
    if (span == null) {
        return;
    }
    if (response instanceof Result) {
        span.captureException(((Result) response).getException());
    }
    span.captureException(thrown).deactivate().end();
}
 
Example 10
Source File: AsyncInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Exception.class)
private static void onExitAsyncContextStart(@Nullable @Advice.Thrown Throwable thrown,
                                            @Advice.Argument(value = 0) @Nullable Runnable runnable) {
    JavaConcurrent.doFinally(thrown, runnable);
}
 
Example 11
Source File: HttpURLConnectionAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(final @ClassName String className, final @Advice.Origin String origin, final @Advice.Thrown Throwable thrown, @Advice.FieldValue("responseCode") final int responseCode) {
  if (isAllowed(className, origin))
    HttpURLConnectionAgentIntercept.exit(thrown, responseCode);
}
 
Example 12
Source File: SpymemcachedAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(final @Advice.Thrown Throwable thrown, final @Advice.Argument(value = 5) Object callback) {
  if (thrown != null)
    SpymemcachedAgentIntercept.exception(thrown, callback);
}
 
Example 13
Source File: PlayAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(final @ClassName String className, final @Advice.Origin String origin, final @Advice.This Object thiz, final @Advice.Return Object returned, final @Advice.Thrown Throwable thrown) {
  if (isAllowed(className, origin))
    PlayAgentIntercept.applyEnd(thiz, returned, thrown);
}
 
Example 14
Source File: RabbitMQAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(final @ClassName String className, final @Advice.Origin String origin, final @Advice.Thrown Throwable thrown) {
  if (isAllowed(className, origin))
    RabbitMQAgentIntercept.finish(thrown);
}
 
Example 15
Source File: ExecutorInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
private static void onExit(@Nullable @Advice.Thrown Throwable thrown,
                           @Nullable @Advice.Argument(0) Collection<? extends Callable<?>> callables) {
    JavaConcurrent.doFinally(thrown, callables);
}
 
Example 16
Source File: FilterAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(@Advice.Thrown(readOnly = false, typing = Typing.DYNAMIC) Throwable thrown) {
  if (thrown instanceof EarlyReturnException)
    thrown = null;
}
 
Example 17
Source File: HttpClientAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(final @Advice.Thrown Throwable thrown) {
  if (thrown != null)
    HttpClientAgentIntercept.onError(thrown);
}
 
Example 18
Source File: SpymemcachedAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(final @Advice.Thrown Throwable thrown, final @Advice.Argument(value = 1, typing = Typing.DYNAMIC) Object callback) {
  if (thrown != null)
    SpymemcachedAgentIntercept.exception(thrown, callback);
}
 
Example 19
Source File: AkkaAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(final @ClassName String className, final @Advice.Origin String origin, final @Advice.Argument(value = 0) Object actorRef, final @Advice.Argument(value = 1) Object message, final @Advice.Thrown Throwable thrown) {
  if (isAllowed(className, origin))
    AkkaAgentIntercept.askEnd(actorRef, message, thrown, null);
}
 
Example 20
Source File: SpymemcachedAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void exit(final @Advice.Thrown Throwable thrown, final @Advice.Argument(value = 4) Object callback) {
  if (thrown != null)
    SpymemcachedAgentIntercept.exception(thrown, callback);
}