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

The following examples show how to use net.bytebuddy.asm.Advice#FieldValue . 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: ExternalSpanContextInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("Duplicates")
@Advice.OnMethodExit(suppress = Throwable.class)
public static void toSpanId(@Advice.FieldValue(value = "textMap", typing = Assigner.Typing.DYNAMIC) @Nullable Iterable<Map.Entry<String, String>> textMap,
                            @Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC, readOnly = false) @Nullable TraceContext childTraceContext,
                            @Advice.Return(readOnly = false) String spanId) {
    if (textMap != null && childTraceContext == null) {
        childTraceContext = parseTextMap(textMap);
    }
    if (childTraceContext != null) {
        spanId = childTraceContext.getParentId().toString();
    }
}
 
Example 2
Source File: AbstractSpanInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static void captureException(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
                                    @Advice.Argument(0) Throwable t,
                                    @Advice.Return(readOnly = false) String errorId) {
    errorId = context.captureExceptionAndGetErrorId(t);
}
 
Example 3
Source File: SpanContextInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodExit(suppress = Throwable.class)
public static void toTraceId(@Advice.FieldValue(value = "traceContext", typing = Assigner.Typing.DYNAMIC) @Nullable AbstractSpan<?> traceContext,
                             @Advice.Return(readOnly = false) String traceId) {
    if (traceContext != null) {
        traceId = traceContext.getTraceContext().getTraceId().toString();
    }
}
 
Example 4
Source File: CodeTemplates.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Advice.OnMethodEnter
static void $$_hibernate_setOwner(
		@Advice.Argument(0) String name,
		@Advice.FieldValue(value = EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME, readOnly = false) CompositeOwnerTracker $$_hibernate_compositeOwners) {
	if ( $$_hibernate_compositeOwners != null ) {
		$$_hibernate_compositeOwners.removeOwner( name );
	}
}
 
Example 5
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 6
Source File: OkHttp3ClientInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodEnter(suppress = Throwable.class)
private static void onBeforeExecute( @Advice.FieldValue(value = "originalRequest", typing = Assigner.Typing.DYNAMIC, readOnly = false) @Nullable Object originalRequest,
                                     @Advice.Local("span") Span span) {

    if (tracer == null || tracer.getActive() == null) {
        return;
    }

    if (originalRequest == null) {
        return;
    }

    final AbstractSpan<?> parent = tracer.getActive();

    if (originalRequest instanceof okhttp3.Request) {
        okhttp3.Request request = (okhttp3.Request) originalRequest;
        HttpUrl url = request.url();
        span = HttpClientHelper.startHttpClientSpan(parent, request.method(), url.toString(), url.scheme(),
            OkHttpClientHelper.computeHostName(url.host()), url.port());
        if (span != null) {
            span.activate();
            if (headerSetterHelperManager != null) {
                TextHeaderSetter<Request.Builder> headerSetter = headerSetterHelperManager.getForClassLoaderOfClass(Request.class);
                if (headerSetter != null) {
                    Request.Builder builder = ((okhttp3.Request) originalRequest).newBuilder();
                    span.propagateTraceContext(builder, headerSetter);
                    originalRequest = builder.build();
                }
            }
        }
    }
}
 
Example 7
Source File: OkHttpClientInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodEnter(suppress = Throwable.class)
private static void onBeforeExecute(@Advice.FieldValue(value = "originalRequest", typing = Assigner.Typing.DYNAMIC, readOnly = false) @Nullable Object originalRequest,
                                    @Advice.Local("span") Span span) {

    if (tracer == null || tracer.getActive() == null) {
        return;
    }
    final AbstractSpan<?> parent = tracer.getActive();

    if (originalRequest == null) {
        return;
    }

    if (originalRequest instanceof com.squareup.okhttp.Request) {
        com.squareup.okhttp.Request request = (com.squareup.okhttp.Request) originalRequest;
        HttpUrl httpUrl = request.httpUrl();
        span = HttpClientHelper.startHttpClientSpan(parent, request.method(), httpUrl.toString(), httpUrl.scheme(),
            OkHttpClientHelper.computeHostName(httpUrl.host()), httpUrl.port());
        if (span != null) {
            span.activate();
            if (headerSetterHelperManager != null) {
                TextHeaderSetter<Request.Builder> headerSetter = headerSetterHelperManager.getForClassLoaderOfClass(Request.class);
                if (headerSetter != null) {
                    Request.Builder builder = ((com.squareup.okhttp.Request) originalRequest).newBuilder();
                    span.propagateTraceContext(builder, headerSetter);
                    originalRequest = builder.build();
                }
            }
        }
    }
}
 
Example 8
Source File: AbstractSpanInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static void injectTraceHeaders(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
                                      @Advice.Argument(0) MethodHandle addHeaderMethodHandle,
                                      @Advice.Argument(1) @Nullable Object headerInjector) throws Throwable {
    if (headerInjector != null) {
        context.propagateTraceContext(headerInjector, HeaderInjectorBridge.get(addHeaderMethodHandle));
    }
}
 
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_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 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: LegacySpanInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodEnter
public static void addTag(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> span) {
    span.activate();
}
 
Example 12
Source File: CodeTemplates.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Advice.OnMethodExit
static void $$_hibernate_hasDirtyAttributes(
		@Advice.Return(readOnly = false) boolean returned,
		@Advice.FieldValue(value = EnhancerConstants.TRACKER_FIELD_NAME) DirtyTracker $$_hibernate_tracker) {
	returned = $$_hibernate_tracker != null && !$$_hibernate_tracker.isEmpty();
}
 
Example 13
Source File: LegacySpanInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodExit
public static void doCreateSpan(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> span,
                                @Advice.Argument(0) Throwable t) {
    span.captureException(t);
}
 
Example 14
Source File: AbstractSpanInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void setName(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
                           @Advice.Argument(0) String name) {
    context.withName(name, PRIO_USER_SUPPLIED);
}
 
Example 15
Source File: AbstractSpanInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
                         @Advice.Return(readOnly = false) String id) {
    id = context.getTraceContext().getId().toString();
}
 
Example 16
Source File: AbstractSpanInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static void doCreateSpan(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
                                @Advice.Return(readOnly = false) Object result) {
    result = context.createSpan();
}
 
Example 17
Source File: AbstractSpanInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static void isSampled(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
                             @Advice.Return(readOnly = false) boolean sampled) {
    sampled = context.isSampled();
}
 
Example 18
Source File: CodeTemplates.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Advice.OnMethodEnter
static void enter(@Advice.FieldValue(EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME) CompositeOwnerTracker $$_hibernate_compositeOwners) {
	if ( $$_hibernate_compositeOwners != null ) {
		$$_hibernate_compositeOwners.callOwner( "" );
	}
}
 
Example 19
Source File: LegacySpanInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodExit
public static void doCreateSpan(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> span,
                                @Advice.Return(readOnly = false) Object result) {
    result = span.createSpan();
}
 
Example 20
Source File: LegacySpanInstrumentation.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@VisibleForAdvice
@Advice.OnMethodEnter
public static void setName(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> span,
                           @Advice.Argument(0) String name) {
    span.withName(name, PRIO_USER_SUPPLIED);
}