Search in sources :

Example 11 with SpanExporter

use of io.opentelemetry.sdk.trace.export.SpanExporter in project splunk-otel-java by signalfx.

the class JaegerThriftSpanExporterFactoryTest method shouldCreateExporterWithoutSplunkAccessToken.

@Test
void shouldCreateExporterWithoutSplunkAccessToken() {
    // given
    given(config.getString(SplunkConfiguration.OTEL_EXPORTER_JAEGER_ENDPOINT)).willReturn("http://localhost:" + port + "/v1/trace");
    // when
    SpanExporter exporter = new JaegerThriftSpanExporterFactory().createExporter(config);
    exporter.export(List.of(prepareMockSpanData())).join(10, TimeUnit.SECONDS);
    // then
    assertNull(TokenCapturingServlet.CAPTURED_SPLUNK_ACCESS_TOKEN.get());
}
Also used : SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Test(org.junit.jupiter.api.Test)

Example 12 with SpanExporter

use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.

the class AutoConfiguredOpenTelemetrySdkTest method tracerProviderCustomizer.

@Test
void tracerProviderCustomizer() {
    InMemorySpanExporter spanExporter = InMemorySpanExporter.create();
    AutoConfiguredOpenTelemetrySdkBuilder autoConfiguration = AutoConfiguredOpenTelemetrySdk.builder().addTracerProviderCustomizer((tracerProviderBuilder, config) -> {
        tracerProviderBuilder.setResource(Resource.builder().put("cat", "meow").build());
        return tracerProviderBuilder.addSpanProcessor(SimpleSpanProcessor.create(spanExporter));
    }).addResourceCustomizer((resource, config) -> resource.merge(Resource.builder().put("cow", "moo").build())).addPropertiesSupplier(() -> Collections.singletonMap("otel.metrics.exporter", "none")).addPropertiesSupplier(() -> Collections.singletonMap("otel.traces.exporter", "none")).addPropertiesSupplier(() -> Collections.singletonMap("otel.logs.exporter", "none")).setResultAsGlobal(false);
    GlobalOpenTelemetry.set(OpenTelemetry.noop());
    AutoConfiguredOpenTelemetrySdk autoConfigured = autoConfiguration.build();
    assertThat(autoConfigured.getResource().getAttribute(stringKey("cow"))).isEqualTo("moo");
    OpenTelemetrySdk sdk = autoConfigured.getOpenTelemetrySdk();
    sdk.getTracerProvider().get("test").spanBuilder("test").startSpan().end();
    List<SpanData> spanItems = spanExporter.getFinishedSpanItems();
    assertThat(spanItems.size()).isEqualTo(1);
    SpanData spanData = spanItems.get(0);
    assertThat(spanData.getResource().getAttribute(stringKey("cat"))).isEqualTo("meow");
    // Ensures the export happened.
    sdk.getSdkTracerProvider().shutdown().join(10, TimeUnit.SECONDS);
}
Also used : InMemorySpanExporter(io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Sampler(io.opentelemetry.sdk.trace.samplers.Sampler) BeforeEach(org.junit.jupiter.api.BeforeEach) LogProcessor(io.opentelemetry.sdk.logs.LogProcessor) SpanId(io.opentelemetry.api.trace.SpanId) W3CTraceContextPropagator(io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk) Resource(io.opentelemetry.sdk.resources.Resource) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) TextMapPropagator(io.opentelemetry.context.propagation.TextMapPropagator) MetricReader(io.opentelemetry.sdk.metrics.export.MetricReader) SimpleSpanProcessor(io.opentelemetry.sdk.trace.export.SimpleSpanProcessor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) ContextKey(io.opentelemetry.context.ContextKey) Context(io.opentelemetry.context.Context) IdGenerator(io.opentelemetry.sdk.trace.IdGenerator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Span(io.opentelemetry.api.trace.Span) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) OpenTelemetry(io.opentelemetry.api.OpenTelemetry) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Mockito.when(org.mockito.Mockito.when) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) Mockito.verify(org.mockito.Mockito.verify) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) Mockito(org.mockito.Mockito) List(java.util.List) InMemorySpanExporter(io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) TextMapGetter(io.opentelemetry.context.propagation.TextMapGetter) MetricReaderFactory(io.opentelemetry.sdk.metrics.export.MetricReaderFactory) TraceId(io.opentelemetry.api.trace.TraceId) SpanData(io.opentelemetry.sdk.trace.data.SpanData) Collections(java.util.Collections) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) SpanData(io.opentelemetry.sdk.trace.data.SpanData) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk) Test(org.junit.jupiter.api.Test)

Example 13 with SpanExporter

use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.

the class ConfigurableSpanExporterTest method configureSpanProcessors_multipleExporters.

@Test
void configureSpanProcessors_multipleExporters() {
    SpanExporter otlpExporter = OtlpGrpcSpanExporter.builder().build();
    SpanExporter zipkinExporter = ZipkinSpanExporter.builder().build();
    ConfigProperties properties = DefaultConfigProperties.createForTest(Collections.singletonMap("otel.traces.exporter", "otlp,zipkin"));
    assertThat(TracerProviderConfiguration.configureSpanProcessors(properties, ImmutableMap.of("otlp", otlpExporter, "zipkin", zipkinExporter), MeterProvider.noop())).hasSize(1).hasAtLeastOneElementOfType(BatchSpanProcessor.class).first().extracting("worker").extracting("spanExporter").asInstanceOf(InstanceOfAssertFactories.type(SpanExporter.class)).satisfies(spanExporter -> {
        assertThat(spanExporter).extracting(spanExporter1 -> spanExporter1.getClass().getSimpleName()).isEqualTo("MultiSpanExporter");
        assertThat(spanExporter).extracting("spanExporters").asInstanceOf(InstanceOfAssertFactories.type(SpanExporter[].class)).satisfies(spanExporters -> {
            assertThat(spanExporters.length).isEqualTo(2);
            assertThat(spanExporters).hasAtLeastOneElementOfType(ZipkinSpanExporter.class).hasAtLeastOneElementOfType(OtlpGrpcSpanExporter.class);
        });
    });
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) ImmutableMap(com.google.common.collect.ImmutableMap) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) BatchSpanProcessor(io.opentelemetry.sdk.trace.export.BatchSpanProcessor) URL(java.net.URL) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) Test(org.junit.jupiter.api.Test) URLClassLoader(java.net.URLClassLoader) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) LoggingSpanExporter(io.opentelemetry.exporter.logging.LoggingSpanExporter) SimpleSpanProcessor(io.opentelemetry.sdk.trace.export.SimpleSpanProcessor) Map(java.util.Map) MeterProvider(io.opentelemetry.api.metrics.MeterProvider) Collections(java.util.Collections) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) LoggingSpanExporter(io.opentelemetry.exporter.logging.LoggingSpanExporter) ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) BatchSpanProcessor(io.opentelemetry.sdk.trace.export.BatchSpanProcessor) Test(org.junit.jupiter.api.Test)

Example 14 with SpanExporter

use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.

the class ConfigurableSpanExporterTest method configureSpanProcessors_simpleSpanProcessor.

@Test
void configureSpanProcessors_simpleSpanProcessor() {
    String exporterName = "logging";
    Map<String, String> propMap = Collections.singletonMap("otel.traces.exporter", exporterName);
    SpanExporter exporter = LoggingSpanExporter.create();
    ConfigProperties properties = DefaultConfigProperties.createForTest(propMap);
    assertThat(TracerProviderConfiguration.configureSpanProcessors(properties, ImmutableMap.of(exporterName, exporter), MeterProvider.noop())).hasSize(1).first().isInstanceOf(SimpleSpanProcessor.class);
}
Also used : ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) LoggingSpanExporter(io.opentelemetry.exporter.logging.LoggingSpanExporter) ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) Test(org.junit.jupiter.api.Test)

Example 15 with SpanExporter

use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.

the class OtlpGrpcConfigTest method configureExportersGeneral.

@Test
void configureExportersGeneral() {
    Map<String, String> props = new HashMap<>();
    props.put("otel.exporter.otlp.endpoint", "https://localhost:" + server.httpsPort());
    props.put("otel.exporter.otlp.certificate", certificate.certificateFile().getAbsolutePath());
    props.put("otel.exporter.otlp.headers", "header-key=header-value");
    props.put("otel.exporter.otlp.compression", "gzip");
    props.put("otel.exporter.otlp.timeout", "15s");
    ConfigProperties properties = DefaultConfigProperties.createForTest(props);
    try (SpanExporter spanExporter = SpanExporterConfiguration.configureExporter("otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop());
        MetricExporter metricExporter = MetricExporterConfiguration.configureOtlpMetrics(properties);
        LogExporter logExporter = LogExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop())) {
        assertThat(spanExporter).extracting("delegate.timeoutNanos").isEqualTo(TimeUnit.SECONDS.toNanos(15));
        assertThat(spanExporter.export(SPAN_DATA).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
        assertThat(server.traceRequests).hasSize(1);
        assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/opentelemetry.proto.collector.trace.v1.TraceService/Export") && headers.contains("header-key", "header-value") && headers.contains("grpc-encoding", "gzip"));
        assertThat(metricExporter).extracting("delegate.timeoutNanos").isEqualTo(TimeUnit.SECONDS.toNanos(15));
        assertThat(metricExporter.export(METRIC_DATA).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
        assertThat(server.metricRequests).hasSize(1);
        assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/opentelemetry.proto.collector.metrics.v1.MetricsService/Export") && headers.contains("header-key", "header-value") && headers.contains("grpc-encoding", "gzip"));
        assertThat(logExporter).extracting("delegate.timeoutNanos").isEqualTo(TimeUnit.SECONDS.toNanos(15));
        assertThat(logExporter.export(LOG_DATA).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
        assertThat(server.logRequests).hasSize(1);
        assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/opentelemetry.proto.collector.logs.v1.LogsService/Export") && headers.contains("header-key", "header-value") && headers.contains("grpc-encoding", "gzip"));
    }
}
Also used : MetricExporter(io.opentelemetry.sdk.metrics.export.MetricExporter) ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) HashMap(java.util.HashMap) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) Test(org.junit.jupiter.api.Test)

Aggregations

SpanExporter (io.opentelemetry.sdk.trace.export.SpanExporter)22 Test (org.junit.jupiter.api.Test)16 OtlpGrpcSpanExporter (io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter)9 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)9 HashMap (java.util.HashMap)9 LoggingSpanExporter (io.opentelemetry.exporter.logging.LoggingSpanExporter)7 ZipkinSpanExporter (io.opentelemetry.exporter.zipkin.ZipkinSpanExporter)7 SimpleSpanProcessor (io.opentelemetry.sdk.trace.export.SimpleSpanProcessor)6 Collections (java.util.Collections)6 Map (java.util.Map)6 MeterProvider (io.opentelemetry.api.metrics.MeterProvider)4 OtlpHttpSpanExporter (io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter)4 ConfigurationException (io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 GlobalOpenTelemetry (io.opentelemetry.api.GlobalOpenTelemetry)2 OpenTelemetry (io.opentelemetry.api.OpenTelemetry)2 AttributeKey.stringKey (io.opentelemetry.api.common.AttributeKey.stringKey)2 Span (io.opentelemetry.api.trace.Span)2 SpanId (io.opentelemetry.api.trace.SpanId)2