Skip to content

Commit

Permalink
fixes bug setting service names to empty (#1428)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
codefromthecrypt committed Apr 6, 2024
1 parent 69e30f3 commit fe3c8b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions brave/src/main/java/brave/handler/MutableSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,9 @@ public void kind(@Nullable Kind kind) {
public void localServiceName(@Nullable String localServiceName) {
if (localServiceName == null || localServiceName.isEmpty()) {
this.localServiceName = null;
} else {
this.localServiceName = localServiceName;
}
this.localServiceName = localServiceName;
}

/**
Expand Down Expand Up @@ -438,8 +439,9 @@ public void localPort(int localPort) {
public void remoteServiceName(@Nullable String remoteServiceName) {
if (remoteServiceName == null || remoteServiceName.isEmpty()) {
this.remoteServiceName = null;
} else {
this.remoteServiceName = remoteServiceName;
}
this.remoteServiceName = remoteServiceName;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions brave/src/test/java/brave/handler/MutableSpanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,27 @@ class Tag {
);
}

@Test void localServiceNameCoercesEmptyToNull() {
MutableSpan span = new MutableSpan();
span.localServiceName("FavStar");
span.localServiceName("");
assertThat(span.localServiceName()).isNull();
}

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

@Test void remoteServiceNameCoercesEmptyToNull() {
MutableSpan span = new MutableSpan();
span.remoteServiceName("FavStar");
span.remoteServiceName("");
assertThat(span.remoteServiceName()).isNull();
}

@Test void remoteServiceNamePreservesCase() {
String expectedRemoteServiceName = "FavStar";
MutableSpan span = new MutableSpan();
Expand Down

0 comments on commit fe3c8b4

Please sign in to comment.