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

fix/otel attributes #1706

Merged
merged 3 commits into from
Dec 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ private TelemetrySemanticConventions() {}
public static final AttributeKey<Long> HTTP_REQUEST_RESEND_COUNT =
longKey("http.request.resend_count"); // stable

/**
* HTTP Request resend delay
*/
public static final AttributeKey<Long> HTTP_REQUEST_RESEND_DELAY =
longKey("http.request.resend_delay"); // stable

/**
* HTTP Request method
*/
Expand All @@ -34,14 +40,19 @@ private TelemetrySemanticConventions() {}
/**
* Network connection protocol version
*/
public static final AttributeKey<String> NETWORK_PROTOCOL_VERSION =
stringKey("network.protocol.version"); // stable
public static final AttributeKey<String> NETWORK_PROTOCOL_NAME =
stringKey("network.protocol.name"); // stable

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

/**
* Full HTTP request URL template
*/
public static final AttributeKey<String> URL_TEMPLATE = stringKey("url.uri_template"); // custom

/**
* HTTP request URL scheme
*/
Expand Down Expand Up @@ -72,12 +83,12 @@ private TelemetrySemanticConventions() {}
/**
* HTTP response content type
*/
public static final AttributeKey<String> CUSTOM_HTTP_RESPONSE_CONTENT_TYPE =
stringKey("http.response_content_type"); // custom
public static final AttributeKey<String> HTTP_RESPONSE_HEADER_CONTENT_TYPE =
stringKey("http.response.header.content-type"); // stable

/**
* HTTP request content type
*/
public static final AttributeKey<String> CUSTOM_HTTP_REQUEST_CONTENT_TYPE =
stringKey("http.request_content_type"); // custom
public static final AttributeKey<String> HTTP_REQUEST_HEADER_CONTENT_TYPE =
stringKey("http.request.header.content-type"); // stable
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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));
Expand All @@ -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)
Expand Down
Loading