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

The following examples show how to use net.bytebuddy.asm.Advice#OnMethodExit . 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) {
        return;
    }

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

    helper.exitServerListenerMethod(thrown, listener, transaction, true);
}
 
Example 2
Source File: CodeTemplates.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Advice.OnMethodExit
static void $$_hibernate_getDirtyAttributes(
		@Advice.This ExtendedSelfDirtinessTracker self,
		@Advice.Return(readOnly = false) String[] returned,
		@Advice.FieldValue(value = EnhancerConstants.TRACKER_FIELD_NAME, readOnly = false) DirtyTracker $$_hibernate_tracker,
		@Advice.FieldValue(value = EnhancerConstants.TRACKER_COLLECTION_NAME, readOnly = false) CollectionTracker $$_hibernate_collectionTracker) {
	if ( $$_hibernate_collectionTracker == null ) {
		returned = ( $$_hibernate_tracker == null ) ? new String[0] : $$_hibernate_tracker.get();
	}
	else {
		if ( $$_hibernate_tracker == null ) {
			$$_hibernate_tracker = new SimpleFieldTracker();
		}
		self.$$_hibernate_getCollectionFieldDirtyNames( $$_hibernate_tracker );
		returned = $$_hibernate_tracker.get();
	}
}
 
Example 3
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 4
Source File: CachedReturnPlugin$short.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * The exit advice.
 *
 * @param returned The value that was returned by the method's execution or {@code 0} if it was not executed.
 * @param cached   The previously cached value or {@code 0} if no previous value exists.
 */
@Advice.OnMethodExit
@SuppressFBWarnings(value = {"UC_USELESS_VOID_METHOD", "DLS_DEAD_LOCAL_STORE"}, justification = "Advice method serves as a template")
protected static void exit(@Advice.Return(readOnly = false) short returned, @CachedReturnPlugin.CacheField short cached) {
    if (returned == 0) {
        returned = cached;
    } else {
        cached = returned;
    }
}
 
Example 5
Source File: CodeTemplates.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Advice.OnMethodExit
static void $$_hibernate_areCollectionFieldsDirty(
		@Advice.Return(readOnly = false) boolean returned,
		@FieldName String fieldName,
		@FieldValue Map<?, ?> map,
		@Advice.FieldValue(EnhancerConstants.TRACKER_COLLECTION_NAME) CollectionTracker $$_hibernate_collectionTracker) {
	if ( !returned && $$_hibernate_collectionTracker != null ) {
		if ( map == null && $$_hibernate_collectionTracker.getSize( fieldName ) != -1 ) {
			returned = true;
		}
		else if ( map != null && $$_hibernate_collectionTracker.getSize( fieldName ) != map.size() ) {
			returned = true;
		}
	}
}
 
Example 6
Source File: ConsumerRecordsIteratorInstrumentation.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 wrapIterator(@Nullable @Advice.Return(readOnly = false) Iterator<ConsumerRecord> iterator) {
    if (tracer == null || !tracer.isRunning() || tracer.currentTransaction() != null) {
        return;
    }

    //noinspection ConstantConditions,rawtypes
    KafkaInstrumentationHeadersHelper<ConsumerRecord, ProducerRecord> kafkaInstrumentationHelper =
        kafkaInstrHeadersHelperManager.getForClassLoaderOfClass(KafkaProducer.class);
    if (iterator != null && kafkaInstrumentationHelper != null) {
        iterator = kafkaInstrumentationHelper.wrapConsumerRecordIterator(iterator);
    }
}
 
Example 7
Source File: ElasticsearchClientSyncInstrumentation.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.Return @Nullable Response response,
                                  @Advice.Local("span") @Nullable Span span,
                                  @Advice.Local("helper") @Nullable ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper,
                                  @Advice.Thrown @Nullable Throwable t) {
    if (helper != null && span != null) {
        try {
            helper.finishClientSpan(response, span, t);
        } finally {
            span.deactivate();
        }
    }
}
 
Example 8
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 9
Source File: CodeTemplates.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Advice.OnMethodExit
static void $$_hibernate_clearDirtyCollectionNames(
		@FieldName String fieldName,
		@FieldValue Collection<?> collection,
		@Advice.Argument(0) LazyAttributeLoadingInterceptor lazyInterceptor,
		@Advice.FieldValue(EnhancerConstants.TRACKER_COLLECTION_NAME) CollectionTracker $$_hibernate_collectionTracker) {
	if ( lazyInterceptor == null || lazyInterceptor.isAttributeLoaded( fieldName ) ) {
		if ( collection == null ) {
			$$_hibernate_collectionTracker.add( fieldName, -1 );
		}
		else {
			$$_hibernate_collectionTracker.add( fieldName, collection.size() );
		}
	}
}
 
Example 10
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 11
Source File: CodeTemplates.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Advice.OnMethodExit
static void $$_hibernate_hasDirtyAttributes(
		@Advice.This ExtendedSelfDirtinessTracker self,
		@Advice.Return(readOnly = false) boolean returned,
		@Advice.FieldValue(value = EnhancerConstants.TRACKER_FIELD_NAME, readOnly = false) DirtyTracker $$_hibernate_tracker) {
	returned = ( $$_hibernate_tracker != null && !$$_hibernate_tracker.isEmpty() ) || self.$$_hibernate_areCollectionFieldsDirty();
}
 
Example 12
Source File: ScheduledTransactionNameInstrumentation.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(@Nullable @Advice.Local("transaction") Transaction transaction,
                                @Advice.Thrown Throwable t) {
    if (transaction != null) {
        transaction.captureException(t)
            .deactivate()
            .end();
    }
}
 
Example 13
Source File: EventProducerAdvice.java    From webtester2-core with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit
public static void onMethodExit(@Advice.This PageFragment pageFragment, @Advice.Origin Method method) {
    try {
        EventProducerImpl impl = THREAD_LOCAL.get();
        if (impl != null) {
            impl.onMethodExit();
        }
    } finally {
        THREAD_LOCAL.remove();

    }
}
 
Example 14
Source File: FilterChainAgentRule.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) Object returned, @Advice.Thrown(readOnly = false, typing = Typing.DYNAMIC) Throwable thrown) {
  if (thrown instanceof EarlyReturnException) {
    returned = ((EarlyReturnException)thrown).getReturnValue();
    thrown = null;
  }
}
 
Example 15
Source File: ThriftAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit
public static void exit(final @ClassName String className, final @Advice.Origin String origin) {
  if (isAllowed(className, origin))
    ThriftAgentIntercept.onComplete();
}
 
Example 16
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,
                           @Advice.Argument(value = 0) @Nullable Runnable runnable) {
    JavaConcurrent.doFinally(thrown, runnable);
}
 
Example 17
Source File: InstrumentationTest.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit
public static void onMethodExit() {
    throw new RuntimeException("This exception should not be suppressed");
}
 
Example 18
Source File: InstrumentationTest.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit
public static void onMethodExit(@Advice.Return(readOnly = false) int returnValue) {
    returnValue = 42;
}
 
Example 19
Source File: ThriftProtocolAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit
public static void exit(final @ClassName String className, final @Advice.Origin String origin) {
  if (isAllowed(className, origin))
    ThriftProtocolAgentIntercept.readMessageEnd();
}
 
Example 20
Source File: KafkaStreamsAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit
public static void exit(final @ClassName String className, final @Advice.Origin String origin, final @Advice.Return Object returned, final @Advice.Argument(value = 1) Object record) {
  if (isAllowed(className, origin))
    KafkaStreamsAgentIntercept.onDeserializeExit(returned, record);
}