use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.
the class OtlpExporterIntegrationTest method testOtlpHttpTraceExport.
@ParameterizedTest
@ValueSource(strings = { "gzip", "none" })
void testOtlpHttpTraceExport(String compression) {
SpanExporter otlpGrpcTraceExporter = OtlpHttpSpanExporter.builder().setEndpoint("http://" + collector.getHost() + ":" + collector.getMappedPort(COLLECTOR_OTLP_HTTP_PORT) + "/v1/traces").setCompression(compression).build();
testTraceExport(otlpGrpcTraceExporter);
}
use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.
the class AutoConfiguredOpenTelemetrySdkTest method builder_addSpanExporterCustomizer.
@Test
void builder_addSpanExporterCustomizer() {
Mockito.lenient().when(spanExporter2.shutdown()).thenReturn(CompletableResultCode.ofSuccess());
SdkTracerProvider sdkTracerProvider = builder.addSpanExporterCustomizer((previous, config) -> {
assertThat(previous).isSameAs(SpanExporter.composite());
return spanExporter1;
}).addSpanExporterCustomizer((previous, config) -> {
assertThat(previous).isSameAs(spanExporter1);
return spanExporter2;
}).build().getOpenTelemetrySdk().getSdkTracerProvider();
assertThat(sdkTracerProvider).extracting("sharedState").extracting("activeSpanProcessor").extracting("worker").extracting("spanExporter").isEqualTo(spanExporter2);
}
use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.
the class SpanExporterConfiguration method configureOtlp.
// Visible for testing
static SpanExporter configureOtlp(ConfigProperties config, MeterProvider meterProvider) {
String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_TRACES, config);
if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) {
ClasspathUtil.checkClassExists("io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter", "OTLP HTTP Trace Exporter", "opentelemetry-exporter-otlp-http-trace");
OtlpHttpSpanExporterBuilder builder = OtlpHttpSpanExporter.builder();
OtlpConfigUtil.configureOtlpExporterBuilder(DATA_TYPE_TRACES, config, builder::setEndpoint, builder::addHeader, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
builder.setMeterProvider(meterProvider);
return builder.build();
} else if (protocol.equals(PROTOCOL_GRPC)) {
ClasspathUtil.checkClassExists("io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter", "OTLP gRPC Trace Exporter", "opentelemetry-exporter-otlp");
OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder();
OtlpConfigUtil.configureOtlpExporterBuilder(DATA_TYPE_TRACES, config, builder::setEndpoint, builder::addHeader, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
builder.setMeterProvider(meterProvider);
return builder.build();
} else {
throw new ConfigurationException("Unsupported OTLP traces protocol: " + protocol);
}
}
use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.
the class SpanExporterConfiguration method configureSpanExporters.
// Visible for testing
static Map<String, SpanExporter> configureSpanExporters(ConfigProperties config, ClassLoader serviceClassLoader, MeterProvider meterProvider, BiFunction<? super SpanExporter, ConfigProperties, ? extends SpanExporter> spanExporterCustomizer) {
Set<String> exporterNames = DefaultConfigProperties.getSet(config, "otel.traces.exporter");
if (exporterNames.contains(EXPORTER_NONE)) {
if (exporterNames.size() > 1) {
throw new ConfigurationException("otel.traces.exporter contains " + EXPORTER_NONE + " along with other exporters");
}
SpanExporter noop = SpanExporter.composite();
SpanExporter customized = spanExporterCustomizer.apply(noop, config);
if (customized == noop) {
return Collections.emptyMap();
}
return Collections.singletonMap(EXPORTER_NONE, customized);
}
if (exporterNames.isEmpty()) {
exporterNames = Collections.singleton("otlp");
}
NamedSpiManager<SpanExporter> spiExportersManager = SpiUtil.loadConfigurable(ConfigurableSpanExporterProvider.class, ConfigurableSpanExporterProvider::getName, ConfigurableSpanExporterProvider::createExporter, config, serviceClassLoader);
return exporterNames.stream().collect(toMap(Function.identity(), exporterName -> spanExporterCustomizer.apply(configureExporter(exporterName, config, spiExportersManager, meterProvider), config)));
}
use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.
the class TracerProviderConfiguration method configureSpanProcessors.
static List<SpanProcessor> configureSpanProcessors(ConfigProperties config, Map<String, SpanExporter> exportersByName, MeterProvider meterProvider) {
Map<String, SpanExporter> exportersByNameCopy = new HashMap<>(exportersByName);
List<SpanProcessor> spanProcessors = new ArrayList<>();
SpanExporter exporter = exportersByNameCopy.remove("logging");
if (exporter != null) {
spanProcessors.add(SimpleSpanProcessor.create(exporter));
}
if (!exportersByNameCopy.isEmpty()) {
SpanExporter compositeSpanExporter = SpanExporter.composite(exportersByNameCopy.values());
spanProcessors.add(configureBatchSpanProcessor(config, compositeSpanExporter, meterProvider));
}
return spanProcessors;
}
Aggregations