Skip to content

Commit fe3c8b4

Browse files
fixes bug setting service names to empty (#1428)
Signed-off-by: Adrian Cole <[email protected]>
1 parent 69e30f3 commit fe3c8b4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

brave/src/main/java/brave/handler/MutableSpan.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ public void kind(@Nullable Kind kind) {
365365
public void localServiceName(@Nullable String localServiceName) {
366366
if (localServiceName == null || localServiceName.isEmpty()) {
367367
this.localServiceName = null;
368+
} else {
369+
this.localServiceName = localServiceName;
368370
}
369-
this.localServiceName = localServiceName;
370371
}
371372

372373
/**
@@ -438,8 +439,9 @@ public void localPort(int localPort) {
438439
public void remoteServiceName(@Nullable String remoteServiceName) {
439440
if (remoteServiceName == null || remoteServiceName.isEmpty()) {
440441
this.remoteServiceName = null;
442+
} else {
443+
this.remoteServiceName = remoteServiceName;
441444
}
442-
this.remoteServiceName = remoteServiceName;
443445
}
444446

445447
/**

brave/src/test/java/brave/handler/MutableSpanTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,27 @@ class Tag {
285285
);
286286
}
287287

288+
@Test void localServiceNameCoercesEmptyToNull() {
289+
MutableSpan span = new MutableSpan();
290+
span.localServiceName("FavStar");
291+
span.localServiceName("");
292+
assertThat(span.localServiceName()).isNull();
293+
}
294+
288295
@Test void localServiceNamePreservesCase() {
289296
String expectedLocalServiceName = "FavStar";
290297
MutableSpan span = new MutableSpan();
291298
span.localServiceName(expectedLocalServiceName);
292299
assertThat(span.localServiceName()).isEqualTo(expectedLocalServiceName);
293300
}
294301

302+
@Test void remoteServiceNameCoercesEmptyToNull() {
303+
MutableSpan span = new MutableSpan();
304+
span.remoteServiceName("FavStar");
305+
span.remoteServiceName("");
306+
assertThat(span.remoteServiceName()).isNull();
307+
}
308+
295309
@Test void remoteServiceNamePreservesCase() {
296310
String expectedRemoteServiceName = "FavStar";
297311
MutableSpan span = new MutableSpan();

0 commit comments

Comments
 (0)