forked from DataDog/dd-trace-java
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from GuanceCloud/liurui
add rhinojs (version:1.7.0) #101
- Loading branch information
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
muzzle { | ||
pass { | ||
group = "org.mozilla" | ||
module = "rhino" | ||
versions = "[1.7.0,)" | ||
assertInverse = true | ||
} | ||
} | ||
|
||
apply from: "$rootDir/gradle/java.gradle" | ||
|
||
dependencies { | ||
compileOnly group: 'org.mozilla', name: 'rhino', version: '1.7.10' | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
.../instrumentation/rhino/src/main/java/datadog/trace/instrumentation/rhino/RhinoAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package datadog.trace.instrumentation.rhino; | ||
|
||
import datadog.trace.bootstrap.instrumentation.api.AgentScope; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan; | ||
import static datadog.trace.instrumentation.rhino.RhinoDecorator.DECORATOR; | ||
|
||
public class RhinoAdvice { | ||
|
||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static AgentScope execute( @Advice.AllArguments final Object[] args) { | ||
String script = (String)args[1]; | ||
String scriptName = (String)args[2]; | ||
|
||
AgentSpan span = DECORATOR.createSpan(scriptName,script); | ||
AgentScope agentScope = activateSpan(span); | ||
return agentScope; | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void exit( | ||
@Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) { | ||
if (scope == null) { | ||
return; | ||
} | ||
DECORATOR.onError(scope.span(),throwable); | ||
DECORATOR.beforeFinish(scope.span()); | ||
scope.close(); | ||
scope.span().finish(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...strumentation/rhino/src/main/java/datadog/trace/instrumentation/rhino/RhinoDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package datadog.trace.instrumentation.rhino; | ||
|
||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
import datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.startSpan; | ||
|
||
public class RhinoDecorator extends BaseDecorator { | ||
private static final Logger log = LoggerFactory.getLogger(RhinoDecorator.class); | ||
public static final RhinoDecorator DECORATOR = new RhinoDecorator(); | ||
|
||
public static final String INSTRUMENTATION = "rhino"; | ||
|
||
@Override | ||
protected String[] instrumentationNames() { | ||
return new String[]{INSTRUMENTATION}; | ||
} | ||
|
||
@Override | ||
protected CharSequence spanType() { | ||
return INSTRUMENTATION; | ||
} | ||
|
||
@Override | ||
protected CharSequence component() { | ||
return INSTRUMENTATION; | ||
} | ||
|
||
public AgentSpan createSpan(String operationName,String script) { | ||
log.debug("--------------------- operationName:{},script:{}",operationName,script); | ||
AgentSpan span = startSpan(operationName); | ||
afterStart(span); | ||
span.setResourceName(operationName); | ||
span.setTag("script",script); | ||
return span; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...ntation/rhino/src/main/java/datadog/trace/instrumentation/rhino/RhinoInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package datadog.trace.instrumentation.rhino; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import datadog.trace.agent.tooling.InstrumenterModule; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named; | ||
import static datadog.trace.instrumentation.rhino.RhinoDecorator.INSTRUMENTATION; | ||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPrivate; | ||
|
||
@AutoService(InstrumenterModule.class) | ||
public class RhinoInstrumentation extends InstrumenterModule.Tracing | ||
implements Instrumenter.ForTypeHierarchy { | ||
|
||
public RhinoInstrumentation() { | ||
super(INSTRUMENTATION); | ||
} | ||
|
||
@Override | ||
public String hierarchyMarkerType() { | ||
return "org.mozilla.javascript.Context"; | ||
} | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> hierarchyMatcher() { | ||
return named(hierarchyMarkerType()); | ||
} | ||
|
||
@Override | ||
public void methodAdvice(MethodTransformer transformer) { | ||
transformer.applyAdvice( | ||
isMethod() | ||
.and(isPrivate()) | ||
.and(named("compileImpl")), | ||
packageName + ".RhinoAdvice"); | ||
} | ||
|
||
@Override | ||
public String[] helperClassNames() { | ||
return new String[]{ | ||
packageName + ".RhinoAdvice", | ||
packageName + ".RhinoDecorator", | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters