@@ -43,6 +43,11 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
43
43
44
44
val (sslSocketFactory, trustManager) = clientSSL()
45
45
val okHttp = new OkHttpClient .Builder ()
46
+ .sslSocketFactory(sslSocketFactory, trustManager)
47
+ .hostnameVerifier(new HostnameVerifier { override def verify (s : String , sslSession : SSLSession ): Boolean = true })
48
+ .build()
49
+
50
+ val okHttp1ONly = new OkHttpClient .Builder ()
46
51
.sslSocketFactory(sslSocketFactory, trustManager)
47
52
.protocols(List (Protocol .HTTP_1_1 ).asJava)
48
53
.hostnameVerifier(new HostnameVerifier { override def verify (s : String , sslSession : SSLSession ): Boolean = true })
@@ -53,22 +58,24 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
53
58
val httpWebServer = startServer(interface, 8081 , https = false )
54
59
val httpsWebServer = startServer(interface, 8082 , https = true )
55
60
56
- testSuite(" HTTP" , httpWebServer)
57
- testSuite(" HTTPS" , httpsWebServer)
61
+ testSuite(" HTTP" , httpWebServer, okHttp)
62
+ testSuite(" HTTPS" , httpsWebServer, okHttp)
63
+ testSuite(" HTTPS with HTTP/1 only clients" , httpsWebServer, okHttp1ONly)
58
64
59
- def testSuite (httpVersion : String , server : WebServer ) = {
65
+ def testSuite (httpVersion : String , server : WebServer , client : OkHttpClient ) = {
60
66
val interface = server.interface
61
67
val port = server.port
62
68
val protocol = server.protocol
63
69
64
70
s " the Akka HTTP server instrumentation with ${httpVersion}" should {
65
71
" create a server Span when receiving requests" in {
66
72
val target = s " $protocol:// $interface: $port/ $dummyPathOk"
67
- okHttp.newCall(new Request .Builder ().url(target).build()).execute()
73
+ client.newCall(new Request .Builder ().url(target).build()).execute()
74
+
68
75
69
76
eventually(timeout(10 seconds)) {
70
77
val span = testSpanReporter().nextSpan().value
71
- span.tags.get(plain(" http.url" )) shouldBe target
78
+ span.tags.get(plain(" http.url" )) should endWith( s " $interface : $port / $dummyPathOk " )
72
79
span.metricTags.get(plain(" component" )) shouldBe " akka.http.server"
73
80
span.metricTags.get(plain(" http.method" )) shouldBe " GET"
74
81
span.metricTags.get(plainLong(" http.status_code" )) shouldBe 200L
@@ -78,7 +85,7 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
78
85
" return the correct operation name with overloaded route" in {
79
86
val target = s " $protocol:// $interface: $port/some_endpoint "
80
87
81
- okHttp .newCall(new Request .Builder ()
88
+ client .newCall(new Request .Builder ()
82
89
.get()
83
90
.url(target).build())
84
91
.execute()
@@ -91,7 +98,7 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
91
98
val path = s " extraction/nested/42/fixed/anchor/32/ ${UUID .randomUUID().toString}/fixed/44/CafE "
92
99
val expected = " /extraction/nested/{}/fixed/anchor/{}/{}/fixed/{}/{}"
93
100
val target = s " $protocol:// $interface: $port/ $path"
94
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
101
+ client .newCall(new Request .Builder ().url(target).build()).execute()
95
102
96
103
eventually(timeout(10 seconds)) {
97
104
val span = testSpanReporter().nextSpan().value
@@ -103,7 +110,7 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
103
110
val path = " extraction/segment/special**"
104
111
val expected = " /extraction/segment/{}"
105
112
val target = s " $protocol:// $interface: $port/ $path"
106
- val response = okHttp .newCall(new Request .Builder ().url(target).build()).execute()
113
+ val response = client .newCall(new Request .Builder ().url(target).build()).execute()
107
114
108
115
response.code() shouldBe 200
109
116
response.body().string() shouldBe " special**"
@@ -118,7 +125,7 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
118
125
val path = " extraction/on-complete/42/more-path"
119
126
val expected = " /extraction/on-complete/{}/more-path"
120
127
val target = s " $protocol:// $interface: $port/ $path"
121
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
128
+ client .newCall(new Request .Builder ().url(target).build()).execute()
122
129
123
130
eventually(timeout(10 seconds)) {
124
131
val span = testSpanReporter().nextSpan().value
@@ -130,7 +137,7 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
130
137
val path = " extraction/on-success/42/after"
131
138
val expected = " /extraction/on-success/{}/after"
132
139
val target = s " $protocol:// $interface: $port/ $path"
133
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
140
+ client .newCall(new Request .Builder ().url(target).build()).execute()
134
141
135
142
eventually(timeout(10 seconds)) {
136
143
val span = testSpanReporter().nextSpan().value
@@ -142,7 +149,7 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
142
149
val path = " extraction/complete-or-recover-with/42/after"
143
150
val expected = " /extraction/complete-or-recover-with/{}/after"
144
151
val target = s " $protocol:// $interface: $port/ $path"
145
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
152
+ client .newCall(new Request .Builder ().url(target).build()).execute()
146
153
147
154
eventually(timeout(10 seconds)) {
148
155
val span = testSpanReporter().nextSpan().value
@@ -154,7 +161,7 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
154
161
val path = " extraction/complete-or-recover-with-success/42/after"
155
162
val expected = " /extraction/complete-or-recover-with-success/{}"
156
163
val target = s " $protocol:// $interface: $port/ $path"
157
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
164
+ client .newCall(new Request .Builder ().url(target).build()).execute()
158
165
159
166
eventually(timeout(10 seconds)) {
160
167
val span = testSpanReporter().nextSpan().value
@@ -166,7 +173,7 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
166
173
val path = s " v3/user/3/post/3 "
167
174
val expected = " /v3/user/{}/post/{}"
168
175
val target = s " $protocol:// $interface: $port/ $path"
169
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
176
+ client .newCall(new Request .Builder ().url(target).build()).execute()
170
177
171
178
eventually(timeout(10 seconds)) {
172
179
val span = testSpanReporter().nextSpan().value
@@ -177,12 +184,12 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
177
184
178
185
" change the Span operation name when using the operationName directive" in {
179
186
val target = s " $protocol:// $interface: $port/ $traceOk"
180
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
187
+ client .newCall(new Request .Builder ().url(target).build()).execute()
181
188
182
189
eventually(timeout(10 seconds)) {
183
190
val span = testSpanReporter().nextSpan().value
184
191
span.operationName shouldBe " user-supplied-operation"
185
- span.tags.get(plain(" http.url" )) shouldBe target
192
+ span.tags.get(plain(" http.url" )) should endWith( s " $interface : $port / $traceOk " )
186
193
span.metricTags.get(plain(" component" )) shouldBe " akka.http.server"
187
194
span.metricTags.get(plain(" http.method" )) shouldBe " GET"
188
195
span.metricTags.get(plainLong(" http.status_code" )) shouldBe 200L
@@ -191,12 +198,12 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
191
198
192
199
" mark spans as failed when request fails" in {
193
200
val target = s " $protocol:// $interface: $port/ $dummyPathError"
194
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
201
+ client .newCall(new Request .Builder ().url(target).build()).execute()
195
202
196
203
eventually(timeout(10 seconds)) {
197
204
val span = testSpanReporter().nextSpan().value
198
205
span.operationName shouldBe s " / $dummyPathError"
199
- span.tags.get(plain(" http.url" )) shouldBe target
206
+ span.tags.get(plain(" http.url" )) should endWith( s " $interface : $port / $dummyPathError " )
200
207
span.metricTags.get(plain(" component" )) shouldBe " akka.http.server"
201
208
span.metricTags.get(plain(" http.method" )) shouldBe " GET"
202
209
span.metricTags.get(plainBoolean(" error" )) shouldBe true
@@ -206,12 +213,12 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
206
213
207
214
" change the operation name to 'unhandled' when the response status code is 404" in {
208
215
val target = s " $protocol:// $interface: $port/unknown-path "
209
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
216
+ client .newCall(new Request .Builder ().url(target).build()).execute()
210
217
211
218
eventually(timeout(10 seconds)) {
212
219
val span = testSpanReporter().nextSpan().value
213
220
span.operationName shouldBe " unhandled"
214
- span.tags.get(plain(" http.url" )) shouldBe target
221
+ span.tags.get(plain(" http.url" )) should endWith( s " $interface : $port /unknown-path " )
215
222
span.metricTags.get(plain(" component" )) shouldBe " akka.http.server"
216
223
span.metricTags.get(plain(" http.method" )) shouldBe " GET"
217
224
span.metricTags.get(plainBoolean(" error" )) shouldBe false
@@ -221,7 +228,7 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
221
228
222
229
" correctly time entity transfer timings" in {
223
230
val target = s " $protocol:// $interface: $port/ $stream"
224
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
231
+ client .newCall(new Request .Builder ().url(target).build()).execute()
225
232
226
233
val span = eventually(timeout(10 seconds)) {
227
234
val span = testSpanReporter().nextSpan().value
@@ -233,14 +240,14 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
233
240
case List (_ @ Mark (_, " http.response.ready" )) =>
234
241
}
235
242
236
- span.tags.get(plain(" http.url" )) shouldBe target
243
+ span.tags.get(plain(" http.url" )) should endWith( s " $interface : $port / $stream " )
237
244
span.metricTags.get(plain(" component" )) shouldBe " akka.http.server"
238
245
span.metricTags.get(plain(" http.method" )) shouldBe " GET"
239
246
}
240
247
241
248
" include the trace-id and keep all user-provided headers in the responses" in {
242
249
val target = s " $protocol:// $interface: $port/extra-header "
243
- val response = okHttp .newCall(new Request .Builder ().url(target).build()).execute()
250
+ val response = client .newCall(new Request .Builder ().url(target).build()).execute()
244
251
245
252
response.headers().names() should contain allOf (
246
253
" trace-id" ,
@@ -250,7 +257,7 @@ class AkkaHttpServerTracingSpec extends AnyWordSpecLike with Matchers with Scala
250
257
251
258
" keep operation names provided by the HTTP Server instrumentation" in {
252
259
val target = s " $protocol:// $interface: $port/name-will-be-changed "
253
- okHttp .newCall(new Request .Builder ().url(target).build()).execute()
260
+ client .newCall(new Request .Builder ().url(target).build()).execute()
254
261
255
262
eventually(timeout(10 seconds)) {
256
263
val span = testSpanReporter().nextSpan().value
0 commit comments