Skip to content

Commit ccace3d

Browse files
authored
Merge pull request #1706 from microsoft/fix/otel-attributes
fix/otel attributes
2 parents 3e0d889 + 6fe9258 commit ccace3d

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private Span startSpan(
255255
GlobalOpenTelemetry.getTracer(obsOptions.getTracerInstrumentationName())
256256
.spanBuilder(methodName + " - " + cleanedUriTemplate)
257257
.startSpan();
258-
span.setAttribute("http.uri_template", decodedUriTemplate);
258+
span.setAttribute(URL_TEMPLATE, decodedUriTemplate);
259259
return span;
260260
}
261261

@@ -725,12 +725,11 @@ private Response getHttpResponseMessage(
725725
final String contentTypeHeaderValue = getHeaderValue(response, CONTENT_TYPE_HEADER_KEY);
726726
if (contentTypeHeaderValue != null && !contentTypeHeaderValue.isEmpty()) {
727727
spanForAttributes.setAttribute(
728-
CUSTOM_HTTP_RESPONSE_CONTENT_TYPE, contentTypeHeaderValue);
728+
HTTP_RESPONSE_HEADER_CONTENT_TYPE, contentTypeHeaderValue);
729729
}
730730
spanForAttributes.setAttribute(HTTP_RESPONSE_STATUS_CODE, response.code());
731731
spanForAttributes.setAttribute(
732-
NETWORK_PROTOCOL_VERSION,
733-
response.protocol().toString().toUpperCase(Locale.ROOT));
732+
NETWORK_PROTOCOL_NAME, response.protocol().toString().toUpperCase(Locale.ROOT));
734733
return this.retryCAEResponseIfRequired(
735734
response, requestInfo, span, spanForAttributes, claims);
736735
} catch (IOException | URISyntaxException ex) {
@@ -869,7 +868,7 @@ public MediaType contentType() {
869868
final String contentType =
870869
contentTypes.toArray(new String[] {})[0];
871870
spanForAttributes.setAttribute(
872-
CUSTOM_HTTP_REQUEST_CONTENT_TYPE, contentType);
871+
HTTP_REQUEST_HEADER_CONTENT_TYPE, contentType);
873872
return MediaType.parse(contentType);
874873
}
875874
}

components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ private TelemetrySemanticConventions() {}
2525
public static final AttributeKey<Long> HTTP_REQUEST_RESEND_COUNT =
2626
longKey("http.request.resend_count"); // stable
2727

28+
/**
29+
* HTTP Request resend delay
30+
*/
31+
public static final AttributeKey<Long> HTTP_REQUEST_RESEND_DELAY =
32+
longKey("http.request.resend_delay"); // stable
33+
2834
/**
2935
* HTTP Request method
3036
*/
@@ -34,14 +40,19 @@ private TelemetrySemanticConventions() {}
3440
/**
3541
* Network connection protocol version
3642
*/
37-
public static final AttributeKey<String> NETWORK_PROTOCOL_VERSION =
38-
stringKey("network.protocol.version"); // stable
43+
public static final AttributeKey<String> NETWORK_PROTOCOL_NAME =
44+
stringKey("network.protocol.name"); // stable
3945

4046
/**
4147
* Full HTTP request URL
4248
*/
4349
public static final AttributeKey<String> URL_FULL = stringKey("url.full"); // stable
4450

51+
/**
52+
* Full HTTP request URL template
53+
*/
54+
public static final AttributeKey<String> URL_TEMPLATE = stringKey("url.uri_template"); // custom
55+
4556
/**
4657
* HTTP request URL scheme
4758
*/
@@ -72,12 +83,12 @@ private TelemetrySemanticConventions() {}
7283
/**
7384
* HTTP response content type
7485
*/
75-
public static final AttributeKey<String> CUSTOM_HTTP_RESPONSE_CONTENT_TYPE =
76-
stringKey("http.response_content_type"); // custom
86+
public static final AttributeKey<String> HTTP_RESPONSE_HEADER_CONTENT_TYPE =
87+
stringKey("http.response.header.content-type"); // stable
7788

7889
/**
7990
* HTTP request content type
8091
*/
81-
public static final AttributeKey<String> CUSTOM_HTTP_REQUEST_CONTENT_TYPE =
82-
stringKey("http.request_content_type"); // custom
92+
public static final AttributeKey<String> HTTP_REQUEST_HEADER_CONTENT_TYPE =
93+
stringKey("http.request.header.content-type"); // stable
8394
}

components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/RetryHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.microsoft.kiota.http.middleware;
22

3+
import static com.microsoft.kiota.http.TelemetrySemanticConventions.*;
4+
35
import com.microsoft.kiota.http.middleware.options.IShouldRetry;
46
import com.microsoft.kiota.http.middleware.options.RetryHandlerOption;
57

@@ -82,7 +84,8 @@ boolean retryRequest(
8284
@Nonnull final Response response,
8385
int executionCount,
8486
@Nonnull final Request request,
85-
@Nonnull final RetryHandlerOption retryOption) {
87+
@Nonnull final RetryHandlerOption retryOption,
88+
@Nonnull final Span span) {
8689

8790
// Should retry option
8891
// Use should retry common for all requests
@@ -107,6 +110,7 @@ && isBuffered(request)
107110

108111
if (shouldRetry) {
109112
long retryInterval = getRetryAfter(response, retryOption.delay(), executionCount);
113+
span.setAttribute(HTTP_REQUEST_RESEND_DELAY, Math.round(retryInterval / 1000f));
110114
try {
111115
Thread.sleep(retryInterval);
112116
} catch (InterruptedException e) {
@@ -234,7 +238,7 @@ boolean isBuffered(final Request request) {
234238
}
235239

236240
int executionCount = 1;
237-
while (retryRequest(response, executionCount, request, retryOption)) {
241+
while (retryRequest(response, executionCount, request, retryOption, span)) {
238242
final Request.Builder builder =
239243
request.newBuilder()
240244
.addHeader(RETRY_ATTEMPT_HEADER, String.valueOf(executionCount));
@@ -254,8 +258,8 @@ boolean isBuffered(final Request request) {
254258
request,
255259
"RetryHandler_Intercept - attempt " + executionCount,
256260
span);
257-
retrySpan.setAttribute("http.retry_count", executionCount);
258-
retrySpan.setAttribute("http.status_code", response.code());
261+
retrySpan.setAttribute(HTTP_REQUEST_RESEND_COUNT, executionCount);
262+
retrySpan.setAttribute(HTTP_RESPONSE_STATUS_CODE, response.code());
259263
retrySpan.end();
260264
response = chain.proceed(request);
261265
if (response == null)

0 commit comments

Comments
 (0)