Skip to content

Commit

Permalink
Remove the local IP address from span (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored Aug 9, 2022
1 parent 8451891 commit 4419f1e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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\"}");
}
}

0 comments on commit 4419f1e

Please sign in to comment.