Skip to content

Commit 85a92cc

Browse files
Fixed the span drop criteria parsing logic (#287)
- Splitting tag key/value match condition based on the first colon
1 parent 6d111a2 commit 85a92cc

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

span-normalizer/span-normalizer/src/main/java/org/hypertrace/core/spannormalizer/jaeger/SpanFilter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ public boolean shouldDropSpan(
115115
@Nullable
116116
private Pair<String, String> convertToPair(String s) {
117117
if (s != null && s.contains(COLON)) {
118-
String[] parts = s.split(COLON);
119-
if (parts.length == 2) {
120-
return Pair.of(parts[0], parts[1]);
121-
}
118+
int colonIndex = s.indexOf(COLON);
119+
return Pair.of(s.substring(0, colonIndex), s.substring(colonIndex + 1));
122120
}
123121
return null;
124122
}

span-normalizer/span-normalizer/src/test/java/org/hypertrace/core/spannormalizer/jaeger/JaegerSpanPreProcessorTest.java

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,49 @@ public void testDropSpanWithMultipleCriterion() {
153153
"tenantIdTagKey",
154154
"tenant-key",
155155
"spanDropCriterion",
156-
List.of("foo:bar,k1:v1", "k2:v2"))));
156+
List.of("foo:bar,k1:v1", "k2:v2", "http.url:https://foo.bar"))));
157157

158158
JaegerSpanPreProcessor jaegerSpanPreProcessor =
159159
new JaegerSpanPreProcessor(ConfigFactory.parseMap(configs));
160160
Process process = Process.newBuilder().setServiceName("testService").build();
161-
Span span =
162-
Span.newBuilder()
163-
.setProcess(process)
164-
.addTags(KeyValue.newBuilder().setKey("tenant-key").setVStr(tenantId).build())
165-
.addTags(KeyValue.newBuilder().setKey("foo").setVStr("bar").build())
166-
.addTags(KeyValue.newBuilder().setKey("k2").setVStr("v2").build())
167-
.build();
168-
PreProcessedSpan preProcessedSpan = jaegerSpanPreProcessor.preProcessSpan(span);
169-
Assertions.assertNull(preProcessedSpan);
161+
{
162+
Span span =
163+
Span.newBuilder()
164+
.setProcess(process)
165+
.addTags(KeyValue.newBuilder().setKey("tenant-key").setVStr(tenantId).build())
166+
.addTags(KeyValue.newBuilder().setKey("foo").setVStr("bar").build())
167+
.addTags(KeyValue.newBuilder().setKey("k2").setVStr("v2").build())
168+
.build();
169+
PreProcessedSpan preProcessedSpan = jaegerSpanPreProcessor.preProcessSpan(span);
170+
// Span dropped due to matching condition: k2:v2
171+
Assertions.assertNull(preProcessedSpan);
172+
}
173+
174+
{
175+
Span span =
176+
Span.newBuilder()
177+
.setProcess(process)
178+
.addTags(KeyValue.newBuilder().setKey("tenant-key").setVStr(tenantId).build())
179+
.addTags(KeyValue.newBuilder().setKey("foo").setVStr("bar").build())
180+
.addTags(KeyValue.newBuilder().setKey("http.url").setVStr("https://foo.bar").build())
181+
.build();
182+
PreProcessedSpan preProcessedSpan = jaegerSpanPreProcessor.preProcessSpan(span);
183+
// Span dropped due to matching condition: http.url:https://foo.bar
184+
Assertions.assertNull(preProcessedSpan);
185+
}
186+
187+
{
188+
Span span =
189+
Span.newBuilder()
190+
.setProcess(process)
191+
.addTags(KeyValue.newBuilder().setKey("tenant-key").setVStr(tenantId).build())
192+
.addTags(KeyValue.newBuilder().setKey("foo").setVStr("bar").build())
193+
.addTags(KeyValue.newBuilder().setKey("http.url").setVStr("https://valid").build())
194+
.build();
195+
PreProcessedSpan preProcessedSpan = jaegerSpanPreProcessor.preProcessSpan(span);
196+
// Span not dropped since there is no matching condition
197+
Assertions.assertNotNull(preProcessedSpan);
198+
}
170199
}
171200

172201
@Test

0 commit comments

Comments
 (0)