Skip to content

Commit

Permalink
Preserve case of local and remote service names (#1080)
Browse files Browse the repository at this point in the history
  • Loading branch information
csabakos authored Feb 11, 2020
1 parent 3b434dc commit d19b014
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
9 changes: 4 additions & 5 deletions brave/src/main/java/brave/Tracing.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 The OpenZipkin Authors
* Copyright 2013-2020 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -30,7 +30,6 @@
import java.io.Closeable;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -152,8 +151,8 @@ public static final class Builder {
Set<FinishedSpanHandler> finishedSpanHandlers = new LinkedHashSet<>(); // dupes not ok

/**
* Lower-case label of the remote node in the service graph, such as "favstar". Avoid names with
* variables or unique identifiers embedded. Defaults to "unknown".
* Label of the remote node in the service graph, such as "favstar". Avoid names with variables
* or unique identifiers embedded. Defaults to "unknown".
*
* <p>This is a primary label for trace lookup and aggregation, so it should be intuitive and
* consistent. Many use a name from service discovery.
Expand All @@ -164,7 +163,7 @@ public Builder localServiceName(String localServiceName) {
if (localServiceName == null || localServiceName.isEmpty()) {
throw new IllegalArgumentException(localServiceName + " is not a valid serviceName");
}
this.localServiceName = localServiceName.toLowerCase(Locale.ROOT);
this.localServiceName = localServiceName;
return this;
}

Expand Down
7 changes: 3 additions & 4 deletions brave/src/main/java/brave/handler/MutableSpan.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 The OpenZipkin Authors
* Copyright 2013-2020 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -19,7 +19,6 @@
import brave.internal.Nullable;
import brave.propagation.TraceContext;
import java.util.ArrayList;
import java.util.Locale;

/**
* This represents a span except for its {@link TraceContext}. It is mutable, for late adjustments.
Expand Down Expand Up @@ -148,7 +147,7 @@ public void localServiceName(String localServiceName) {
if (localServiceName == null || localServiceName.isEmpty()) {
throw new NullPointerException("localServiceName is empty");
}
this.localServiceName = localServiceName.toLowerCase(Locale.ROOT);
this.localServiceName = localServiceName;
}

/** When null {@link brave.Tracing.Builder#localIp(String) default} will be used for zipkin. */
Expand Down Expand Up @@ -184,7 +183,7 @@ public void remoteServiceName(String remoteServiceName) {
if (remoteServiceName == null || remoteServiceName.isEmpty()) {
throw new NullPointerException("remoteServiceName is empty");
}
this.remoteServiceName = remoteServiceName.toLowerCase(Locale.ROOT);
this.remoteServiceName = remoteServiceName;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion brave/src/test/java/brave/TracingTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 The OpenZipkin Authors
* Copyright 2013-2020 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -69,6 +69,12 @@ public class TracingTest {
assertThat(spans).isEmpty();
}

@Test public void localServiceNamePreservesCase() {
String expectedLocalServiceName = "FavStar";
Tracing.Builder builder = Tracing.newBuilder().localServiceName(expectedLocalServiceName);
assertThat(builder).extracting("localServiceName").isEqualTo(expectedLocalServiceName);
}

@Test public void spanReporter_getsLocalEndpointInfo() {
String expectedLocalServiceName = "favistar", expectedLocalIp = "1.2.3.4";
int expectedLocalPort = 80;
Expand Down
16 changes: 15 additions & 1 deletion brave/src/test/java/brave/handler/MutableSpanTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 The OpenZipkin Authors
* Copyright 2013-2020 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -178,6 +178,20 @@ class Tag {
);
}

@Test public void localServiceNamePreservesCase() {
String expectedLocalServiceName = "FavStar";
MutableSpan span = new MutableSpan();
span.localServiceName(expectedLocalServiceName);
assertThat(span.localServiceName()).isEqualTo(expectedLocalServiceName);
}

@Test public void remoteServiceNamePreservesCase() {
String expectedRemoteServiceName = "FavStar";
MutableSpan span = new MutableSpan();
span.remoteServiceName(expectedRemoteServiceName);
assertThat(span.remoteServiceName()).isEqualTo(expectedRemoteServiceName);
}

/**
* {@link brave.Span#kind(Span.Kind)} is nullable, so setting kind to null should work.
*
Expand Down

0 comments on commit d19b014

Please sign in to comment.