Search in sources :

Example 1 with OtlpGrpcLogExporterBuilder

use of io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder in project splunk-otel-java by signalfx.

the class LogExporterBuilderTest method testCustomEndpoint.

@Test
void testCustomEndpoint() {
    String endpoint = "http://example.com:9122/";
    Config config = mock(Config.class);
    OtlpGrpcLogExporterBuilder builder = mock(OtlpGrpcLogExporterBuilder.class);
    OtlpGrpcLogExporter expected = mock(OtlpGrpcLogExporter.class);
    when(builder.addHeader(EXTRA_CONTENT_TYPE, STACKTRACES_HEADER_VALUE)).thenReturn(builder);
    when(builder.build()).thenReturn(expected);
    when(config.getString(Configuration.CONFIG_KEY_OTEL_OTLP_URL, null)).thenReturn("http://shadowed.example.com:9122/");
    when(config.getString(Configuration.CONFIG_KEY_INGEST_URL, "http://shadowed.example.com:9122/")).thenReturn(endpoint);
    LogExporter exporter = LogExporterBuilder.fromConfig(config, () -> builder);
    assertNotNull(exporter);
    verify(builder).setEndpoint(endpoint);
}
Also used : Config(io.opentelemetry.instrumentation.api.config.Config) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) OtlpGrpcLogExporter(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OtlpGrpcLogExporterBuilder(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder) OtlpGrpcLogExporter(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter) Test(org.junit.jupiter.api.Test)

Example 2 with OtlpGrpcLogExporterBuilder

use of io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder in project splunk-otel-java by signalfx.

the class LogExporterBuilder method fromConfig.

@VisibleForTesting
static LogExporter fromConfig(Config config, Supplier<OtlpGrpcLogExporterBuilder> makeBuilder) {
    OtlpGrpcLogExporterBuilder builder = makeBuilder.get();
    String ingestUrl = Configuration.getConfigUrl(config);
    if (ingestUrl != null) {
        builder.setEndpoint(ingestUrl);
    }
    return builder.addHeader(EXTRA_CONTENT_TYPE, STACKTRACES_HEADER_VALUE).build();
}
Also used : OtlpGrpcLogExporterBuilder(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with OtlpGrpcLogExporterBuilder

use of io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder in project opentelemetry-java by open-telemetry.

the class LogExporterConfiguration method configureOtlpLogs.

// Visible for testing
@Nullable
static LogExporter configureOtlpLogs(ConfigProperties config, MeterProvider meterProvider) {
    String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_LOGS, config);
    if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) {
        try {
            ClasspathUtil.checkClassExists("io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogExporter", "OTLP HTTP Log Exporter", "opentelemetry-exporter-otlp-http-logs");
        } catch (ConfigurationException e) {
            // Squash this for now until logs are stable
            return null;
        }
        OtlpHttpLogExporterBuilder builder = OtlpHttpLogExporter.builder();
        OtlpConfigUtil.configureOtlpExporterBuilder(DATA_TYPE_LOGS, 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)) {
        try {
            ClasspathUtil.checkClassExists("io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter", "OTLP gRPC Log Exporter", "opentelemetry-exporter-otlp-logs");
        } catch (ConfigurationException e) {
            // Squash this for now until logs are stable
            return null;
        }
        OtlpGrpcLogExporterBuilder builder = OtlpGrpcLogExporter.builder();
        OtlpConfigUtil.configureOtlpExporterBuilder(DATA_TYPE_LOGS, 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 logs protocol: " + protocol);
    }
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) OtlpGrpcLogExporter(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter) OtlpHttpLogExporter(io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogExporter) BiFunction(java.util.function.BiFunction) Set(java.util.Set) SystemOutLogExporter(io.opentelemetry.exporter.logging.SystemOutLogExporter) OtlpHttpLogExporterBuilder(io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogExporterBuilder) HashMap(java.util.HashMap) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) PROTOCOL_GRPC(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC) RetryUtil(io.opentelemetry.exporter.internal.retry.RetryUtil) PROTOCOL_HTTP_PROTOBUF(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF) Map(java.util.Map) DATA_TYPE_LOGS(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_LOGS) MeterProvider(io.opentelemetry.api.metrics.MeterProvider) Collections(java.util.Collections) OtlpGrpcLogExporterBuilder(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder) Nullable(javax.annotation.Nullable) OtlpHttpLogExporterBuilder(io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogExporterBuilder) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) OtlpGrpcLogExporterBuilder(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder) Nullable(javax.annotation.Nullable)

Example 4 with OtlpGrpcLogExporterBuilder

use of io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder in project splunk-otel-java by signalfx.

the class LogExporterBuilderTest method testBuildSimple.

@Test
void testBuildSimple() {
    Config config = mock(Config.class);
    OtlpGrpcLogExporterBuilder builder = mock(OtlpGrpcLogExporterBuilder.class);
    OtlpGrpcLogExporter expected = mock(OtlpGrpcLogExporter.class);
    when(builder.addHeader(EXTRA_CONTENT_TYPE, STACKTRACES_HEADER_VALUE)).thenReturn(builder);
    when(builder.build()).thenReturn(expected);
    LogExporter exporter = LogExporterBuilder.fromConfig(config, () -> builder);
    assertSame(expected, exporter);
    verify(builder, never()).setEndpoint(anyString());
}
Also used : Config(io.opentelemetry.instrumentation.api.config.Config) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) OtlpGrpcLogExporter(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter) OtlpGrpcLogExporterBuilder(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder) OtlpGrpcLogExporter(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter) Test(org.junit.jupiter.api.Test)

Aggregations

OtlpGrpcLogExporterBuilder (io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder)4 OtlpGrpcLogExporter (io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter)3 LogExporter (io.opentelemetry.sdk.logs.export.LogExporter)3 Config (io.opentelemetry.instrumentation.api.config.Config)2 Test (org.junit.jupiter.api.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MeterProvider (io.opentelemetry.api.metrics.MeterProvider)1 RetryUtil (io.opentelemetry.exporter.internal.retry.RetryUtil)1 SystemOutLogExporter (io.opentelemetry.exporter.logging.SystemOutLogExporter)1 OtlpHttpLogExporter (io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogExporter)1 OtlpHttpLogExporterBuilder (io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogExporterBuilder)1 DATA_TYPE_LOGS (io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_LOGS)1 PROTOCOL_GRPC (io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC)1 PROTOCOL_HTTP_PROTOBUF (io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF)1 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)1 ConfigurationException (io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1