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

Revert from Async to Sync #770

Merged
merged 11 commits into from
Nov 10, 2023
Prev Previous commit
Next Next commit
use latest semanticAttribute key values
  • Loading branch information
ramsessanchez committed Nov 7, 2023
commit da71febf1cf215c002a6b91fc8dea8886f6ed85a
2 changes: 1 addition & 1 deletion components/http/okHttp/gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'io.opentelemetry:opentelemetry-api:1.31.0'
implementation 'io.opentelemetry:opentelemetry-context:1.31.0'
implementation 'io.opentelemetry:opentelemetry-semconv:1.30.1-alpha'
implementation 'io.opentelemetry.semconv:opentelemetry-semconv:1.22.0-alpha'
baywet marked this conversation as resolved.
Show resolved Hide resolved
implementation 'com.google.guava:guava:32.1.3-jre'
implementation 'jakarta.annotation:jakarta.annotation-api:2.1.1'
api 'com.squareup.okhttp3:okhttp:4.12.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Scope;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.context.Context;

/** RequestAdapter implementation for OkHttp */
Expand Down Expand Up @@ -621,15 +621,15 @@ private Response getHttpResponseMessage(@Nonnull final RequestInformation reques
Response response = this.client.newCall(getRequestFromRequestInformation(requestInfo, span, spanForAttributes)).execute();
ramsessanchez marked this conversation as resolved.
Show resolved Hide resolved
final String contentLengthHeaderValue = getHeaderValue(response, "Content-Length");
if(contentLengthHeaderValue != null && !contentLengthHeaderValue.isEmpty()) {
final Integer contentLengthHeaderValueAsInt = Integer.parseInt(contentLengthHeaderValue);
spanForAttributes.setAttribute(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, contentLengthHeaderValueAsInt);
final int contentLengthHeaderValueAsInt = Integer.parseInt(contentLengthHeaderValue);
spanForAttributes.setAttribute(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, contentLengthHeaderValueAsInt);
}
final String contentTypeHeaderValue = getHeaderValue(response, "Content-Length");
if(contentTypeHeaderValue != null && !contentTypeHeaderValue.isEmpty()) {
spanForAttributes.setAttribute("http.response_content_type", contentTypeHeaderValue);
}
spanForAttributes.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, response.code());
spanForAttributes.setAttribute(SemanticAttributes.HTTP_FLAVOR, response.protocol().toString().toUpperCase(Locale.ROOT));
spanForAttributes.setAttribute(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, response.code());
spanForAttributes.setAttribute(SemanticAttributes.NETWORK_PROTOCOL_VERSION, response.protocol().toString().toUpperCase(Locale.ROOT));
return this.retryCAEResponseIfRequired(response, requestInfo, span, spanForAttributes, claims);
}
catch (IOException | URISyntaxException ex) {
Expand Down Expand Up @@ -670,7 +670,7 @@ private Response retryCAEResponseIfRequired(@Nonnull final Response response, @N
}
closeResponse(true, response);
span.addEvent(authenticateChallengedEventKey);
spanForAttributes.setAttribute(SemanticAttributes.HTTP_RETRY_COUNT, 1);
spanForAttributes.setAttribute(SemanticAttributes.HTTP_RESEND_COUNT, 1);
return this.getHttpResponseMessage(requestInfo, span, spanForAttributes, responseClaims);
}
return response;
Expand Down Expand Up @@ -739,14 +739,14 @@ public <T> T convertToNativeRequest(@Nonnull final RequestInformation requestInf
protected @Nonnull Request getRequestFromRequestInformation(@Nonnull final RequestInformation requestInfo, @Nonnull final Span parentSpan, @Nonnull final Span spanForAttributes) throws URISyntaxException, MalformedURLException{
final Span span = GlobalOpenTelemetry.getTracer(obsOptions.getTracerInstrumentationName()).spanBuilder("getRequestFromRequestInformation").setParent(Context.current().with(parentSpan)).startSpan();
try(final Scope scope = span.makeCurrent()) {
spanForAttributes.setAttribute(SemanticAttributes.HTTP_METHOD, requestInfo.httpMethod.toString());
spanForAttributes.setAttribute(SemanticAttributes.HTTP_REQUEST_METHOD, requestInfo.httpMethod.toString());
final URL requestURL = requestInfo.getUri().toURL();
if (obsOptions.getIncludeEUIIAttributes()) {
spanForAttributes.setAttribute(SemanticAttributes.HTTP_URL, requestURL.toString());
spanForAttributes.setAttribute(SemanticAttributes.URL_FULL, requestURL.toString());
}
spanForAttributes.setAttribute("http.port", requestURL.getPort());
spanForAttributes.setAttribute(SemanticAttributes.HTTP_HOST, requestURL.getHost());
spanForAttributes.setAttribute(SemanticAttributes.HTTP_SCHEME, requestURL.getProtocol());
spanForAttributes.setAttribute(SemanticAttributes.SERVER_ADDRESS, requestURL.getHost());
spanForAttributes.setAttribute(SemanticAttributes.URL_SCHEME, requestURL.getProtocol());

RequestBody body = requestInfo.content == null ?
null :
Expand Down Expand Up @@ -801,7 +801,7 @@ public void writeTo(@Nonnull BufferedSink sink) throws IOException {
if(contentLengthHeader != null && !contentLengthHeader.isEmpty()) {
final String firstEntryValue = contentLengthHeader.get(0);
if(firstEntryValue != null && !firstEntryValue.isEmpty()) {
spanForAttributes.setAttribute(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, Long.parseLong(firstEntryValue));
spanForAttributes.setAttribute(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, Long.parseLong(firstEntryValue));
}
}
return request;
Expand Down