-
Notifications
You must be signed in to change notification settings - Fork 936
/
Copy pathJaxrsAnnotationsInstrumentationTest.groovy
168 lines (152 loc) · 3.58 KB
/
JaxrsAnnotationsInstrumentationTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes
import io.opentelemetry.semconv.ErrorAttributes
import io.opentelemetry.semconv.HttpAttributes
import spock.lang.Unroll
import javax.ws.rs.DELETE
import javax.ws.rs.GET
import javax.ws.rs.HEAD
import javax.ws.rs.OPTIONS
import javax.ws.rs.POST
import javax.ws.rs.PUT
import javax.ws.rs.Path
import static io.opentelemetry.api.trace.SpanKind.SERVER
import static io.opentelemetry.instrumentation.test.utils.ClassUtils.getClassName
class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecification {
@Unroll
def "span named '#paramName' from annotations on class '#className' when is not root span"() {
setup:
runWithHttpServerSpan {
obj.call()
}
expect:
assertTraces(1) {
trace(0, 2) {
span(0) {
name "GET " + paramName
kind SERVER
hasNoParent()
attributes {
"$HttpAttributes.HTTP_REQUEST_METHOD" "GET"
"$HttpAttributes.HTTP_ROUTE" paramName
"$ErrorAttributes.ERROR_TYPE" "_OTHER"
}
}
span(1) {
name "${className}.call"
childOf span(0)
attributes {
"$CodeIncubatingAttributes.CODE_NAMESPACE" obj.getClass().getName()
"$CodeIncubatingAttributes.CODE_FUNCTION" "call"
}
}
}
}
when: "multiple calls to the same method"
runWithHttpServerSpan {
(1..10).each {
obj.call()
}
}
then: "doesn't increase the cache size"
where:
paramName | obj
"/a" | new Jax() {
@Path("/a")
void call() {
}
}
"/b" | new Jax() {
@GET
@Path("/b")
void call() {
}
}
"/interface/c" | new InterfaceWithPath() {
@POST
@Path("/c")
void call() {
}
}
"/interface" | new InterfaceWithPath() {
@HEAD
void call() {
}
}
"/abstract/d" | new AbstractClassWithPath() {
@POST
@Path("/d")
void call() {
}
}
"/abstract" | new AbstractClassWithPath() {
@PUT
void call() {
}
}
"/child/e" | new ChildClassWithPath() {
@OPTIONS
@Path("/e")
void call() {
}
}
"/child/call" | new ChildClassWithPath() {
@DELETE
void call() {
}
}
"/child/call" | new ChildClassWithPath()
"/child/call" | new JavaInterfaces.ChildClassOnInterface()
"/child/call" | new JavaInterfaces.DefaultChildClassOnInterface()
className = getClassName(obj.class)
}
def "no annotations has no effect"() {
setup:
runWithHttpServerSpan {
obj.call()
}
expect:
assertTraces(1) {
trace(0, 1) {
span(0) {
name "GET"
kind SERVER
attributes {
"$HttpAttributes.HTTP_REQUEST_METHOD" "GET"
"$ErrorAttributes.ERROR_TYPE" "_OTHER"
}
}
}
}
where:
obj | _
new Jax() {
void call() {
}
} | _
}
interface Jax {
void call()
}
@Path("/interface")
interface InterfaceWithPath extends Jax {
@GET
void call()
}
@Path("/abstract")
static abstract class AbstractClassWithPath implements Jax {
@PUT
abstract void call()
}
@Path("child")
static class ChildClassWithPath extends AbstractClassWithPath {
@Path("call")
@POST
void call() {
}
}
}