Skip to content

Commit

Permalink
Update OTel version to 1.17 (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored Aug 19, 2022
1 parent 9c16aab commit fec8616
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 92 deletions.
2 changes: 1 addition & 1 deletion splunk-otel-android-volley/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ android {
}
}

val otelVersion = "1.16.0"
val otelVersion = "1.17.0"
val otelAlphaVersion = "$otelVersion-alpha"

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,43 +93,12 @@ private List<String> findCaseInsensitive(String name, Map<String, String> header
return result;
}

@Nullable
@Override
public Long requestContentLength(
RequestWrapper requestWrapper, @Nullable HttpResponse response) {
Request<?> request = requestWrapper.getRequest();
try {
return request.getBody() != null ? (long) request.getBody().length : null;
} catch (AuthFailureError authFailureError) {
return null;
}
}

@Nullable
@Override
public Long requestContentLengthUncompressed(
RequestWrapper requestWrapper, @Nullable HttpResponse response) {
return null;
}

@Override
public Integer statusCode(RequestWrapper requestWrapper, @Nullable HttpResponse response) {
public Integer statusCode(
RequestWrapper requestWrapper, HttpResponse response, @Nullable Throwable error) {
return response.getStatusCode();
}

@Override
public Long responseContentLength(
RequestWrapper requestWrapper, @Nullable HttpResponse response) {
return (long) response.getContentLength();
}

@Nullable
@Override
public Long responseContentLengthUncompressed(
RequestWrapper requestWrapper, @Nullable HttpResponse response) {
return null;
}

@Override
public List<String> responseHeader(
RequestWrapper requestWrapper, @Nullable HttpResponse response, String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ public String peerName(RequestWrapper requestWrapper, @Nullable HttpResponse htt
public Integer peerPort(RequestWrapper requestWrapper, @Nullable HttpResponse httpResponse) {
return requestWrapper.getUrl() != null ? requestWrapper.getUrl().getPort() : null;
}

@Override
public String peerIp(RequestWrapper requestWrapper, @Nullable HttpResponse httpResponse) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public VolleyTracing build() {
new VolleyResponseAttributesExtractor(
new ServerTimingHeaderParser()))
.addAttributesExtractors(additionalExtractors)
.newClientInstrumenter(ClientRequestHeaderSetter.INSTANCE);
.buildClientInstrumenter(ClientRequestHeaderSetter.INSTANCE);

return new VolleyTracing(instrumenter);
}
Expand Down
2 changes: 1 addition & 1 deletion splunk-otel-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {
}
}

val otelVersion = "1.16.0"
val otelVersion = "1.17.0"
val otelAlphaVersion = "$otelVersion-alpha"

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import okhttp3.Request;
import okhttp3.Response;

Expand Down Expand Up @@ -52,29 +51,11 @@ public void onEnd(
}

private void onResponse(AttributesBuilder attributes, Response response) {
recordContentLength(attributes, response);
String serverTimingHeader = response.header("Server-Timing");

String[] ids = serverTimingHeaderParser.parse(serverTimingHeader);
if (ids.length == 2) {
attributes.put(LINK_TRACE_ID_KEY, ids[0]);
attributes.put(LINK_SPAN_ID_KEY, ids[1]);
}
}

private void recordContentLength(AttributesBuilder attributesBuilder, Response response) {
// make a best low-impact effort at getting the content length on the response.
String contentLengthHeader = response.header("Content-Length");
if (contentLengthHeader != null) {
try {
long contentLength = Long.parseLong(contentLengthHeader);
if (contentLength > 0) {
attributesBuilder.put(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, contentLength);
}
} catch (NumberFormatException e) {
// who knows what we got back? It wasn't a number!
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
Expand All @@ -46,7 +45,6 @@ public void spanDecoration() {
.message("hello")
.code(200)
.addHeader("Server-Timing", "headerValue")
.addHeader("Content-Length", "101")
.build();

RumResponseAttributesExtractor attributesExtractor =
Expand All @@ -60,8 +58,7 @@ public void spanDecoration() {
.containsOnly(
entry(SplunkRum.COMPONENT_KEY, "http"),
entry(SplunkRum.LINK_TRACE_ID_KEY, "9499195c502eb217c448a68bfe0f967c"),
entry(SplunkRum.LINK_SPAN_ID_KEY, "fe16eca542cd5d86"),
entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 101L));
entry(SplunkRum.LINK_SPAN_ID_KEY, "fe16eca542cd5d86"));
}

@Test
Expand All @@ -87,32 +84,4 @@ public void spanDecoration_noLinkingHeader() {

assertThat(attributes).containsOnly(entry(SplunkRum.COMPONENT_KEY, "http"));
}

@Test
public void spanDecoration_contentLength() {
ServerTimingHeaderParser headerParser = mock(ServerTimingHeaderParser.class);
when(headerParser.parse(null)).thenReturn(new String[0]);

Request fakeRequest = mock(Request.class);
Response response =
new Response.Builder()
.request(fakeRequest)
.protocol(Protocol.HTTP_1_1)
.message("hello")
.addHeader("Content-Length", "101")
.code(200)
.build();

RumResponseAttributesExtractor attributesExtractor =
new RumResponseAttributesExtractor(headerParser);
AttributesBuilder attributesBuilder = Attributes.builder();
attributesExtractor.onEnd(attributesBuilder, Context.root(), fakeRequest, response, null);
attributesExtractor.onStart(attributesBuilder, Context.root(), fakeRequest);
Attributes attributes = attributesBuilder.build();

assertThat(attributes)
.containsOnly(
entry(SplunkRum.COMPONENT_KEY, "http"),
entry(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, 101L));
}
}

0 comments on commit fec8616

Please sign in to comment.