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

The following examples show how to use net.bytebuddy.asm.Advice#Enter . 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: StatementInstrumentation.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
public static void onAfterExecute(@Advice.Enter @Nullable Span span,
                                  @Advice.Thrown @Nullable Throwable t,
                                  @Advice.Return long returnValue /* bytebuddy converts int to long for us here ! */) {
    if (span == null) {
        return;
    }

    if (t == null) {
        span.getContext()
            .getDb()
            .withAffectedRowsCount(returnValue);
    }

    span.captureException(t)
        .deactivate()
        .end();
}
 
Example 2
Source File: StatementInstrumentation.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
public static void onAfterExecute(@Advice.Enter @Nullable Span span,
                                  @Advice.Thrown @Nullable Throwable t,
                                  @Advice.Return long returnValue /* bytebuddy converts int to long for us here ! */) {
    if (span == null) {
        return;
    }

    if (t == null) {
        span.getContext()
            .getDb()
            .withAffectedRowsCount(returnValue);
    }

    span.captureException(t)
        .deactivate()
        .end();
}
 
Example 3
Source File: RunnableCallableForkJoinTaskInstrumentation.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.Enter AbstractSpan<?> span) {
    if (span != null) {
        span.deactivate();
    }
}
 
Example 4
Source File: StatementInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
public static void onAfterExecute(@Advice.This Statement statement,
                                  @Advice.Enter @Nullable Span span,
                                  @Advice.Thrown @Nullable Throwable t) {
    if (span == null) {
        return;
    }

    span.captureException(t)
        .deactivate()
        .end();

}
 
Example 5
Source File: StatementInstrumentation.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 onAfterExecute(@Advice.This Statement statement,
                                  @Advice.Enter @Nullable Span span,
                                  @Advice.Thrown @Nullable Throwable t) {

    if (span == null) {
        return;
    }

    span.captureException(t)
        .deactivate()
        .end();
}
 
Example 6
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 7
Source File: KafkaConsumerInstrumentation.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 pollEnd(@Advice.Enter @Nullable final Span span,
                           @Advice.Thrown final Throwable throwable) {

    if (span != null) {
        span.captureException(throwable);
        span.deactivate().end();
    }
}
 
Example 8
Source File: JmsMessageListenerInstrumentation.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 afterOnMessage(@Advice.Enter @Nullable final Transaction transaction,
                                  @Advice.Thrown final Throwable throwable) {

    if (transaction != null) {
        transaction.captureException(throwable);
        transaction.deactivate().end();
    }
}
 
Example 9
Source File: JmsMessageProducerInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void afterSend(@Advice.Enter @Nullable final Span span,
                             @Advice.Thrown final Throwable throwable) {

    if (span != null) {
        span.captureException(throwable);
        span.deactivate().end();
    }
}
 
Example 10
Source File: JmsMessageProducerInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void endSpan(@Advice.Enter @Nullable final Span span,
                           @Advice.Thrown final Throwable throwable) {

    if (span != null) {
        span.captureException(throwable);
        span.deactivate().end();
    }
}
 
Example 11
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 12
Source File: ConnectionAdvice.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, @Advice.Origin("#m") String methodName) {
    if (span != null) {
        span.deactivate().captureException(thrown);
        if (!methodName.endsWith("Async")) {
            span.end();
        }
    }
}
 
Example 13
Source File: AllowancesByteBuddyTransformer.java    From BlockHound with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class)
static void onExit(
        @Advice.Enter BlockHoundRuntime.State previousState,
        @AllowancesByteBuddyTransformer.AllowedArgument boolean allowed
) {
    if (previousState != null) {
        previousState.setAllowed(!allowed);
    }
}
 
Example 14
Source File: JmsMessageConsumerInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void afterReceive(@Advice.Origin Class<?> clazz,
                                @Advice.Origin("#m") String methodName,
                                @Advice.Enter @Nullable final AbstractSpan abstractSpan,
                                @Advice.Return @Nullable final Message message,
                                @Advice.Thrown final Throwable throwable) {

    //noinspection ConstantConditions
    JmsInstrumentationHelper<Destination, Message, MessageListener> helper =
        jmsInstrHelperManager.getForClassLoaderOfClass(MessageListener.class);

    Destination destination = null;
    String destinationName = null;
    boolean discard = false;
    boolean addDetails = true;
    if (message != null) {
        try {
            destination = message.getJMSDestination();
            if (helper != null) {
                destinationName = helper.extractDestinationName(message, destination);
                discard = helper.ignoreDestination(destinationName);
            }
        } catch (JMSException e) {
            logger.error("Failed to retrieve meta info from Message", e);
        }

        if (abstractSpan instanceof Transaction) {
            Transaction transaction = (Transaction) abstractSpan;
            if (discard) {
                transaction.ignoreTransaction();
            } else if (helper != null) {
                helper.makeChildOf(transaction, message);
                transaction.withType(MESSAGING_TYPE);
                helper.addMessageDetails(message, abstractSpan);
            }
        }
    } else if (abstractSpan instanceof Transaction) {
        // Do not report polling transactions if not yielding messages
        ((Transaction) abstractSpan).ignoreTransaction();
        addDetails = false;
    }

    if (abstractSpan != null) {
        try {
            if (discard) {
                abstractSpan.requestDiscarding();
            } else if (addDetails) {
                if (message != null && helper != null && destinationName != null) {
                    abstractSpan.appendToName(" from ");
                    helper.addDestinationDetails(message, destination, destinationName, abstractSpan);
                    helper.setMessageAge(message, abstractSpan);
                }
                abstractSpan.captureException(throwable);
            }
        } finally {
            abstractSpan.deactivate().end();
        }
    }

    if (!discard && tracer != null && tracer.currentTransaction() == null && helper != null
        && message != null && messagingConfiguration != null
        && messagingConfiguration.getMessagePollingTransactionStrategy() != MessagingConfiguration.Strategy.POLLING
        && !"receiveNoWait".equals(methodName)) {

        Transaction messageHandlingTransaction = helper.startJmsTransaction(message, clazz);
        if (messageHandlingTransaction != null) {
            messageHandlingTransaction.withType(MESSAGE_HANDLING)
                .withName(RECEIVE_NAME_PREFIX);

            if (destinationName != null) {
                messageHandlingTransaction.appendToName(" from ");
                helper.addDestinationDetails(message, destination, destinationName, messageHandlingTransaction);
                helper.addMessageDetails(message, messageHandlingTransaction);
                helper.setMessageAge(message, messageHandlingTransaction);
            }

            messageHandlingTransaction.activate();
        }
    }
}
 
Example 15
Source File: UrlInstrumentation.java    From opencensus-java with Apache License 2.0 3 votes vote down vote up
/**
 * Closes the current span and scope when exiting the method.
 *
 * <p>NB: This method is never called as is. Instead, Byte Buddy copies the method's bytecode
 * into Executor#execute.
 *
 * <p>NB: By default, any {@link Throwable} thrown during the advice's execution is silently
 * suppressed.
 *
 * @see Advice
 */
@Advice.OnMethodExit(onThrowable = Throwable.class)
@SuppressWarnings("unused")
@SuppressFBWarnings("UPM_UNCALLED_PRIVATE_METHOD")
private static void exit(@Advice.Enter Closeable scope, @Advice.Thrown Throwable throwable) {
  TraceTrampoline.endScope(scope, throwable);
}