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

The following examples show how to use net.bytebuddy.asm.Advice#This . 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: ClientCallImplInstrumentation.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
@Advice.OnMethodEnter(suppress = Throwable.class)
private static void onEnter(@Advice.This ClientCall<?, ?> clientCall,
                            @Advice.Argument(0) ClientCall.Listener<?> listener,
                            @Advice.Argument(1) Metadata headers,
                            @Advice.Local("span") Span span) {

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

    ElasticApmAgent.ensureInstrumented(listener.getClass(), RESPONSE_LISTENER_INSTRUMENTATIONS);

    GrpcHelper helper = grpcHelperManager.getForClassLoaderOfClass(ClientCall.class);
    if (helper != null) {
        span = helper.clientCallStartEnter(clientCall, listener, headers);
    }

}
 
Example 2
Source File: StatementInstrumentation.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class)
@SuppressWarnings("DuplicatedCode")
public static Span onBeforeExecute(@Advice.This Statement statement) {
    if (tracer == null || jdbcHelperManager == null) {
        return null;
    }
    JdbcHelper helper = jdbcHelperManager.getForClassLoaderOfClass(Statement.class);
    if (helper == null) {
        return null;
    }

    String sql = helper.retrieveSqlForStatement(statement);
    return helper.createJdbcSpan(sql, statement, tracer.getActive(), true);

}
 
Example 3
Source File: AbstractAsyncHttpClientInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodEnter(suppress = Throwable.class)
private static void onMethodEnter(@Advice.This AsyncHandler<?> asyncHandler, @Advice.Local("span") Span span, @Advice.Argument(0) HttpResponseStatus status) {
    span = handlerSpanMap.get(asyncHandler);
    if (span != null) {
        span.activate();
    }
}
 
Example 4
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 5
Source File: CodeTemplates.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Advice.OnMethodExit
static void exit(@Advice.This CompositeOwner self, @FieldName String fieldName, @FieldValue Object field) {
	if ( field != null ) {
		( (CompositeTracker) field ).$$_hibernate_setOwner( fieldName, self );
	}
	self.$$_hibernate_trackChange( fieldName );
}
 
Example 6
Source File: HttpUrlConnectionInstrumentation.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 afterDisconnect(@Advice.This HttpURLConnection thiz,
                                   @Nullable @Advice.Thrown Throwable t,
                                   @Advice.FieldValue("responseCode") int responseCode) {
    Span span = inFlightSpans.remove(thiz);
    if (span != null) {
        span.captureException(t).end();
    }
}
 
Example 7
Source File: FutureInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit(suppress = Throwable.class)
public static void onExit(@Advice.This Object thiz) {
    final AbstractSpan<?> context = getActive();
    if (context != null) {
        promisesToContext.put(thiz, context);
        // this span might be ended before the Promise$Transformation#run method starts
        // we have to avoid that this span gets recycled, even in the above mentioned case
        context.incrementReferences();
    }
}
 
Example 8
Source File: CodeTemplates.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Advice.OnMethodExit
static void exit(@Advice.This Object self, @Advice.Argument(0) Object argument, @MappedBy String mappedBy) {
	if ( argument != null && Hibernate.isPropertyInitialized( argument, mappedBy ) ) {
		Collection<Object> c = getter( argument );
		if ( c != null && !c.contains( self ) ) {
			c.add( self );
		}
	}
}
 
Example 9
Source File: ConnectionInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class)
public static Span onEnter(@Advice.This Connection thiz,
                           @Advice.Argument(0) MongoNamespace namespace,
                           @Advice.Origin("#m") String methodName) {
    Span span = ElasticApmInstrumentation.createExitSpan();

    if (span == null) {
        return null;
    }

    span.withType("db").withSubtype("mongodb")
        .getContext().getDb().withType("mongodb");
    span.getContext().getDestination().getService()
        .withName("mongodb").withResource("mongodb").withType("db");
    ServerAddress serverAddress = thiz.getDescription().getServerAddress();
    span.getContext().getDestination()
        .withAddress(serverAddress.getHost())
        .withPort(serverAddress.getPort());

    String command = methodName;
    if (methodName.equals("query")) {
        // if the method name is query, that corresponds to the find command
        command = "find";
    }
    span.withAction(command);
    StringBuilder spanName = span.getAndOverrideName(AbstractSpan.PRIO_DEFAULT);
    if (spanName != null) {
        int indexOfCommand = command.indexOf("Command");
        spanName.append(namespace.getDatabaseName())
            .append(".").append(namespace.getCollectionName())
            .append(".").append(command, 0, indexOfCommand > 0 ? indexOfCommand : command.length());
    }
    span.activate();
    return span;
}
 
Example 10
Source File: CodeTemplates.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Advice.OnMethodEnter
static void $$_hibernate_clearDirtyAttributes(
		@Advice.This ExtendedSelfDirtinessTracker self,
		@Advice.FieldValue(value = EnhancerConstants.TRACKER_FIELD_NAME, readOnly = false) DirtyTracker $$_hibernate_tracker) {
	if ( $$_hibernate_tracker != null ) {
		$$_hibernate_tracker.clear();
	}
	self.$$_hibernate_clearDirtyCollectionNames();
}
 
Example 11
Source File: SpringWebSocketAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodEnter
public static void enter(final @ClassName String className, final @Advice.Origin String origin, final @Advice.This Object thiz) {
  if (isAllowed(className, origin))
    SpringWebSocketAgentIntercept.messageChannelSend(thiz);
}
 
Example 12
Source File: AsyncHttpClientAgentRule.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.This Object thiz) {
  if (isAllowed(className, origin))
    AsyncHttpClientAgentIntercept.exit(thiz);
}
 
Example 13
Source File: HibernateSearch6Instrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodEnter(suppress = Throwable.class)
private static void onBeforeExecute(@Advice.This SearchQuery query,
                                    @Advice.Local("span") Span span,
                                    @Advice.Origin("#m") String methodName) {
    span = HibernateSearchHelper.createAndActivateSpan(tracer, methodName, query.getQueryString());
}
 
Example 14
Source File: ElasticsearchRestClientAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodEnter
public static void enter(final @ClassName String className, final @Advice.Origin String origin, final @Advice.This Object thiz, final @Advice.FieldValue(value = "httpClientConfigCallback") Object httpClientConfigCallback) {
  if (isAllowed(className, origin))
    ElasticsearchRestClientAgentIntercept.rest(thiz, httpClientConfigCallback);
}
 
Example 15
Source File: BufferAlignmentInterceptor.java    From agrona with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodEnter
public static void verifyAlignment(final int index, final @Advice.This DirectBuffer buffer)
{
    verifyAlignment(index, buffer, BitUtil.SIZE_OF_LONG);
}
 
Example 16
Source File: CxfWsClientAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodEnter
public static void enter(final @ClassName String className, final @Advice.Origin String origin, final @Advice.This Object thiz) {
  if (isAllowed(className, origin))
    CxfAgentIntercept.addClientTracingFeature(thiz);
}
 
Example 17
Source File: GoogleHttpClientAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodEnter
public static void enter(final @ClassName String className, final @Advice.Origin String origin, final @Advice.This Object thiz) {
  if (isAllowed(className, origin))
    GoogleHttpClientAgentIntercept.enter(thiz);
}
 
Example 18
Source File: SpringMessagingAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodEnter
public static void enter(final @ClassName String className, final @Advice.Origin String origin, final @Advice.This Object thiz) {
  if (isAllowed(className, origin))
    SpringMessagingAgentIntercept.enter(thiz);
}
 
Example 19
Source File: AkkaAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodEnter
public static void enter(final @ClassName String className, final @Advice.Origin String origin, final @Advice.This Object thiz, @Advice.Argument(value = 0, readOnly = false, typing = Typing.DYNAMIC) Object message, final @Advice.Argument(value = 1) Object sender) {
  if (isAllowed(className, origin))
    message = AkkaAgentIntercept.askStart(thiz, message, "tell", sender);
}
 
Example 20
Source File: ThreadInstrumentation.java    From opencensus-java with Apache License 2.0 3 votes vote down vote up
/**
 * Attaches the context that was previously saved for this thread.
 *
 * <p>NB: This method is never called as is. Instead, Byte Buddy copies the method's bytecode
 * into Thread#run.
 *
 * @see Advice
 */
@Advice.OnMethodEnter
@SuppressWarnings("unused")
@SuppressFBWarnings("UPM_UNCALLED_PRIVATE_METHOD")
private static void enter(@Advice.This Thread thread) {
  ContextTrampoline.attachContextForThread(thread);
}