use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.
the class OtlpGrpcConfigTest method configureSpanExporter.
@Test
void configureSpanExporter() {
// Set values for general and signal specific properties. Signal specific should override
// general.
Map<String, String> props = new HashMap<>();
props.put("otel.exporter.otlp.endpoint", "http://foo.bar");
props.put("otel.exporter.otlp.certificate", Paths.get("foo", "bar", "baz").toString());
props.put("otel.exporter.otlp.headers", "header-key=dummy-value");
props.put("otel.exporter.otlp.compression", "foo");
props.put("otel.exporter.otlp.timeout", "10s");
props.put("otel.exporter.otlp.traces.endpoint", "https://localhost:" + server.httpsPort());
props.put("otel.exporter.otlp.traces.certificate", certificate.certificateFile().getAbsolutePath());
props.put("otel.exporter.otlp.traces.headers", "header-key=header-value");
props.put("otel.exporter.otlp.traces.compression", "gzip");
props.put("otel.exporter.otlp.traces.timeout", "15s");
try (SpanExporter spanExporter = SpanExporterConfiguration.configureExporter("otlp", DefaultConfigProperties.createForTest(props), NamedSpiManager.createEmpty(), MeterProvider.noop())) {
assertThat(spanExporter).extracting("delegate.timeoutNanos").isEqualTo(TimeUnit.SECONDS.toNanos(15));
assertThat(spanExporter.export(SPAN_DATA).join(10, 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"));
}
}
use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.
the class OpenTelemetrySdkTest method stringRepresentation.
@Test
void stringRepresentation() {
SpanExporter exporter = mock(SpanExporter.class);
when(exporter.toString()).thenReturn("MockSpanExporter{}");
Resource resource = Resource.builder().put(AttributeKey.stringKey("service.name"), "otel-test").build();
OpenTelemetrySdk sdk = OpenTelemetrySdk.builder().setTracerProvider(SdkTracerProvider.builder().setResource(resource).addSpanProcessor(SimpleSpanProcessor.create(SpanExporter.composite(exporter, exporter))).build()).build();
assertThat(sdk.toString()).isEqualTo("OpenTelemetrySdk{" + "tracerProvider=SdkTracerProvider{" + "clock=SystemClock{}, " + "idGenerator=RandomIdGenerator{}, " + "resource=Resource{schemaUrl=null, attributes={service.name=\"otel-test\"}}, " + "spanLimitsSupplier=SpanLimitsValue{maxNumberOfAttributes=128, maxNumberOfEvents=128, maxNumberOfLinks=128, maxNumberOfAttributesPerEvent=128, maxNumberOfAttributesPerLink=128, maxAttributeValueLength=2147483647}, " + "sampler=ParentBased{root:AlwaysOnSampler,remoteParentSampled:AlwaysOnSampler,remoteParentNotSampled:AlwaysOffSampler,localParentSampled:AlwaysOnSampler,localParentNotSampled:AlwaysOffSampler}, " + "spanProcessor=SimpleSpanProcessor{spanExporter=MultiSpanExporter{spanExporters=[MockSpanExporter{}, MockSpanExporter{}]}}}}");
}
use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.
the class OtlpGrpcRetryTest method configureSpanExporterRetryPolicy.
@Test
@SuppressLogger(DefaultGrpcExporter.class)
void configureSpanExporterRetryPolicy() {
Map<String, String> props = new HashMap<>();
props.put("otel.exporter.otlp.traces.endpoint", "https://localhost:" + server.httpsPort());
props.put("otel.exporter.otlp.traces.certificate", certificate.certificateFile().getAbsolutePath());
props.put("otel.experimental.exporter.otlp.retry.enabled", "true");
try (SpanExporter spanExporter = SpanExporterConfiguration.configureExporter("otlp", DefaultConfigProperties.createForTest(props), NamedSpiManager.createEmpty(), MeterProvider.noop())) {
testRetryableStatusCodes(() -> SPAN_DATA, spanExporter::export, server.traceRequests::size);
testDefaultRetryPolicy(() -> SPAN_DATA, spanExporter::export, server.traceRequests::size);
}
}
use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.
the class OtlpHttpConfigTest method configureExportersGeneral.
@Test
void configureExportersGeneral() {
Map<String, String> props = new HashMap<>();
props.put("otel.exporter.otlp.protocol", "http/protobuf");
props.put("otel.exporter.otlp.endpoint", "https://localhost:" + server.httpsPort());
props.put("otel.exporter.otlp.certificate", server.selfSignedCertificate.certificate().getPath());
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);
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.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))).extracting(OkHttpClient::callTimeoutMillis).isEqualTo((int) TimeUnit.SECONDS.toMillis(15));
assertThat(spanExporter.export(Lists.newArrayList(generateFakeSpan())).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.traceRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/v1/traces") && headers.contains("header-key", "header-value") && headers.contains("content-encoding", "gzip"));
assertThat(metricExporter).extracting("delegate.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))).extracting(OkHttpClient::callTimeoutMillis).isEqualTo((int) TimeUnit.SECONDS.toMillis(15));
assertThat(metricExporter.export(Lists.newArrayList(generateFakeMetric())).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.metricRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/v1/metrics") && headers.contains("header-key", "header-value") && headers.contains("content-encoding", "gzip"));
assertThat(logExporter).extracting("delegate.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))).extracting(OkHttpClient::callTimeoutMillis).isEqualTo((int) TimeUnit.SECONDS.toMillis(15));
assertThat(logExporter.export(Lists.newArrayList(generateFakeLog())).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.logRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/v1/logs") && headers.contains("header-key", "header-value") && headers.contains("content-encoding", "gzip"));
}
use of io.opentelemetry.sdk.trace.export.SpanExporter in project opentelemetry-java by open-telemetry.
the class OtlpHttpConfigTest method configureSpanExporter.
@Test
void configureSpanExporter() {
// Set values for general and signal specific properties. Signal specific should override
// general.
Map<String, String> props = new HashMap<>();
props.put("otel.exporter.otlp.protocol", "grpc");
props.put("otel.exporter.otlp.endpoint", "http://foo.bar");
props.put("otel.exporter.otlp.certificate", Paths.get("foo", "bar", "baz").toString());
props.put("otel.exporter.otlp.headers", "header-key=dummy-value");
props.put("otel.exporter.otlp.compression", "foo");
props.put("otel.exporter.otlp.timeout", "10s");
props.put("otel.exporter.otlp.traces.protocol", "http/protobuf");
props.put("otel.exporter.otlp.traces.endpoint", "https://localhost:" + server.httpsPort() + "/v1/traces");
props.put("otel.exporter.otlp.traces.certificate", server.selfSignedCertificate.certificate().getPath());
props.put("otel.exporter.otlp.traces.headers", "header-key=header-value");
props.put("otel.exporter.otlp.traces.compression", "gzip");
props.put("otel.exporter.otlp.traces.timeout", "15s");
SpanExporter spanExporter = SpanExporterConfiguration.configureExporter("otlp", DefaultConfigProperties.createForTest(props), NamedSpiManager.createEmpty(), MeterProvider.noop());
assertThat(spanExporter).extracting("delegate.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))).extracting(OkHttpClient::callTimeoutMillis).isEqualTo((int) TimeUnit.SECONDS.toMillis(15));
assertThat(spanExporter.export(Lists.newArrayList(generateFakeSpan())).join(10, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.traceRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/v1/traces") && headers.contains("header-key", "header-value") && headers.contains("content-encoding", "gzip"));
}
Aggregations