Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add http.status_code attribute to all Spans that have a lowLevelHttpResponse #986

Merged
merged 1 commit into from Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1012,6 +1012,7 @@ public HttpResponse execute() throws IOException {
LowLevelHttpResponse lowLevelHttpResponse = lowLevelHttpRequest.execute();
if (lowLevelHttpResponse != null) {
OpenCensusUtils.recordReceivedMessageEvent(span, lowLevelHttpResponse.getContentLength());
span.putAttribute(HttpTraceAttributeConstants.HTTP_STATUS_CODE, AttributeValue.longAttributeValue(lowLevelHttpResponse.getStatusCode()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a long instead of an int? Status codes don't go past 5XX

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is only long for integer attribute types in OpenCensus: https://javadoc.io/doc/io.opencensus/opencensus-api/0.12.2/io/opencensus/trace/AttributeValue.html

}
// Flag used to indicate if an exception is thrown before the response is constructed.
boolean responseConstructed = false;
Expand Down
Expand Up @@ -82,6 +82,7 @@ public void executeCreatesSpan() throws IOException {
assertAttributeEquals(span, "http.host", "google.com");
assertAttributeEquals(span, "http.url", "https://google.com/");
assertAttributeEquals(span, "http.method", "GET");
assertAttributeEquals(span, "http.status_code", "200");

// Ensure we have a single annotation for starting the first attempt
assertEquals(1, span.getAnnotations().getEvents().size());
Expand Down