Skip to content

Commit

Permalink
Merge branch 'master' into issue-1337-migrate-to-indy-jaxrs
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbarny authored Apr 14, 2021
2 parents b25b688 + a67d352 commit dce0ebc
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 148 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Even when matching on the main class name or on system properties,
[float]
===== Refactors
* Migrate some plugins to indy dispatcher {pull}1369[#1369] {pull}1374[#1374]
* Migrate some plugins to indy dispatcher {pull}1369[#1369] {pull}1410[#1410] {pull}1374[#1374]
[[release-notes-1.x]]
=== Java Agent version 1.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.opentracing.impl;
package co.elastic.apm.agent.opentracingimpl;

import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
Expand All @@ -38,11 +37,10 @@

public class ApmScopeInstrumentation extends OpenTracingBridgeInstrumentation {

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void release(@Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) @Nullable AbstractSpan<?> dispatcher) {
if (dispatcher != null) {
dispatcher.deactivate();
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void release(@Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) @Nullable Object context) {
if (context instanceof AbstractSpan<?>) {
((AbstractSpan<?>) context).deactivate();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.opentracing.impl;
package co.elastic.apm.agent.opentracingimpl;

import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.GlobalTracer;
import co.elastic.apm.agent.impl.sampling.ConstantSampler;
Expand Down Expand Up @@ -76,18 +75,21 @@ public CreateSpanInstrumentation() {

@Nullable
@AssignTo.Return
@Advice.OnMethodExit(suppress = Throwable.class)
public static Object createSpan(@Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) @Nullable AbstractSpan<?> parentContext,
@Advice.Origin Class<?> spanBuilderClass,
@Advice.FieldValue(value = "tags") Map<String, Object> tags,
@Advice.FieldValue(value = "operationName") String operationName,
@Advice.FieldValue(value = "microseconds") long microseconds,
@Advice.Argument(1) @Nullable Iterable<Map.Entry<String, String>> baggage) {
return doCreateTransactionOrSpan(parentContext, tags, operationName, microseconds, baggage, spanBuilderClass.getClassLoader());
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static Object createSpan(@Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) @Nullable Object parentContext,
@Advice.Origin Class<?> spanBuilderClass,
@Advice.FieldValue(value = "tags") Map<String, Object> tags,
@Advice.FieldValue(value = "operationName") String operationName,
@Advice.FieldValue(value = "microseconds") long microseconds,
@Advice.Argument(1) @Nullable Iterable<Map.Entry<String, String>> baggage) {
AbstractSpan<?> parent = null;
if (parentContext instanceof AbstractSpan<?>) {
parent = (AbstractSpan<?>) parentContext;
}
return doCreateTransactionOrSpan(parent, tags, operationName, microseconds, baggage, spanBuilderClass.getClassLoader());
}

@Nullable
@VisibleForAdvice
public static AbstractSpan<?> doCreateTransactionOrSpan(@Nullable AbstractSpan<?> parentContext,
Map<String, Object> tags,
String operationName, long microseconds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.opentracing.impl;
package co.elastic.apm.agent.opentracingimpl;

import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.impl.context.web.ResultUtil;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
Expand All @@ -47,7 +46,6 @@

public class ApmSpanInstrumentation extends OpenTracingBridgeInstrumentation {

@VisibleForAdvice
public static final Logger logger = LoggerFactory.getLogger(ApmSpanInstrumentation.class);

private final ElementMatcher<? super MethodDescription> methodMatcher;
Expand All @@ -71,15 +69,14 @@ public FinishInstrumentation() {
super(named("finishInternal"));
}

@Advice.OnMethodEnter(suppress = Throwable.class)
private static void finishInternal(@Advice.FieldValue(value = "dispatcher", typing = Assigner.Typing.DYNAMIC) @Nullable AbstractSpan<?> span,
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void finishInternal(@Advice.FieldValue(value = "dispatcher", typing = Assigner.Typing.DYNAMIC) @Nullable Object context,
@Advice.Argument(0) long finishMicros) {
if (span != null) {
doFinishInternal(span, finishMicros);
if (context instanceof AbstractSpan<?>) {
doFinishInternal((AbstractSpan<?>) context, finishMicros);
}
}

@VisibleForAdvice
public static void doFinishInternal(AbstractSpan<?> abstractSpan, long finishMicros) {
abstractSpan.incrementReferences();
if (abstractSpan instanceof Transaction) {
Expand Down Expand Up @@ -111,12 +108,11 @@ public SetOperationName() {
super(named("setOperationName"));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void setOperationName(@Advice.FieldValue(value = "dispatcher", typing = Assigner.Typing.DYNAMIC) @Nullable AbstractSpan<?> span,
public static void setOperationName(@Advice.FieldValue(value = "dispatcher", typing = Assigner.Typing.DYNAMIC) @Nullable Object context,
@Advice.Argument(0) @Nullable String operationName) {
if (span != null) {
span.withName(operationName, PRIO_USER_SUPPLIED);
if (context instanceof AbstractSpan<?>) {
((AbstractSpan<?>) context).withName(operationName, PRIO_USER_SUPPLIED);
} else {
logger.warn("Calling setOperationName on an already finished span");
}
Expand All @@ -128,13 +124,13 @@ public LogInstrumentation() {
super(named("log").and(takesArguments(long.class, Map.class)));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void log(@Advice.FieldValue(value = "dispatcher", typing = Assigner.Typing.DYNAMIC) @Nullable AbstractSpan<?> span,
public static void log(@Advice.FieldValue(value = "dispatcher", typing = Assigner.Typing.DYNAMIC) @Nullable Object context,
@Advice.Argument(0) long epochTimestampMicros,
@Advice.Argument(1) Map<String, ?> fields) {

if (span != null) {
if (context instanceof AbstractSpan<?>) {
AbstractSpan<?> span = (AbstractSpan<?>) context;
if ("error".equals(fields.get("event"))) {
final Object errorObject = fields.get("error.object");
if (errorObject instanceof Throwable) {
Expand All @@ -157,18 +153,17 @@ public TagInstrumentation() {
super(named("handleTag"));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void handleTag(@Advice.FieldValue(value = "dispatcher", typing = Assigner.Typing.DYNAMIC) @Nullable AbstractSpan<?> span,
public static void handleTag(@Advice.FieldValue(value = "dispatcher", typing = Assigner.Typing.DYNAMIC) @Nullable Object abstractSpanObj,
@Advice.Argument(0) String key,
@Advice.Argument(1) @Nullable Object value) {
if (value == null) {
return;
}
if (span instanceof Transaction) {
handleTransactionTag((Transaction) span, key, value);
} else if (span instanceof Span) {
handleSpanTag((Span) span, key, value);
if (abstractSpanObj instanceof Transaction) {
handleTransactionTag((Transaction) abstractSpanObj, key, value);
} else if (abstractSpanObj instanceof Span) {
handleSpanTag((Span) abstractSpanObj, key, value);
} else {
logger.warn("Calling setTag on an already finished span");
}
Expand Down Expand Up @@ -242,6 +237,7 @@ private static boolean handleSpecialTransactionTag(Transaction transaction, Stri
}

private static boolean handleSpecialSpanTag(Span span, String key, Object value) {
//noinspection IfCanBeSwitch
if ("type".equals(key)) {
if (span.getSubtype() == null && span.getAction() == null) {
span.setType(value.toString(), null, null);
Expand Down Expand Up @@ -306,9 +302,9 @@ public GetTraceContextInstrumentation() {

@Nullable
@AssignTo.Return
@Advice.OnMethodExit(suppress = Throwable.class)
public static Object getTraceContext(@Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) @Nullable AbstractSpan<?> abstractSpan) {
return abstractSpan;
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static Object getTraceContext(@Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) @Nullable Object abstractSpanObj) {
return abstractSpanObj;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.opentracing.impl;
package co.elastic.apm.agent.opentracingimpl;

import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
Expand All @@ -33,7 +33,7 @@

public class ElasticApmTracerInstrumentation extends OpenTracingBridgeInstrumentation {

@Advice.OnMethodExit(suppress = Throwable.class)
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static void close() {
tracer.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.opentracing.impl;
package co.elastic.apm.agent.opentracingimpl;

import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.GlobalTracer;
import co.elastic.apm.agent.impl.transaction.TraceContext;
Expand All @@ -34,8 +33,6 @@
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.implementation.bytecode.assign.Assigner;
import net.bytebuddy.matcher.ElementMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import java.util.Map;
Expand All @@ -44,8 +41,6 @@

public class ExternalSpanContextInstrumentation extends OpenTracingBridgeInstrumentation {

private static final Logger logger = LoggerFactory.getLogger(ExternalSpanContextInstrumentation.class);

private final ElementMatcher<? super MethodDescription> methodMatcher;

public ExternalSpanContextInstrumentation(ElementMatcher<? super MethodDescription> methodMatcher) {
Expand All @@ -70,11 +65,11 @@ public ToTraceIdInstrumentation() {

@Nullable
@AssignTo.Field(value = "childTraceContext")
@Advice.OnMethodEnter(suppress = Throwable.class)
public static TraceContext toTraceId(@Advice.FieldValue(value = "textMap", typing = Assigner.Typing.DYNAMIC) @Nullable Iterable<Map.Entry<String, String>> textMap,
@Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC) @Nullable TraceContext childTraceContext) {
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static Object toTraceId(@Advice.FieldValue(value = "textMap", typing = Assigner.Typing.DYNAMIC) @Nullable Iterable<Map.Entry<String, String>> textMap,
@Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC) @Nullable Object childTraceContextObj) {
if (textMap == null) {
return childTraceContext;
return childTraceContextObj;
}
return parseTextMap(textMap);

Expand All @@ -83,12 +78,12 @@ public static TraceContext toTraceId(@Advice.FieldValue(value = "textMap", typin

@Nullable
@AssignTo.Return
@Advice.OnMethodExit(suppress = Throwable.class)
public static String onExit(@Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC) @Nullable TraceContext childTraceContext) {
if (childTraceContext == null) {
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static String onExit(@Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC) @Nullable Object childTraceContextObj) {
if (!(childTraceContextObj instanceof TraceContext)) {
return null;
}
return childTraceContext.getTraceId().toString();
return ((TraceContext) childTraceContextObj).getTraceId().toString();
}
}

Expand All @@ -100,27 +95,26 @@ public ToSpanIdInstrumentation() {

@Nullable
@AssignTo.Field(value = "childTraceContext")
@Advice.OnMethodEnter(suppress = Throwable.class)
public static TraceContext toSpanId(@Advice.FieldValue(value = "textMap", typing = Assigner.Typing.DYNAMIC) @Nullable Iterable<Map.Entry<String, String>> textMap,
@Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC) @Nullable TraceContext childTraceContext) {
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static Object toSpanId(@Advice.FieldValue(value = "textMap", typing = Assigner.Typing.DYNAMIC) @Nullable Iterable<Map.Entry<String, String>> textMap,
@Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC) @Nullable Object childTraceContextObj) {
if (textMap == null) {
return childTraceContext;
return childTraceContextObj;
}
return parseTextMap(textMap);
}

@Nullable
@AssignTo.Return
@Advice.OnMethodExit(suppress = Throwable.class)
public static String onExit(@Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC) @Nullable TraceContext childTraceContext) {
if (childTraceContext == null) {
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static String onExit(@Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC) @Nullable Object childTraceContextObj) {
if (!(childTraceContextObj instanceof TraceContext)) {
return null;
}
return childTraceContext.getParentId().toString();
return ((TraceContext) childTraceContextObj).getParentId().toString();
}
}

@VisibleForAdvice
@Nullable
public static TraceContext parseTextMap(Iterable<Map.Entry<String, String>> textMap) {
ElasticApmTracer tracer = GlobalTracer.getTracerImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.opentracing.impl;
package co.elastic.apm.agent.opentracingimpl;

import co.elastic.apm.agent.bci.TracerAwareInstrumentation;

Expand All @@ -40,8 +40,4 @@ public Collection<String> getInstrumentationGroupNames() {
return Collections.singleton("opentracing");
}

@Override
public boolean indyPlugin() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.opentracing.impl;
package co.elastic.apm.agent.opentracingimpl;

import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.impl.transaction.TextHeaderGetter;
import co.elastic.apm.agent.impl.transaction.TextHeaderSetter;

import javax.annotation.Nullable;
import java.util.Map;

@VisibleForAdvice
public class OpenTracingTextMapBridge implements TextHeaderGetter<Iterable<Map.Entry<String, String>>>, TextHeaderSetter<Map<String, String>> {

private static final OpenTracingTextMapBridge INSTANCE = new OpenTracingTextMapBridge();

@VisibleForAdvice
public static OpenTracingTextMapBridge instance() {
return INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.opentracing.impl;
package co.elastic.apm.agent.opentracingimpl;

import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
Expand Down Expand Up @@ -61,11 +60,10 @@ public ActivateInstrumentation() {
super(named("doActivate"));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void doActivate(@Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) @Nullable AbstractSpan<?> span) {
if (span != null) {
span.activate();
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void doActivate(@Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) @Nullable Object context) {
if (context instanceof AbstractSpan<?>) {
((AbstractSpan<?>) context).activate();
}
}
}
Expand All @@ -78,8 +76,7 @@ public CurrentSpanInstrumentation() {

@Nullable
@AssignTo.Return
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static Object getCurrentSpan() {
return tracer.getActive();
}
Expand All @@ -94,8 +91,7 @@ public CurrentTraceContextInstrumentation() {

@Nullable
@AssignTo.Return
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static Object getCurrentTraceContext() {
return tracer.getActive();
}
Expand Down
Loading

0 comments on commit dce0ebc

Please sign in to comment.