-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split HttpStatusConverter into client and server implementations, and…
… create two HttpSpanStatusExtractor.create methods, one for server and one for client.
- Loading branch information
1 parent
23232bd
commit 917f3d6
Showing
46 changed files
with
419 additions
and
291 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
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
25 changes: 25 additions & 0 deletions
25
.../src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpClientStatusConverter.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,25 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.tracer; | ||
|
||
import io.opentelemetry.api.trace.StatusCode; | ||
|
||
final class HttpClientStatusConverter implements HttpStatusConverter { | ||
|
||
static final HttpStatusConverter INSTANCE = new HttpClientStatusConverter(); | ||
|
||
// https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#status | ||
@Override | ||
public StatusCode statusFromHttpStatus(int httpStatus) { | ||
if (httpStatus >= 100 && httpStatus < 400) { | ||
return StatusCode.UNSET; | ||
} | ||
|
||
return StatusCode.ERROR; | ||
} | ||
|
||
private HttpClientStatusConverter() {} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
.../src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerStatusConverter.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,25 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.tracer; | ||
|
||
import io.opentelemetry.api.trace.StatusCode; | ||
|
||
final class HttpServerStatusConverter implements HttpStatusConverter { | ||
|
||
static final HttpStatusConverter INSTANCE = new HttpServerStatusConverter(); | ||
|
||
// https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md#status | ||
@Override | ||
public StatusCode statusFromHttpStatus(int httpStatus) { | ||
if (httpStatus >= 100 && httpStatus < 500) { | ||
return StatusCode.UNSET; | ||
} | ||
|
||
return StatusCode.ERROR; | ||
} | ||
|
||
private HttpServerStatusConverter() {} | ||
} |
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
94 changes: 94 additions & 0 deletions
94
...t/groovy/io/opentelemetry/instrumentation/api/tracer/HttpClientStatusConverterTest.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,94 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.tracer | ||
|
||
import io.opentelemetry.api.trace.StatusCode | ||
import spock.lang.Specification | ||
|
||
class HttpClientStatusConverterTest extends Specification { | ||
|
||
def "test HTTP #httpStatus to OTel #expectedStatus"() { | ||
when: | ||
def status = HttpStatusConverter.CLIENT.statusFromHttpStatus(httpStatus) | ||
|
||
then: | ||
status == expectedStatus | ||
|
||
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes | ||
where: | ||
httpStatus | expectedStatus | ||
100 | StatusCode.UNSET | ||
101 | StatusCode.UNSET | ||
102 | StatusCode.UNSET | ||
103 | StatusCode.UNSET | ||
|
||
200 | StatusCode.UNSET | ||
201 | StatusCode.UNSET | ||
202 | StatusCode.UNSET | ||
203 | StatusCode.UNSET | ||
204 | StatusCode.UNSET | ||
205 | StatusCode.UNSET | ||
206 | StatusCode.UNSET | ||
207 | StatusCode.UNSET | ||
208 | StatusCode.UNSET | ||
226 | StatusCode.UNSET | ||
|
||
300 | StatusCode.UNSET | ||
301 | StatusCode.UNSET | ||
302 | StatusCode.UNSET | ||
303 | StatusCode.UNSET | ||
304 | StatusCode.UNSET | ||
305 | StatusCode.UNSET | ||
306 | StatusCode.UNSET | ||
307 | StatusCode.UNSET | ||
308 | StatusCode.UNSET | ||
|
||
400 | StatusCode.ERROR | ||
401 | StatusCode.ERROR | ||
403 | StatusCode.ERROR | ||
404 | StatusCode.ERROR | ||
405 | StatusCode.ERROR | ||
406 | StatusCode.ERROR | ||
407 | StatusCode.ERROR | ||
408 | StatusCode.ERROR | ||
409 | StatusCode.ERROR | ||
410 | StatusCode.ERROR | ||
411 | StatusCode.ERROR | ||
412 | StatusCode.ERROR | ||
413 | StatusCode.ERROR | ||
414 | StatusCode.ERROR | ||
415 | StatusCode.ERROR | ||
416 | StatusCode.ERROR | ||
417 | StatusCode.ERROR | ||
418 | StatusCode.ERROR | ||
421 | StatusCode.ERROR | ||
422 | StatusCode.ERROR | ||
423 | StatusCode.ERROR | ||
424 | StatusCode.ERROR | ||
425 | StatusCode.ERROR | ||
426 | StatusCode.ERROR | ||
428 | StatusCode.ERROR | ||
429 | StatusCode.ERROR | ||
431 | StatusCode.ERROR | ||
451 | StatusCode.ERROR | ||
|
||
500 | StatusCode.ERROR | ||
501 | StatusCode.ERROR | ||
502 | StatusCode.ERROR | ||
503 | StatusCode.ERROR | ||
504 | StatusCode.ERROR | ||
505 | StatusCode.ERROR | ||
506 | StatusCode.ERROR | ||
507 | StatusCode.ERROR | ||
508 | StatusCode.ERROR | ||
510 | StatusCode.ERROR | ||
511 | StatusCode.ERROR | ||
|
||
// Don't exist | ||
99 | StatusCode.ERROR | ||
600 | StatusCode.ERROR | ||
} | ||
} |
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.