Skip to content

Commit

Permalink
Replace deprecated OpenTelemetry semantic convention attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
reta committed Oct 17, 2023
1 parent ef7d989 commit d17fe34
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<Str
Context parentContext = Context.current();
Span activeSpan = tracer.spanBuilder(buildSpanDescription(uri.toString(), method))
.setParent(parentContext).setSpanKind(SpanKind.CLIENT)
.setAttribute(SemanticAttributes.HTTP_METHOD, method)
.setAttribute(SemanticAttributes.HTTP_URL, uri.toString())
.setAttribute(SemanticAttributes.HTTP_REQUEST_METHOD, method)
.setAttribute(SemanticAttributes.URL_FULL, uri.toString())
// TODO: Enhance with semantics from request
.startSpan();
Scope scope = activeSpan.makeCurrent();
Expand Down Expand Up @@ -100,7 +100,7 @@ protected void stopTraceSpan(final TraceScopeHolder<TraceScope> holder, final in
scope = span.makeCurrent();
}

span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE.getKey(), responseStatus);
span.setAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE.getKey(), responseStatus);

span.end();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<Str

SpanBuilder spanBuilder = tracer.spanBuilder(buildSpanDescription(uri.getPath(), method))
.setSpanKind(SpanKind.SERVER)
.setAttribute(SemanticAttributes.HTTP_METHOD, method)
.setAttribute(SemanticAttributes.HTTP_URL, uri.toString());
.setAttribute(SemanticAttributes.HTTP_REQUEST_METHOD, method)
.setAttribute(SemanticAttributes.URL_FULL, uri.toString());
Span activeSpan = spanBuilder.startSpan();
Scope scope = activeSpan.makeCurrent();

Expand Down Expand Up @@ -104,7 +104,7 @@ protected void stopTraceSpan(final Map<String, List<String>> requestHeaders,
scope = span.makeCurrent();
}

span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, responseStatus);
span.setAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, responseStatus);
span.end();

scope.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void testThatNewSpanIsCreatedWhenNotProvided() {
assertThat(otelRule.getSpans().get(0).getName(), equalTo("Get Books"));
assertThat(otelRule.getSpans().get(1).getName(), equalTo("GET /bookstore/books"));
assertThat(otelRule.getSpans().get(1).getAttributes(),
hasAttribute(SemanticAttributes.HTTP_STATUS_CODE, 200L));
hasAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 200L));
assertThat(otelRule.getSpans().get(1).getInstrumentationScopeInfo().getName(),
equalTo("jaxrs-server-test"));
}
Expand Down Expand Up @@ -397,7 +397,7 @@ public void testThatErrorSpanIsCreatedOnExceptionWhenNotProvided() {
assertThat(otelRule.getSpans().toString(), otelRule.getSpans().size(), equalTo(1));
assertThat(otelRule.getSpans().get(0).getName(), equalTo("GET /bookstore/books/exception"));
assertThat(otelRule.getSpans().get(0).getAttributes(),
hasAttribute(SemanticAttributes.HTTP_STATUS_CODE, 500L));
hasAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 500L));
}

@Test
Expand All @@ -408,7 +408,7 @@ public void testThatErrorSpanIsCreatedOnErrorWhenNotProvided() {
assertThat(otelRule.getSpans().toString(), otelRule.getSpans().size(), equalTo(1));
assertThat(otelRule.getSpans().get(0).getName(), equalTo("GET /bookstore/books/error"));
assertThat(otelRule.getSpans().get(0).getAttributes(),
hasAttribute(SemanticAttributes.HTTP_STATUS_CODE, 503L));
hasAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 503L));
}

@Test
Expand All @@ -419,7 +419,7 @@ public void testThatErrorSpanIsCreatedOnMappedExceptionWhenNotProvided() {
assertThat(otelRule.getSpans().toString(), otelRule.getSpans().size(), equalTo(1));
assertThat(otelRule.getSpans().get(0).getName(), equalTo("GET /bookstore/books/mapper"));
assertThat(otelRule.getSpans().get(0).getAttributes(),
hasAttribute(SemanticAttributes.HTTP_STATUS_CODE, 404L));
hasAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 404L));
}

private WebClient withTrace(final WebClient client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void testThatNewChildSpanIsCreatedWhenParentIsProvidedInCaseOfFault() thr
assertThat(otelRule.getSpans().size(), equalTo(2));
assertThat(otelRule.getSpans().get(0).getName(), equalTo("POST /BookStore"));
assertThat(otelRule.getSpans().get(0).getAttributes(),
hasAttribute(SemanticAttributes.HTTP_STATUS_CODE, 500L));
hasAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 500L));
assertThat(otelRule.getSpans().get(1).getName(),
equalTo("POST http://localhost:" + PORT + "/BookStore"));
}
Expand All @@ -252,7 +252,7 @@ public void testThatNewChildSpanIsCreatedWhenParentIsProvidedAndCustomStatusCode
assertThat(otelRule.getSpans().size(), equalTo(1));
assertThat(otelRule.getSpans().get(0).getName(), equalTo("POST /BookStore"));
assertThat(otelRule.getSpans().get(0).getAttributes(),
hasAttribute(SemanticAttributes.HTTP_STATUS_CODE, 202L));
hasAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 202L));
}

@Test
Expand Down

0 comments on commit d17fe34

Please sign in to comment.