diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java index b634cf7d..e41ff385 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java @@ -255,7 +255,7 @@ private Span startSpan( GlobalOpenTelemetry.getTracer(obsOptions.getTracerInstrumentationName()) .spanBuilder(methodName + " - " + cleanedUriTemplate) .startSpan(); - span.setAttribute("http.uri_template", decodedUriTemplate); + span.setAttribute(URL_TEMPLATE, decodedUriTemplate); return span; } @@ -725,12 +725,11 @@ private Response getHttpResponseMessage( final String contentTypeHeaderValue = getHeaderValue(response, CONTENT_TYPE_HEADER_KEY); if (contentTypeHeaderValue != null && !contentTypeHeaderValue.isEmpty()) { spanForAttributes.setAttribute( - CUSTOM_HTTP_RESPONSE_CONTENT_TYPE, contentTypeHeaderValue); + HTTP_RESPONSE_HEADER_CONTENT_TYPE, contentTypeHeaderValue); } spanForAttributes.setAttribute(HTTP_RESPONSE_STATUS_CODE, response.code()); spanForAttributes.setAttribute( - NETWORK_PROTOCOL_VERSION, - response.protocol().toString().toUpperCase(Locale.ROOT)); + NETWORK_PROTOCOL_NAME, response.protocol().toString().toUpperCase(Locale.ROOT)); return this.retryCAEResponseIfRequired( response, requestInfo, span, spanForAttributes, claims); } catch (IOException | URISyntaxException ex) { @@ -869,7 +868,7 @@ public MediaType contentType() { final String contentType = contentTypes.toArray(new String[] {})[0]; spanForAttributes.setAttribute( - CUSTOM_HTTP_REQUEST_CONTENT_TYPE, contentType); + HTTP_REQUEST_HEADER_CONTENT_TYPE, contentType); return MediaType.parse(contentType); } } diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java index 6fdb412f..7ac1ac94 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java @@ -25,6 +25,12 @@ private TelemetrySemanticConventions() {} public static final AttributeKey HTTP_REQUEST_RESEND_COUNT = longKey("http.request.resend_count"); // stable + /** + * HTTP Request resend delay + */ + public static final AttributeKey HTTP_REQUEST_RESEND_DELAY = + longKey("http.request.resend_delay"); // stable + /** * HTTP Request method */ @@ -34,14 +40,19 @@ private TelemetrySemanticConventions() {} /** * Network connection protocol version */ - public static final AttributeKey NETWORK_PROTOCOL_VERSION = - stringKey("network.protocol.version"); // stable + public static final AttributeKey NETWORK_PROTOCOL_NAME = + stringKey("network.protocol.name"); // stable /** * Full HTTP request URL */ public static final AttributeKey URL_FULL = stringKey("url.full"); // stable + /** + * Full HTTP request URL template + */ + public static final AttributeKey URL_TEMPLATE = stringKey("url.uri_template"); // custom + /** * HTTP request URL scheme */ @@ -72,12 +83,12 @@ private TelemetrySemanticConventions() {} /** * HTTP response content type */ - public static final AttributeKey CUSTOM_HTTP_RESPONSE_CONTENT_TYPE = - stringKey("http.response_content_type"); // custom + public static final AttributeKey HTTP_RESPONSE_HEADER_CONTENT_TYPE = + stringKey("http.response.header.content-type"); // stable /** * HTTP request content type */ - public static final AttributeKey CUSTOM_HTTP_REQUEST_CONTENT_TYPE = - stringKey("http.request_content_type"); // custom + public static final AttributeKey HTTP_REQUEST_HEADER_CONTENT_TYPE = + stringKey("http.request.header.content-type"); // stable } diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/RetryHandler.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/RetryHandler.java index 68fc2658..86a551e6 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/RetryHandler.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/RetryHandler.java @@ -1,5 +1,7 @@ package com.microsoft.kiota.http.middleware; +import static com.microsoft.kiota.http.TelemetrySemanticConventions.*; + import com.microsoft.kiota.http.middleware.options.IShouldRetry; import com.microsoft.kiota.http.middleware.options.RetryHandlerOption; @@ -82,7 +84,8 @@ boolean retryRequest( @Nonnull final Response response, int executionCount, @Nonnull final Request request, - @Nonnull final RetryHandlerOption retryOption) { + @Nonnull final RetryHandlerOption retryOption, + @Nonnull final Span span) { // Should retry option // Use should retry common for all requests @@ -107,6 +110,7 @@ && isBuffered(request) if (shouldRetry) { long retryInterval = getRetryAfter(response, retryOption.delay(), executionCount); + span.setAttribute(HTTP_REQUEST_RESEND_DELAY, Math.round(retryInterval / 1000f)); try { Thread.sleep(retryInterval); } catch (InterruptedException e) { @@ -234,7 +238,7 @@ boolean isBuffered(final Request request) { } int executionCount = 1; - while (retryRequest(response, executionCount, request, retryOption)) { + while (retryRequest(response, executionCount, request, retryOption, span)) { final Request.Builder builder = request.newBuilder() .addHeader(RETRY_ATTEMPT_HEADER, String.valueOf(executionCount)); @@ -254,8 +258,8 @@ boolean isBuffered(final Request request) { request, "RetryHandler_Intercept - attempt " + executionCount, span); - retrySpan.setAttribute("http.retry_count", executionCount); - retrySpan.setAttribute("http.status_code", response.code()); + retrySpan.setAttribute(HTTP_REQUEST_RESEND_COUNT, executionCount); + retrySpan.setAttribute(HTTP_RESPONSE_STATUS_CODE, response.code()); retrySpan.end(); response = chain.proceed(request); if (response == null)