Search in sources :

Example 16 with SpanExporter

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"));
    }
}
Also used : SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 17 with SpanExporter

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{}]}}}}");
}
Also used : SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Resource(io.opentelemetry.sdk.resources.Resource) Test(org.junit.jupiter.api.Test)

Example 18 with SpanExporter

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);
    }
}
Also used : SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) HashMap(java.util.HashMap) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Example 19 with SpanExporter

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

Example 20 with SpanExporter

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"));
}
Also used : SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) HashMap(java.util.HashMap) 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