From 4419f1e9f4c26c6a3801e39a787dc8c641ab3917 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Tue, 9 Aug 2022 22:36:47 +0200 Subject: [PATCH] Remove the local IP address from span (#327) --- .../com/splunk/rum/CustomZipkinEncoder.java | 4 +++ .../splunk/rum/CustomZipkinEncoderTest.java | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/CustomZipkinEncoder.java b/splunk-otel-android/src/main/java/com/splunk/rum/CustomZipkinEncoder.java index 9fe102f0a..6057dbe94 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/CustomZipkinEncoder.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/CustomZipkinEncoder.java @@ -18,6 +18,7 @@ import java.nio.charset.StandardCharsets; import java.util.List; +import zipkin2.Endpoint; import zipkin2.Span; import zipkin2.codec.BytesEncoder; import zipkin2.codec.Encoding; @@ -49,6 +50,9 @@ public int sizeInBytes(Span span) { @Override public byte[] encode(Span span) { + Endpoint localEndpoint = Endpoint.newBuilder().serviceName(span.localServiceName()).build(); + span = span.toBuilder().localEndpoint(localEndpoint).build(); + String properSpanName = span.tags().get(RumAttributeAppender.SPLUNK_OPERATION_KEY.getKey()); // note: this can be optimized, if necessary. Let's keep it simple for now. diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/CustomZipkinEncoderTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/CustomZipkinEncoderTest.java index 548ce24d3..35d0a7179 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/CustomZipkinEncoderTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/CustomZipkinEncoderTest.java @@ -16,11 +16,13 @@ package com.splunk.rum; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import io.opentelemetry.api.trace.SpanId; import io.opentelemetry.api.trace.TraceId; import org.junit.Test; +import zipkin2.Endpoint; import zipkin2.Span; public class CustomZipkinEncoderTest { @@ -42,4 +44,27 @@ public void nameReplacement() { new String(bytes)); assertEquals(bytes.length, encoder.sizeInBytes(span)); } + + @Test + public void removeLocalIp() { + Span span = + Span.newBuilder() + .name("test") + .traceId(TraceId.fromLongs(1, 2)) + .id(SpanId.fromLong(1)) + .localEndpoint( + Endpoint.newBuilder() + .serviceName("test-app") + .ip("127.0.0.1") + .build()) + .build(); + + CustomZipkinEncoder encoder = new CustomZipkinEncoder(); + + byte[] bytes = encoder.encode(span); + assertThat(new String(bytes)) + .contains("\"localEndpoint\":{\"serviceName\":\"test-app\"}") + .doesNotContain( + "\"localEndpoint\":{\"serviceName\":\"test-app\",\"ipv4\":\"127.0.0.1\"}"); + } }