use of com.google.cloud.aiplatform.v1.Endpoint in project opentelemetry-java by open-telemetry.
the class ZipkinSpanExporterTest method generateSpan_ResourceServiceNameMapping.
@Test
void generateSpan_ResourceServiceNameMapping() {
Resource resource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "super-zipkin-service"));
SpanData data = buildStandardSpan().setResource(resource).build();
Endpoint expectedEndpoint = Endpoint.newBuilder().serviceName("super-zipkin-service").ip(exporter.getLocalAddressForTest()).build();
Span expectedZipkinSpan = buildZipkinSpan(Span.Kind.SERVER).toBuilder().localEndpoint(expectedEndpoint).putTag(ZipkinSpanExporter.OTEL_STATUS_CODE, "OK").build();
assertThat(exporter.generateSpan(data)).isEqualTo(expectedZipkinSpan);
}
use of com.google.cloud.aiplatform.v1.Endpoint in project opentelemetry-java by open-telemetry.
the class ZipkinSpanExporterTest method generateSpan_defaultResourceServiceName.
@Test
void generateSpan_defaultResourceServiceName() {
SpanData data = buildStandardSpan().setResource(Resource.empty()).build();
Endpoint expectedEndpoint = Endpoint.newBuilder().serviceName(Resource.getDefault().getAttribute(ResourceAttributes.SERVICE_NAME)).ip(exporter.getLocalAddressForTest()).build();
Span expectedZipkinSpan = buildZipkinSpan(Span.Kind.SERVER).toBuilder().localEndpoint(expectedEndpoint).putTag(ZipkinSpanExporter.OTEL_STATUS_CODE, "OK").build();
assertThat(exporter.generateSpan(data)).isEqualTo(expectedZipkinSpan);
}
use of com.google.cloud.aiplatform.v1.Endpoint in project opentelemetry-java by open-telemetry.
the class ZipkinSpanExporter method getEndpoint.
private Endpoint getEndpoint(SpanData spanData) {
Attributes resourceAttributes = spanData.getResource().getAttributes();
Endpoint.Builder endpoint = Endpoint.newBuilder().ip(localAddress);
// use the service.name from the Resource, if it's been set.
String serviceNameValue = resourceAttributes.get(ResourceAttributes.SERVICE_NAME);
if (serviceNameValue == null) {
serviceNameValue = Resource.getDefault().getAttribute(ResourceAttributes.SERVICE_NAME);
}
// In practice should never be null unless the default Resource spec is changed.
if (serviceNameValue != null) {
endpoint.serviceName(serviceNameValue);
}
return endpoint.build();
}
use of com.google.cloud.aiplatform.v1.Endpoint in project opentelemetry-java by open-telemetry.
the class ZipkinSpanExporter method generateSpan.
Span generateSpan(SpanData spanData) {
Endpoint endpoint = getEndpoint(spanData);
long startTimestamp = toEpochMicros(spanData.getStartEpochNanos());
long endTimestamp = toEpochMicros(spanData.getEndEpochNanos());
Span.Builder spanBuilder = Span.newBuilder().traceId(spanData.getTraceId()).id(spanData.getSpanId()).kind(toSpanKind(spanData)).name(spanData.getName()).timestamp(toEpochMicros(spanData.getStartEpochNanos())).duration(Math.max(1, endTimestamp - startTimestamp)).localEndpoint(endpoint);
if (spanData.getParentSpanContext().isValid()) {
spanBuilder.parentId(spanData.getParentSpanId());
}
Attributes spanAttributes = spanData.getAttributes();
spanAttributes.forEach((key, value) -> spanBuilder.putTag(key.getKey(), valueToString(key, value)));
int droppedAttributes = spanData.getTotalAttributeCount() - spanAttributes.size();
if (droppedAttributes > 0) {
spanBuilder.putTag(OTEL_DROPPED_ATTRIBUTES_COUNT, String.valueOf(droppedAttributes));
}
StatusData status = spanData.getStatus();
// include status code & error.
if (status.getStatusCode() != StatusCode.UNSET) {
spanBuilder.putTag(OTEL_STATUS_CODE, status.getStatusCode().toString());
// add the error tag, if it isn't already in the source span.
if (status.getStatusCode() == StatusCode.ERROR && spanAttributes.get(STATUS_ERROR) == null) {
spanBuilder.putTag(STATUS_ERROR.getKey(), nullToEmpty(status.getDescription()));
}
}
InstrumentationScopeInfo instrumentationScopeInfo = spanData.getInstrumentationScopeInfo();
if (!instrumentationScopeInfo.getName().isEmpty()) {
spanBuilder.putTag(KEY_INSTRUMENTATION_SCOPE_NAME, instrumentationScopeInfo.getName());
// Include instrumentation library name for backwards compatibility
spanBuilder.putTag(KEY_INSTRUMENTATION_LIBRARY_NAME, instrumentationScopeInfo.getName());
}
if (instrumentationScopeInfo.getVersion() != null) {
spanBuilder.putTag(KEY_INSTRUMENTATION_SCOPE_VERSION, instrumentationScopeInfo.getVersion());
// Include instrumentation library name for backwards compatibility
spanBuilder.putTag(KEY_INSTRUMENTATION_LIBRARY_VERSION, instrumentationScopeInfo.getVersion());
}
for (EventData annotation : spanData.getEvents()) {
spanBuilder.addAnnotation(toEpochMicros(annotation.getEpochNanos()), annotation.getName());
}
int droppedEvents = spanData.getTotalRecordedEvents() - spanData.getEvents().size();
if (droppedEvents > 0) {
spanBuilder.putTag(OTEL_DROPPED_EVENTS_COUNT, String.valueOf(droppedEvents));
}
return spanBuilder.build();
}
use of com.google.cloud.aiplatform.v1.Endpoint 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