Skip to content

Commit 319b87b

Browse files
committed
Function BootstrapInitializationTelemetry test
Found a way to get the BootstrapInitializationTelemetryTest working Using a Groovy Proxy to circumvent the class resolution problems Added a number of tests to check that telemetry is working as expected
1 parent fe2a16a commit 319b87b

File tree

2 files changed

+86
-37
lines changed

2 files changed

+86
-37
lines changed

dd-java-agent/src/test/groovy/datadog/trace/agent/BootstrapInitializationTelemetryTest.groovy

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package datadog.trace.agent
2+
3+
import datadog.trace.bootstrap.BootstrapInitializationTelemetry
4+
import datadog.trace.bootstrap.JsonBuffer
5+
import spock.lang.Specification
6+
import groovy.util.Proxy
7+
8+
class BootstrapInitializationTelemetryTest extends Specification {
9+
def initTelemetry, capture
10+
11+
def setup() {
12+
def capture = new Capture()
13+
def initTelemetry = new BootstrapInitializationTelemetry.JsonBased(capture)
14+
15+
// There's an annoying interaction between our bootstrap injection
16+
// and the GroovyClassLoader class resolution. Groovy resolves the import
17+
// against the application ClassLoader, but when a method invocation
18+
// happens it resolves the invocation against the bootstrap classloader.
19+
20+
// To side step this problem, put a Groovy Proxy around the object under test
21+
def initTelemetryProxy = new Proxy()
22+
initTelemetryProxy.setAdaptee(initTelemetry)
23+
24+
this.initTelemetry = initTelemetryProxy
25+
this.capture = capture
26+
}
27+
28+
def "real example"() {
29+
when:
30+
initTelemetry.initMetaInfo("runtime_name", "java")
31+
initTelemetry.initMetaInfo("runtime_version", "1.8.0_382")
32+
33+
initTelemetry.onError(new Exception("foo"))
34+
initTelemetry.finish()
35+
36+
then:
37+
capture.json() == '{"metadata":{"runtime_name":"java","runtime_version":"1.8.0_382"},"points":[{"name":"library_entrypoint.error","tags":["error_type:java.lang.Exception"]},{"name":"library_entrypoint.complete"}]}'
38+
}
39+
40+
def "trivial completion check"() {
41+
when:
42+
initTelemetry.finish()
43+
44+
then:
45+
capture.json().contains("library_entrypoint.complete")
46+
}
47+
48+
def "trivial incomplete check"() {
49+
when:
50+
initTelemetry.markIncomplete()
51+
initTelemetry.finish()
52+
53+
then:
54+
!capture.json().contains("library_entrypoint.complete")
55+
}
56+
57+
def "incomplete on fatal error"() {
58+
when:
59+
initTelemetry.onFatalError(new Exception("foo"))
60+
initTelemetry.finish()
61+
62+
then:
63+
!capture.json().contains("library_entrypoint.complete")
64+
}
65+
66+
def "incomplete on abort"() {
67+
when:
68+
initTelemetry.onAbort("reason")
69+
initTelemetry.finish()
70+
71+
then:
72+
!capture.json().contains("library_entrypoint.complete")
73+
}
74+
75+
static class Capture implements BootstrapInitializationTelemetry.JsonSender {
76+
JsonBuffer buffer
77+
78+
void send(JsonBuffer buffer) {
79+
this.buffer = buffer
80+
}
81+
82+
String json() {
83+
return this.buffer.toString()
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)