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());
}
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);
}
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);
});
});
}
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);
}
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"));
}
}
Aggregations