-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
177 changed files
with
3,669 additions
and
1,103 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
63 changes: 63 additions & 0 deletions
63
...-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/api/ContextVisitors.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,63 @@ | ||
package datadog.trace.bootstrap.instrumentation.api; | ||
|
||
import java.util.Map; | ||
|
||
public final class ContextVisitors { | ||
|
||
private static final MapContextVisitor<?> MAP_CONTEXT_VISITOR = new MapContextVisitor<>(); | ||
private static final EntrySetContextVisitor<?> ENTRY_SET_CONTEXT_VISITOR = | ||
new EntrySetContextVisitor<>(); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T extends Map<String, ? extends Object>> | ||
AgentPropagation.ContextVisitor<T> objectValuesMap() { | ||
return (AgentPropagation.ContextVisitor<T>) MAP_CONTEXT_VISITOR; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T extends Map<String, String>> | ||
AgentPropagation.ContextVisitor<T> stringValuesMap() { | ||
return (AgentPropagation.ContextVisitor<T>) MAP_CONTEXT_VISITOR; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T extends Iterable<Map.Entry<String, ? extends Object>>> | ||
AgentPropagation.ContextVisitor<T> objectValuesEntrySet() { | ||
return (AgentPropagation.ContextVisitor<T>) ENTRY_SET_CONTEXT_VISITOR; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T extends Iterable<Map.Entry<String, String>>> | ||
AgentPropagation.ContextVisitor<T> stringValuesEntrySet() { | ||
return (AgentPropagation.ContextVisitor<T>) ENTRY_SET_CONTEXT_VISITOR; | ||
} | ||
|
||
private static final class MapContextVisitor<T extends Map<String, ? extends Object>> | ||
implements AgentPropagation.ContextVisitor<T> { | ||
|
||
@Override | ||
public void forEachKey(T carrier, AgentPropagation.KeyClassifier classifier) { | ||
for (Map.Entry<String, ? extends Object> entry : carrier.entrySet()) { | ||
if (null != entry.getValue() | ||
&& !classifier.accept(entry.getKey(), entry.getValue().toString())) { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static final class EntrySetContextVisitor< | ||
T extends Iterable<Map.Entry<String, ? extends Object>>> | ||
implements AgentPropagation.ContextVisitor<T> { | ||
|
||
@Override | ||
public void forEachKey(T carrier, AgentPropagation.KeyClassifier classifier) { | ||
for (Map.Entry<String, ? extends Object> entry : carrier) { | ||
if (null != entry.getValue() | ||
&& !classifier.accept(entry.getKey(), entry.getValue().toString())) { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
...tstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/TestDecorator.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,51 @@ | ||
package datadog.trace.bootstrap.instrumentation.decorator; | ||
|
||
import datadog.trace.api.DDSpanTypes; | ||
import datadog.trace.api.DDTags; | ||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
import datadog.trace.bootstrap.instrumentation.api.Tags; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public abstract class TestDecorator extends BaseDecorator { | ||
public static final String TEST_PASS = "PASS"; | ||
public static final String TEST_FAIL = "FAIL"; | ||
public static final String TEST_SKIP = "SKIP"; | ||
|
||
protected abstract String testFramework(); | ||
|
||
protected String spanKind() { | ||
return Tags.SPAN_KIND_TEST; | ||
} | ||
|
||
@Override | ||
protected String spanType() { | ||
return DDSpanTypes.TEST; | ||
} | ||
|
||
@Override | ||
public AgentSpan afterStart(final AgentSpan span) { | ||
assert span != null; | ||
span.setTag(Tags.SPAN_KIND, spanKind()); | ||
span.setTag(DDTags.SPAN_TYPE, spanType()); | ||
span.setTag(DDTags.TEST_FRAMEWORK, testFramework()); | ||
return super.afterStart(span); | ||
} | ||
|
||
public List<String> testNames( | ||
final Class<?> testClass, final Class<? extends Annotation> testAnnotation) { | ||
final List<String> testNames = new ArrayList<>(); | ||
|
||
final Method[] methods = testClass.getMethods(); | ||
for (final Method method : methods) { | ||
if (method.getAnnotation(testAnnotation) != null) { | ||
testNames.add(method.getName()); | ||
} | ||
} | ||
return testNames; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...rc/test/groovy/datadog/trace/bootstrap/instrumentation/decorator/TestDecoratorTest.groovy
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,70 @@ | ||
package datadog.trace.bootstrap.instrumentation.decorator | ||
|
||
import datadog.trace.api.DDTags | ||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan | ||
import datadog.trace.bootstrap.instrumentation.api.Tags | ||
|
||
class TestDecoratorTest extends BaseDecoratorTest { | ||
|
||
def span = Mock(AgentSpan) | ||
|
||
def "test afterStart"() { | ||
setup: | ||
def decorator = newDecorator() | ||
|
||
when: | ||
decorator.afterStart(span) | ||
|
||
then: | ||
1 * span.setTag(Tags.COMPONENT, "test-component") | ||
1 * span.setTag(Tags.SPAN_KIND, decorator.spanKind()) | ||
1 * span.setTag(DDTags.SPAN_TYPE, decorator.spanType()) | ||
1 * span.setTag(DDTags.TEST_FRAMEWORK, decorator.testFramework()) | ||
_ * span.setTag(_, _) // Want to allow other calls from child implementations. | ||
_ * span.setServiceName(_) | ||
_ * span.setOperationName(_) | ||
0 * _ | ||
|
||
where: | ||
serviceName << ["test-service", "other-service", null] | ||
} | ||
|
||
def "test beforeFinish"() { | ||
when: | ||
newDecorator().beforeFinish(span) | ||
|
||
then: | ||
0 * _ | ||
} | ||
|
||
|
||
@Override | ||
def newDecorator() { | ||
return new TestDecorator() { | ||
@Override | ||
protected String testFramework() { | ||
return "test-framework" | ||
} | ||
|
||
@Override | ||
protected String[] instrumentationNames() { | ||
return ["test1", "test2"] | ||
} | ||
|
||
@Override | ||
protected String spanType() { | ||
return "test-type" | ||
} | ||
|
||
@Override | ||
protected String spanKind() { | ||
return "test-type" | ||
} | ||
|
||
@Override | ||
protected String component() { | ||
return "test-component" | ||
} | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.