Skip to content

Commit

Permalink
migrate to indy plugins api plugin (#1411)
Browse files Browse the repository at this point in the history
* migrate to indy plugins api plugin

Co-authored-by: kananindzya <[email protected]>
Co-authored-by: Sylvain Juge <[email protected]>
  • Loading branch information
3 people authored Nov 4, 2020
1 parent 71df6e4 commit 64fbb26
Show file tree
Hide file tree
Showing 20 changed files with 328 additions and 305 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ endif::[]
* Fix ignored runtime attach `config_file` {pull}1469[1469]
===== Refactors
* Migrate some plugins to indy dispatcher {pull}1404[1404]
* Migrate some plugins to indy dispatcher {pull}1404[1404] {pull}1411[1411]
[[release-notes-1.x]]
=== Java Agent version 1.x
Expand Down
3 changes: 2 additions & 1 deletion apm-agent-plugins/apm-api-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
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.plugin.api;
package co.elastic.apm.agent.pluginapi;

import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.Transaction;
Expand Down Expand Up @@ -69,11 +68,12 @@ public SetNameInstrumentation() {
super(named("doSetName"));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void setName(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void setName(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Argument(0) String name) {
context.withName(name, PRIO_USER_SUPPLIED);
if (context instanceof AbstractSpan<?>) {
((AbstractSpan<?>) context).withName(name, PRIO_USER_SUPPLIED);
}
}
}

Expand All @@ -82,9 +82,8 @@ public SetTypeInstrumentation() {
super(named("doSetType"));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void setType(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void setType(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Argument(0) String type) {
if (context instanceof Transaction) {
((Transaction) context).withType(type);
Expand All @@ -99,8 +98,7 @@ public SetTypesInstrumentation() {
super(named("doSetTypes"));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void setType(@Advice.Argument(0) Object span,
@Advice.Argument(1) @Nullable String type,
@Advice.Argument(2) @Nullable String subtype,
Expand All @@ -116,11 +114,16 @@ public DoCreateSpanInstrumentation() {
super(named("doCreateSpan"));
}

@VisibleForAdvice
@Nullable
@AssignTo.Return
@Advice.OnMethodExit(suppress = Throwable.class)
public static Span doCreateSpan(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context) {
return context.createSpan();
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static Object doCreateSpan(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Return @Nullable Object returnValue) {
if (context instanceof AbstractSpan<?>) {
return ((AbstractSpan<?>) context).createSpan();
} else {
return returnValue;
}
}
}

Expand All @@ -129,11 +132,12 @@ public SetStartTimestampInstrumentation() {
super(named("doSetStartTimestamp").and(takesArguments(long.class)));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void setStartTimestamp(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void setStartTimestamp(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Argument(value = 0) long epochMicros) {
context.setStartTimestamp(epochMicros);
if (context instanceof AbstractSpan<?>) {
((AbstractSpan<?>) context).setStartTimestamp(epochMicros);
}
}
}

Expand All @@ -142,10 +146,11 @@ public EndInstrumentation() {
super(named("end").and(takesArguments(0)));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void end(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context) {
context.end();
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void end(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context) {
if (context instanceof AbstractSpan<?>) {
((AbstractSpan<?>) context).end();
}
}
}

Expand All @@ -154,11 +159,12 @@ public EndWithTimestampInstrumentation() {
super(named("end").and(takesArguments(long.class)));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void end(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void end(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Argument(value = 0) long epochMicros) {
context.end(epochMicros);
if (context instanceof AbstractSpan<?>) {
((AbstractSpan<?>) context).end(epochMicros);
}
}
}

Expand All @@ -174,11 +180,15 @@ public CaptureExceptionInstrumentation() {

@Nullable
@AssignTo.Return
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static String captureException(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
@Advice.Argument(0) Throwable t) {
return context.captureExceptionAndGetErrorId(t);
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static String captureException(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Argument(0) Throwable t,
@Advice.Return String returnValue) {
if (context instanceof AbstractSpan<?>) {
return ((AbstractSpan<?>) context).captureExceptionAndGetErrorId(t);
} else {
return returnValue;
}
}
}

Expand All @@ -193,11 +203,12 @@ public LegacyCaptureExceptionInstrumentation() {
.and(returns(Void.class)));
}

@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static void captureException(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static void captureException(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Argument(0) Throwable t) {
context.captureException(t);
if (context instanceof AbstractSpan<?>) {
((AbstractSpan<?>) context).captureException(t);
}
}
}

Expand All @@ -207,10 +218,14 @@ public GetIdInstrumentation() {
}

@AssignTo.Return
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static String getId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context) {
return context.getTraceContext().getId().toString();
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static String getId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Return String returnValue) {
if (context instanceof AbstractSpan<?>) {
return ((AbstractSpan<?>) context).getTraceContext().getId().toString();
} else {
return returnValue;
}
}
}

Expand All @@ -220,10 +235,14 @@ public GetTraceIdInstrumentation() {
}

@AssignTo.Return
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static String getTraceId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context) {
return context.getTraceContext().getTraceId().toString();
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static String getTraceId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Return String returnValue) {
if (context instanceof AbstractSpan<?>) {
return ((AbstractSpan<?>) context).getTraceContext().getTraceId().toString();
} else {
return returnValue;
}
}
}

Expand All @@ -232,12 +251,11 @@ public AddStringLabelInstrumentation() {
super(named("doAddTag").or(named("doAddStringLabel")));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void addLabel(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void addLabel(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Argument(0) String key, @Nullable @Advice.Argument(1) String value) {
if (value != null) {
context.addLabel(key, value);
if (value != null && context instanceof AbstractSpan) {
((AbstractSpan<?>) context).addLabel(key, value);
}
}
}
Expand All @@ -247,12 +265,11 @@ public AddNumberLabelInstrumentation() {
super(named("doAddNumberLabel"));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void addLabel(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void addLabel(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Argument(0) String key, @Nullable @Advice.Argument(1) Number value) {
if (value != null) {
context.addLabel(key, value);
if (value != null && context instanceof AbstractSpan) {
((AbstractSpan<?>) context).addLabel(key, value);
}
}
}
Expand All @@ -262,12 +279,11 @@ public AddBooleanLabelInstrumentation() {
super(named("doAddBooleanLabel"));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void addLabel(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void addLabel(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Argument(0) String key, @Nullable @Advice.Argument(1) Boolean value) {
if (value != null) {
context.addLabel(key, value);
if (value != null && context instanceof AbstractSpan) {
((AbstractSpan<?>) context).addLabel(key, value);
}
}
}
Expand All @@ -277,10 +293,11 @@ public ActivateInstrumentation() {
super(named("activate"));
}

@VisibleForAdvice
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void activate(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context) {
context.activate();
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void activate(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context) {
if (context instanceof AbstractSpan<?>) {
((AbstractSpan<?>) context).activate();
}
}
}

Expand All @@ -290,10 +307,14 @@ public IsSampledInstrumentation() {
}

@AssignTo.Return
@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static boolean isSampled(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context) {
return context.isSampled();
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static boolean isSampled(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Return boolean returnValue) {
if (context instanceof AbstractSpan<?>) {
return ((AbstractSpan<?>) context).isSampled();
} else {
return returnValue;
}
}
}

Expand All @@ -303,13 +324,12 @@ public InjectTraceHeadersInstrumentation() {
super(named("doInjectTraceHeaders"));
}

@VisibleForAdvice
@Advice.OnMethodExit(suppress = Throwable.class)
public static void injectTraceHeaders(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context,
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static void injectTraceHeaders(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context,
@Advice.Argument(0) MethodHandle addHeaderMethodHandle,
@Advice.Argument(1) @Nullable Object headerInjector) throws Throwable {
if (headerInjector != null) {
context.propagateTraceContext(headerInjector, HeaderInjectorBridge.get(addHeaderMethodHandle));
@Advice.Argument(1) @Nullable Object headerInjector) {
if (headerInjector != null && context instanceof AbstractSpan) {
((AbstractSpan<?>) context).propagateTraceContext(headerInjector, HeaderInjectorBridge.get(addHeaderMethodHandle));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.plugin.api;
package co.elastic.apm.agent.pluginapi;

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

import java.util.Collection;
import java.util.Collections;

import static co.elastic.apm.agent.plugin.api.ElasticApmApiInstrumentation.PUBLIC_API_INSTRUMENTATION_GROUP;

public abstract class ApiInstrumentation extends TracerAwareInstrumentation {
@Override
public boolean includeWhenInstrumentationIsDisabled() {
Expand All @@ -39,11 +37,6 @@ public boolean includeWhenInstrumentationIsDisabled() {

@Override
public Collection<String> getInstrumentationGroupNames() {
return Collections.singleton(PUBLIC_API_INSTRUMENTATION_GROUP);
}

@Override
public boolean indyPlugin() {
return false;
return Collections.singleton(ElasticApmApiInstrumentation.PUBLIC_API_INSTRUMENTATION_GROUP);
}
}
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.plugin.api;
package co.elastic.apm.agent.pluginapi;

import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import net.bytebuddy.asm.Advice;
Expand All @@ -35,9 +35,11 @@

public class ApiScopeInstrumentation extends ApiInstrumentation {

@Advice.OnMethodEnter(suppress = Throwable.class)
private static void close(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) AbstractSpan<?> context) {
context.deactivate();
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void close(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context) {
if (context instanceof AbstractSpan) {
((AbstractSpan<?>) context).deactivate();
}
}

@Override
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.plugin.api;
package co.elastic.apm.agent.pluginapi;

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

public class CaptureExceptionInstrumentation extends ApiInstrumentation {

@Advice.OnMethodEnter(suppress = Throwable.class)
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void captureException(@Advice.Origin Class<?> clazz, @Advice.Argument(0) Throwable t) {
tracer.captureAndReportException(t, clazz.getClassLoader());
}
Expand Down
Loading

0 comments on commit 64fbb26

Please sign in to comment.