use of wavefront.report.Annotation in project java by wavefrontHQ.
the class SpanLimitLengthTransformer method apply.
@Nullable
@Override
public Span apply(@Nullable Span span) {
if (span == null)
return null;
long startNanos = ruleMetrics.ruleStart();
try {
if (!v2Predicate.test(span))
return span;
switch(scope) {
case "spanName":
if (span.getName().length() > maxLength && (compiledMatchPattern == null || compiledMatchPattern.matcher(span.getName()).matches())) {
span.setName(truncate(span.getName(), maxLength, actionSubtype));
ruleMetrics.incrementRuleAppliedCounter();
}
break;
case "sourceName":
if (span.getName().length() > maxLength && (compiledMatchPattern == null || compiledMatchPattern.matcher(span.getSource()).matches())) {
span.setSource(truncate(span.getSource(), maxLength, actionSubtype));
ruleMetrics.incrementRuleAppliedCounter();
}
break;
default:
List<Annotation> annotations = new ArrayList<>(span.getAnnotations());
Iterator<Annotation> iterator = annotations.iterator();
boolean changed = false;
while (iterator.hasNext()) {
Annotation entry = iterator.next();
if (entry.getKey().equals(scope) && entry.getValue().length() > maxLength) {
if (compiledMatchPattern == null || compiledMatchPattern.matcher(entry.getValue()).matches()) {
changed = true;
if (actionSubtype == LengthLimitActionType.DROP) {
iterator.remove();
} else {
entry.setValue(truncate(entry.getValue(), maxLength, actionSubtype));
}
ruleMetrics.incrementRuleAppliedCounter();
if (firstMatchOnly) {
break;
}
}
}
}
if (changed) {
span.setAnnotations(annotations);
}
}
return span;
} finally {
ruleMetrics.ruleEnd(startNanos);
}
}
use of wavefront.report.Annotation in project java by wavefrontHQ.
the class SpanForceLowercaseTransformer method apply.
@Nullable
@Override
public Span apply(@Nullable Span span) {
if (span == null)
return null;
long startNanos = ruleMetrics.ruleStart();
try {
if (!v2Predicate.test(span))
return span;
switch(scope) {
case "spanName":
if (compiledMatchPattern != null && !compiledMatchPattern.matcher(span.getName()).matches()) {
break;
}
span.setName(span.getName().toLowerCase());
ruleMetrics.incrementRuleAppliedCounter();
break;
case // source name is not case sensitive in Wavefront, but we'll do it anyway
"sourceName":
if (compiledMatchPattern != null && !compiledMatchPattern.matcher(span.getSource()).matches()) {
break;
}
span.setSource(span.getSource().toLowerCase());
ruleMetrics.incrementRuleAppliedCounter();
break;
default:
for (Annotation x : span.getAnnotations()) {
if (x.getKey().equals(scope) && (compiledMatchPattern == null || compiledMatchPattern.matcher(x.getValue()).matches())) {
x.setValue(x.getValue().toLowerCase());
ruleMetrics.incrementRuleAppliedCounter();
if (firstMatchOnly) {
break;
}
}
}
}
return span;
} finally {
ruleMetrics.ruleEnd(startNanos);
}
}
use of wavefront.report.Annotation in project java by wavefrontHQ.
the class SpanSanitizeTransformer method apply.
@Override
public Span apply(@Nullable Span span) {
if (span == null)
return null;
long startNanos = ruleMetrics.ruleStart();
boolean ruleApplied = false;
// sanitize name and replace '*' with '-'
String name = span.getName();
if (name != null) {
span.setName(sanitizeValue(name).replace('*', '-'));
if (!span.getName().equals(name)) {
ruleApplied = true;
}
}
// sanitize source
String source = span.getSource();
if (source != null) {
span.setSource(sanitizeWithoutQuotes(source));
if (!span.getSource().equals(source)) {
ruleApplied = true;
}
}
if (span.getAnnotations() != null) {
for (Annotation a : span.getAnnotations()) {
// sanitize tag key
String key = a.getKey();
if (key != null) {
a.setKey(sanitizeWithoutQuotes(key));
if (!a.getKey().equals(key)) {
ruleApplied = true;
}
}
// sanitize tag value
String value = a.getValue();
if (value != null) {
a.setValue(sanitizeValue(value));
if (!a.getValue().equals(value)) {
ruleApplied = true;
}
}
}
}
if (ruleApplied) {
ruleMetrics.incrementRuleAppliedCounter();
}
ruleMetrics.ruleEnd(startNanos);
return span;
}
use of wavefront.report.Annotation in project java by wavefrontHQ.
the class ZipkinPortUnificationHandlerTest method testZipkinDurationSampler.
@Test
public void testZipkinDurationSampler() throws Exception {
ZipkinPortUnificationHandler handler = new ZipkinPortUnificationHandler("9411", new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new DurationSampler(5), () -> null), null, null);
Endpoint localEndpoint1 = Endpoint.newBuilder().serviceName("frontend").ip("10.0.0.1").build();
zipkin2.Span spanServer1 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(4 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").addAnnotation(startTime * 1000, "start processing").build();
zipkin2.Span spanServer2 = zipkin2.Span.newBuilder().traceId("3822889fe47043bd").id("3822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(9 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").addAnnotation(startTime * 1000, "start processing").build();
List<zipkin2.Span> zipkinSpanList = ImmutableList.of(spanServer1, spanServer2);
SpanBytesEncoder encoder = SpanBytesEncoder.values()[1];
ByteBuf content = Unpooled.copiedBuffer(encoder.encodeList(zipkinSpanList));
// take care of mocks.
// Reset mock
reset(mockTraceHandler, mockTraceSpanLogsHandler);
// Set Expectation
Span expectedSpan2 = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(9).setName("getservice").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-3822-889fe47043bd").setTraceId("00000000-0000-0000-3822-889fe47043bd").setAnnotations(ImmutableList.of(new Annotation("zipkinSpanId", "3822889fe47043bd"), new Annotation("zipkinTraceId", "3822889fe47043bd"), new Annotation("span.kind", "server"), new Annotation("_spanSecondaryId", "server"), new Annotation("service", "frontend"), new Annotation("http.method", "GET"), new Annotation("http.status_code", "200"), new Annotation("http.url", "none+h1c://localhost:8881/"), new Annotation("application", "Zipkin"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("ipv4", "10.0.0.1"), new Annotation("_spanLogs", "true"))).build();
mockTraceHandler.report(expectedSpan2);
expectLastCall();
mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("default").setTraceId("00000000-0000-0000-3822-889fe47043bd").setSpanId("00000000-0000-0000-3822-889fe47043bd").setSpanSecondaryId("server").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(startTime * 1000).setFields(ImmutableMap.of("annotation", "start processing")).build())).build());
expectLastCall();
replay(mockTraceHandler, mockTraceSpanLogsHandler);
ChannelHandlerContext mockCtx = createNiceMock(ChannelHandlerContext.class);
doMockLifecycle(mockCtx);
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:9411/api/v1/spans", content, true);
handler.handleHttpMessage(mockCtx, httpRequest);
verify(mockTraceHandler, mockTraceSpanLogsHandler);
}
use of wavefront.report.Annotation in project java by wavefrontHQ.
the class ZipkinPortUnificationHandlerTest method testZipkinDebugOverride.
@Test
public void testZipkinDebugOverride() throws Exception {
ZipkinPortUnificationHandler handler = new ZipkinPortUnificationHandler("9411", new NoopHealthCheckManager(), mockTraceHandler, mockTraceSpanLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new DurationSampler(10), () -> null), null, null);
// take care of mocks.
// Reset mock
reset(mockTraceHandler, mockTraceSpanLogsHandler);
// Set Expectation
Span expectedSpan2 = Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(9).setName("getservice").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-3822-889fe47043bd").setTraceId("00000000-0000-0000-3822-889fe47043bd").setAnnotations(ImmutableList.of(new Annotation("zipkinSpanId", "3822889fe47043bd"), new Annotation("zipkinTraceId", "3822889fe47043bd"), new Annotation("span.kind", "server"), new Annotation("_spanSecondaryId", "server"), new Annotation("service", "frontend"), new Annotation("http.method", "GET"), new Annotation("http.status_code", "200"), new Annotation("http.url", "none+h1c://localhost:8881/"), new Annotation("application", "Zipkin"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("debug", "true"), new Annotation("ipv4", "10.0.0.1"), new Annotation("_spanLogs", "true"))).build();
mockTraceHandler.report(expectedSpan2);
expectLastCall();
mockTraceSpanLogsHandler.report(SpanLogs.newBuilder().setCustomer("default").setTraceId("00000000-0000-0000-3822-889fe47043bd").setSpanId("00000000-0000-0000-3822-889fe47043bd").setSpanSecondaryId("server").setLogs(ImmutableList.of(SpanLog.newBuilder().setTimestamp(startTime * 1000).setFields(ImmutableMap.of("annotation", "start processing")).build())).build());
expectLastCall();
mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(6).setName("getservice").setSource(DEFAULT_SOURCE).setSpanId("00000000-0000-0000-5822-889fe47043bd").setTraceId("00000000-0000-0000-5822-889fe47043bd").setAnnotations(ImmutableList.of(new Annotation("zipkinSpanId", "5822889fe47043bd"), new Annotation("zipkinTraceId", "5822889fe47043bd"), new Annotation("span.kind", "server"), new Annotation("service", "frontend"), new Annotation("debug", "debug-id-4"), new Annotation("http.method", "GET"), new Annotation("http.status_code", "200"), new Annotation("http.url", "none+h1c://localhost:8881/"), new Annotation("application", "Zipkin"), new Annotation("cluster", "none"), new Annotation("shard", "none"), new Annotation("debug", "true"), new Annotation("ipv4", "10.0.0.1"))).build());
expectLastCall();
Endpoint localEndpoint1 = Endpoint.newBuilder().serviceName("frontend").ip("10.0.0.1").build();
zipkin2.Span spanServer1 = zipkin2.Span.newBuilder().traceId("2822889fe47043bd").id("2822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(8 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").addAnnotation(startTime * 1000, "start processing").build();
zipkin2.Span spanServer2 = zipkin2.Span.newBuilder().traceId("3822889fe47043bd").id("3822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(9 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").debug(true).addAnnotation(startTime * 1000, "start processing").build();
zipkin2.Span spanServer3 = zipkin2.Span.newBuilder().traceId("4822889fe47043bd").id("4822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(7 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").putTag("debug", "debug-id-1").addAnnotation(startTime * 1000, "start processing").build();
zipkin2.Span spanServer4 = zipkin2.Span.newBuilder().traceId("5822889fe47043bd").id("5822889fe47043bd").kind(zipkin2.Span.Kind.SERVER).name("getservice").timestamp(startTime * 1000).duration(6 * 1000).localEndpoint(localEndpoint1).putTag("http.method", "GET").putTag("http.url", "none+h1c://localhost:8881/").putTag("http.status_code", "200").putTag("debug", "debug-id-4").debug(true).build();
List<zipkin2.Span> zipkinSpanList = ImmutableList.of(spanServer1, spanServer2, spanServer3, spanServer4);
SpanBytesEncoder encoder = SpanBytesEncoder.values()[1];
ByteBuf content = Unpooled.copiedBuffer(encoder.encodeList(zipkinSpanList));
replay(mockTraceHandler, mockTraceSpanLogsHandler);
ChannelHandlerContext mockCtx = createNiceMock(ChannelHandlerContext.class);
doMockLifecycle(mockCtx);
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost:9411/api/v1/spans", content, true);
handler.handleHttpMessage(mockCtx, httpRequest);
verify(mockTraceHandler, mockTraceSpanLogsHandler);
}
Aggregations