From fec861666b035830b7a17ca4ecb9b55e14a88029 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Fri, 19 Aug 2022 12:29:59 +0200 Subject: [PATCH] Update OTel version to 1.17 (#335) --- splunk-otel-android-volley/build.gradle.kts | 2 +- .../rum/VolleyHttpClientAttributesGetter.java | 35 ++----------------- .../rum/VolleyNetClientAttributesGetter.java | 5 --- .../com/splunk/rum/VolleyTracingBuilder.java | 2 +- splunk-otel-android/build.gradle.kts | 2 +- .../rum/RumResponseAttributesExtractor.java | 19 ---------- .../RumResponseAttributesExtractorTest.java | 33 +---------------- 7 files changed, 6 insertions(+), 92 deletions(-) diff --git a/splunk-otel-android-volley/build.gradle.kts b/splunk-otel-android-volley/build.gradle.kts index 9ef052cf4..74b18aa1e 100644 --- a/splunk-otel-android-volley/build.gradle.kts +++ b/splunk-otel-android-volley/build.gradle.kts @@ -41,7 +41,7 @@ android { } } -val otelVersion = "1.16.0" +val otelVersion = "1.17.0" val otelAlphaVersion = "$otelVersion-alpha" dependencies { diff --git a/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyHttpClientAttributesGetter.java b/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyHttpClientAttributesGetter.java index 600f4657a..935ba1d11 100644 --- a/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyHttpClientAttributesGetter.java +++ b/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyHttpClientAttributesGetter.java @@ -93,43 +93,12 @@ private List findCaseInsensitive(String name, Map 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 responseHeader( RequestWrapper requestWrapper, @Nullable HttpResponse response, String name) { diff --git a/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyNetClientAttributesGetter.java b/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyNetClientAttributesGetter.java index 530a892f6..9225ea1e8 100644 --- a/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyNetClientAttributesGetter.java +++ b/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyNetClientAttributesGetter.java @@ -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; - } } diff --git a/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyTracingBuilder.java b/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyTracingBuilder.java index ce399a07d..a3dba074c 100644 --- a/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyTracingBuilder.java +++ b/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyTracingBuilder.java @@ -101,7 +101,7 @@ public VolleyTracing build() { new VolleyResponseAttributesExtractor( new ServerTimingHeaderParser())) .addAttributesExtractors(additionalExtractors) - .newClientInstrumenter(ClientRequestHeaderSetter.INSTANCE); + .buildClientInstrumenter(ClientRequestHeaderSetter.INSTANCE); return new VolleyTracing(instrumenter); } diff --git a/splunk-otel-android/build.gradle.kts b/splunk-otel-android/build.gradle.kts index cd8f83edd..83ac0bbea 100644 --- a/splunk-otel-android/build.gradle.kts +++ b/splunk-otel-android/build.gradle.kts @@ -39,7 +39,7 @@ android { } } -val otelVersion = "1.16.0" +val otelVersion = "1.17.0" val otelAlphaVersion = "$otelVersion-alpha" dependencies { diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/RumResponseAttributesExtractor.java b/splunk-otel-android/src/main/java/com/splunk/rum/RumResponseAttributesExtractor.java index 0f7baedbd..76da987e7 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/RumResponseAttributesExtractor.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/RumResponseAttributesExtractor.java @@ -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; @@ -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! - } - } - } } diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/RumResponseAttributesExtractorTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/RumResponseAttributesExtractorTest.java index 987c1fcbf..2b0b320b9 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/RumResponseAttributesExtractorTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/RumResponseAttributesExtractorTest.java @@ -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; @@ -46,7 +45,6 @@ public void spanDecoration() { .message("hello") .code(200) .addHeader("Server-Timing", "headerValue") - .addHeader("Content-Length", "101") .build(); RumResponseAttributesExtractor attributesExtractor = @@ -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 @@ -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)); - } }