-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't report 400 level as error for SERVER spans (#4403)
* don't report 400 level as error for server spans * fix HttpServerTest base class * fix JspInstrumentationForward test * split HttpStatusConverter into client and server implementations, and create two HttpSpanStatusExtractor.create methods, one for server and one for client. * rebase * fix test * spotless * fix test * remove unused * use strongly typed attributes converters and rename to overloaded create() * fix tests * remove redundant assert Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
- Loading branch information
1 parent
5d7c0dd
commit a50c133
Showing
21 changed files
with
315 additions
and
63 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
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
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/HttpServerStatusConverterTest.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 HttpServerStatusConverterTest extends Specification { | ||
|
||
def "test HTTP #httpStatus to OTel #expectedStatus"() { | ||
when: | ||
def status = HttpStatusConverter.SERVER.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.UNSET | ||
401 | StatusCode.UNSET | ||
403 | StatusCode.UNSET | ||
404 | StatusCode.UNSET | ||
405 | StatusCode.UNSET | ||
406 | StatusCode.UNSET | ||
407 | StatusCode.UNSET | ||
408 | StatusCode.UNSET | ||
409 | StatusCode.UNSET | ||
410 | StatusCode.UNSET | ||
411 | StatusCode.UNSET | ||
412 | StatusCode.UNSET | ||
413 | StatusCode.UNSET | ||
414 | StatusCode.UNSET | ||
415 | StatusCode.UNSET | ||
416 | StatusCode.UNSET | ||
417 | StatusCode.UNSET | ||
418 | StatusCode.UNSET | ||
421 | StatusCode.UNSET | ||
422 | StatusCode.UNSET | ||
423 | StatusCode.UNSET | ||
424 | StatusCode.UNSET | ||
425 | StatusCode.UNSET | ||
426 | StatusCode.UNSET | ||
428 | StatusCode.UNSET | ||
429 | StatusCode.UNSET | ||
431 | StatusCode.UNSET | ||
451 | StatusCode.UNSET | ||
|
||
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 | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...pentelemetry/instrumentation/api/instrumenter/http/HttpClientSpanStatusExtractorTest.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,70 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.http; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.anyMap; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.opentelemetry.api.trace.StatusCode; | ||
import io.opentelemetry.instrumentation.api.tracer.HttpStatusConverter; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class HttpClientSpanStatusExtractorTest { | ||
@Mock private HttpClientAttributesExtractor<Map<String, String>, Map<String, String>> extractor; | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {1, 100, 101, 200, 201, 300, 301, 400, 401, 500, 501, 600, 601}) | ||
void hasStatus(int statusCode) { | ||
when(extractor.statusCode(anyMap(), anyMap())).thenReturn(statusCode); | ||
assertThat( | ||
HttpSpanStatusExtractor.create(extractor) | ||
.extract(Collections.emptyMap(), Collections.emptyMap(), null)) | ||
.isEqualTo(HttpStatusConverter.CLIENT.statusFromHttpStatus(statusCode)); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {1, 100, 101, 200, 201, 300, 301, 400, 401, 500, 501, 600, 601}) | ||
void hasStatusAndException(int statusCode) { | ||
when(extractor.statusCode(anyMap(), anyMap())).thenReturn(statusCode); | ||
|
||
// Presence of exception has no effect. | ||
assertThat( | ||
HttpSpanStatusExtractor.create(extractor) | ||
.extract( | ||
Collections.emptyMap(), Collections.emptyMap(), new IllegalStateException())) | ||
.isEqualTo(StatusCode.ERROR); | ||
} | ||
|
||
@Test | ||
void hasNoStatus_fallsBackToDefault_unset() { | ||
when(extractor.statusCode(anyMap(), anyMap())).thenReturn(null); | ||
|
||
assertThat( | ||
HttpSpanStatusExtractor.create(extractor) | ||
.extract(Collections.emptyMap(), Collections.emptyMap(), null)) | ||
.isEqualTo(StatusCode.UNSET); | ||
} | ||
|
||
@Test | ||
void hasNoStatus_fallsBackToDefault_error() { | ||
when(extractor.statusCode(anyMap(), anyMap())).thenReturn(null); | ||
|
||
assertThat( | ||
HttpSpanStatusExtractor.create(extractor) | ||
.extract( | ||
Collections.emptyMap(), Collections.emptyMap(), new IllegalStateException())) | ||
.isEqualTo(StatusCode.ERROR); | ||
} | ||
} |
Oops, something went wrong.