Search in sources :

Example 1 with ExportTraceServiceRequest

use of io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest in project instrumentation-java by census-instrumentation.

the class OcAgentTraceExporterIntegrationTest method testExportSpans.

@Test
public void testExportSpans() throws InterruptedException, IOException {
    // Mock a real-life scenario in production, where Agent is not enabled at first, then enabled
    // after an outage. Users should be able to see traces shortly after Agent is up.
    // Configure to be always-sampled.
    TraceConfig traceConfig = Tracing.getTraceConfig();
    TraceParams activeTraceParams = traceConfig.getActiveTraceParams();
    traceConfig.updateActiveTraceParams(activeTraceParams.toBuilder().setSampler(Samplers.alwaysSample()).build());
    // Register the OcAgent Exporter first.
    // Agent is not yet up and running so Exporter will just retry connection.
    OcAgentTraceExporter.createAndRegister(OcAgentTraceExporterConfiguration.builder().setServiceName(SERVICE_NAME).setUseInsecure(true).setEnableConfig(false).build());
    // Create one root span and 5 children.
    try (Scope scope = tracer.spanBuilder("root").startScopedSpan()) {
        for (int i = 0; i < 5; i++) {
            // Fake work
            doWork("first-iteration-child-" + i, i);
        }
    }
    // Wait 5s so that SpanExporter exports exports all spans.
    Thread.sleep(5000);
    // No interaction with Agent so far.
    assertThat(fakeOcAgentTraceServiceGrpc.getExportTraceServiceRequests()).isEmpty();
    // Image an outage happened, now start Agent. Exporter should be able to connect to Agent
    // when the next batch of SpanData arrives.
    agent.start();
    // Create one root span and 8 children.
    try (Scope scope = tracer.spanBuilder("root2").startScopedSpan()) {
        for (int i = 0; i < 8; i++) {
            // Fake work
            doWork("second-iteration-child-" + i, i);
        }
    }
    // Wait 5s so that SpanExporter exports exports all spans.
    Thread.sleep(5000);
    List<ExportTraceServiceRequest> exportRequests = fakeOcAgentTraceServiceGrpc.getExportTraceServiceRequests();
    assertThat(exportRequests.size()).isAtLeast(2);
    ExportTraceServiceRequest firstRequest = exportRequests.get(0);
    Node expectedNode = OcAgentNodeUtils.getNodeInfo(SERVICE_NAME);
    Node actualNode = firstRequest.getNode();
    assertThat(actualNode.getIdentifier().getHostName()).isEqualTo(expectedNode.getIdentifier().getHostName());
    assertThat(actualNode.getIdentifier().getPid()).isEqualTo(expectedNode.getIdentifier().getPid());
    assertThat(actualNode.getLibraryInfo()).isEqualTo(expectedNode.getLibraryInfo());
    assertThat(actualNode.getServiceInfo()).isEqualTo(expectedNode.getServiceInfo());
    List<io.opencensus.proto.trace.v1.Span> spanProtos = new ArrayList<>();
    for (int i = 1; i < exportRequests.size(); i++) {
        spanProtos.addAll(exportRequests.get(i).getSpansList());
    }
    // On some platforms (e.g Windows) SpanData will never be dropped, so spans from the first batch
    // may also be exported after Agent is up.
    assertThat(spanProtos.size()).isAtLeast(9);
    Set<String> exportedSpanNames = new HashSet<>();
    for (io.opencensus.proto.trace.v1.Span spanProto : spanProtos) {
        if ("root2".equals(spanProto.getName().getValue())) {
            assertThat(spanProto.getChildSpanCount().getValue()).isEqualTo(8);
            assertThat(spanProto.getParentSpanId()).isEqualTo(ByteString.EMPTY);
        } else if ("root".equals(spanProto.getName().getValue())) {
            // This won't happen on Linux but does happen on Windows.
            assertThat(spanProto.getChildSpanCount().getValue()).isEqualTo(5);
            assertThat(spanProto.getParentSpanId()).isEqualTo(ByteString.EMPTY);
        }
        exportedSpanNames.add(spanProto.getName().getValue());
    }
    // The second batch of spans should be exported no matter what.
    assertThat(exportedSpanNames).contains("root2");
    for (int i = 0; i < 8; i++) {
        assertThat(exportedSpanNames).contains("second-iteration-child-" + i);
    }
}
Also used : ExportTraceServiceRequest(io.opencensus.proto.agent.trace.v1.ExportTraceServiceRequest) Node(io.opencensus.proto.agent.common.v1.Node) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) TraceParams(io.opencensus.trace.config.TraceParams) Span(io.opencensus.trace.Span) Scope(io.opencensus.common.Scope) TraceConfig(io.opencensus.trace.config.TraceConfig) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with ExportTraceServiceRequest

use of io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest in project instrumentation-java by census-instrumentation.

the class OcAgentTraceExporterHandler method createExportRpcHandlerAndConnect.

@Nullable
private static OcAgentTraceServiceExportRpcHandler createExportRpcHandlerAndConnect(TraceServiceGrpc.TraceServiceStub stub, Node node) {
    @Nullable OcAgentTraceServiceExportRpcHandler exportRpcHandler = null;
    try {
        exportRpcHandler = OcAgentTraceServiceExportRpcHandler.create(stub);
        // First message must have Node set.
        ExportTraceServiceRequest firstExportReq = ExportTraceServiceRequest.newBuilder().setNode(node).build();
        exportRpcHandler.onExport(firstExportReq);
    } catch (RuntimeException e) {
        if (exportRpcHandler != null) {
            exportRpcHandler.onComplete(e);
        }
    }
    return exportRpcHandler;
}
Also used : ExportTraceServiceRequest(io.opencensus.proto.agent.trace.v1.ExportTraceServiceRequest) Nullable(javax.annotation.Nullable) Nullable(javax.annotation.Nullable)

Example 3 with ExportTraceServiceRequest

use of io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest in project instrumentation-java by census-instrumentation.

the class OcAgentTraceServiceRpcHandlersTest method export_createAndExport.

@Test
public void export_createAndExport() {
    OcAgentTraceServiceExportRpcHandler exportRpcHandler = OcAgentTraceServiceExportRpcHandler.create(getStub(serverName));
    ExportTraceServiceRequest request = ExportTraceServiceRequest.newBuilder().build();
    exportRpcHandler.onExport(request);
    assertThat(traceServiceGrpc.getExportTraceServiceRequests()).containsExactly(request);
}
Also used : ExportTraceServiceRequest(io.opencensus.proto.agent.trace.v1.ExportTraceServiceRequest) Test(org.junit.Test)

Example 4 with ExportTraceServiceRequest

use of io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest in project inspectit-ocelot by inspectIT.

the class OpenTelemetryProtoConverterTest method getTestRequest.

private ExportTraceServiceRequest getTestRequest(String file) throws Exception {
    InputStream resource = this.getClass().getResourceAsStream(file);
    String traceRequestJson = IOUtils.toString(resource, StandardCharsets.UTF_8);
    ExportTraceServiceRequest.Builder requestBuilder = ExportTraceServiceRequest.newBuilder();
    JsonFormat.parser().merge(traceRequestJson, requestBuilder);
    return requestBuilder.build();
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) InputStream(java.io.InputStream)

Example 5 with ExportTraceServiceRequest

use of io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest in project opentelemetry-java by open-telemetry.

the class OtlpHttpSpanExporterTest method exportAndAssertResult.

private static ExportTraceServiceRequest exportAndAssertResult(OtlpHttpSpanExporter otlpHttpSpanExporter, boolean expectedResult) {
    List<SpanData> spans = Collections.singletonList(generateFakeSpan());
    CompletableResultCode resultCode = otlpHttpSpanExporter.export(spans);
    resultCode.join(10, TimeUnit.SECONDS);
    assertThat(resultCode.isSuccess()).isEqualTo(expectedResult);
    List<ResourceSpans> resourceSpans = Arrays.stream(ResourceSpansMarshaler.create(spans)).map(marshaler -> {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            marshaler.writeBinaryTo(bos);
            return ResourceSpans.parseFrom(bos.toByteArray());
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }).collect(Collectors.toList());
    return ExportTraceServiceRequest.newBuilder().addAllResourceSpans(resourceSpans).build();
}
Also used : RecordedRequest(com.linecorp.armeria.testing.junit5.server.mock.RecordedRequest) TraceFlags(io.opentelemetry.api.trace.TraceFlags) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) InetAddress(java.net.InetAddress) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Duration(java.time.Duration) Level(org.slf4j.event.Level) GzipSource(okio.GzipSource) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) HttpResponse(com.linecorp.armeria.common.HttpResponse) MockWebServerExtension(com.linecorp.armeria.testing.junit5.server.mock.MockWebServerExtension) SpanContext(io.opentelemetry.api.trace.SpanContext) Status(com.google.rpc.Status) HttpMethod(com.linecorp.armeria.common.HttpMethod) SpanKind(io.opentelemetry.api.trace.SpanKind) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) OkHttpExporter(io.opentelemetry.exporter.internal.okhttp.OkHttpExporter) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test) List(java.util.List) LogCapturer(io.github.netmikey.logunit.api.LogCapturer) HeldCertificate(okhttp3.tls.HeldCertificate) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) SpanData(io.opentelemetry.sdk.trace.data.SpanData) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) ServerBuilder(com.linecorp.armeria.server.ServerBuilder) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StatusData(io.opentelemetry.sdk.trace.data.StatusData) MediaType(com.linecorp.armeria.common.MediaType) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) TraceState(io.opentelemetry.api.trace.TraceState) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) RetryPolicy(io.opentelemetry.exporter.internal.retry.RetryPolicy) HttpStatus(com.linecorp.armeria.common.HttpStatus) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ResourceSpansMarshaler(io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler) LoggingEvent(org.slf4j.event.LoggingEvent) Buffer(okio.Buffer) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TimeUnit(java.util.concurrent.TimeUnit) ExportTraceServiceResponse(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse) RetryUtil(io.opentelemetry.exporter.internal.retry.RetryUtil) Message(com.google.protobuf.Message) Collections(java.util.Collections) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) TestSpanData(io.opentelemetry.sdk.testing.trace.TestSpanData) SpanData(io.opentelemetry.sdk.trace.data.SpanData) TestSpanData(io.opentelemetry.sdk.testing.trace.TestSpanData) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) UncheckedIOException(java.io.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans)

Aggregations

ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)36 Test (org.junit.Test)21 ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)13 Record (com.amazon.dataprepper.model.record.Record)11 ArrayList (java.util.ArrayList)11 ByteString (com.google.protobuf.ByteString)9 HashMap (java.util.HashMap)9 Map (java.util.Map)9 List (java.util.List)8 InstrumentationLibrarySpans (io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans)7 Span (io.opentelemetry.proto.trace.v1.Span)7 Test (org.junit.jupiter.api.Test)6 TraceServiceGrpc (io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc)5 AggregatedHttpRequest (com.linecorp.armeria.common.AggregatedHttpRequest)4 Measurement (io.micrometer.core.instrument.Measurement)4 StringJoiner (java.util.StringJoiner)4 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)3 ConnectionConfiguration (com.amazon.dataprepper.plugins.sink.opensearch.ConnectionConfiguration)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3