Search in sources :

Example 1 with LogExporter

use of io.opentelemetry.sdk.logs.export.LogExporter in project opentelemetry-java by open-telemetry.

the class OtlpGrpcRetryTest method configureLogExporterRetryPolicy.

@Test
@SuppressLogger(DefaultGrpcExporter.class)
void configureLogExporterRetryPolicy() {
    Map<String, String> props = new HashMap<>();
    props.put("otel.exporter.otlp.logs.endpoint", "https://localhost:" + server.httpsPort());
    props.put("otel.exporter.otlp.logs.certificate", certificate.certificateFile().getAbsolutePath());
    props.put("otel.experimental.exporter.otlp.retry.enabled", "true");
    try (LogExporter logExporter = LogExporterConfiguration.configureOtlpLogs(DefaultConfigProperties.createForTest(props), MeterProvider.noop())) {
        testRetryableStatusCodes(() -> LOG_DATA, logExporter::export, server.logRequests::size);
        testDefaultRetryPolicy(() -> LOG_DATA, logExporter::export, server.logRequests::size);
    }
}
Also used : HashMap(java.util.HashMap) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Example 2 with LogExporter

use of io.opentelemetry.sdk.logs.export.LogExporter in project opentelemetry-java by open-telemetry.

the class OtlpHttpConfigTest method configureLogExporter.

@Test
public void configureLogExporter() {
    // 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.logs.protocol", "http/protobuf");
    props.put("otel.exporter.otlp.logs.endpoint", "https://localhost:" + server.httpsPort() + "/v1/logs");
    props.put("otel.exporter.otlp.logs.certificate", server.selfSignedCertificate.certificate().getPath());
    props.put("otel.exporter.otlp.logs.headers", "header-key=header-value");
    props.put("otel.exporter.otlp.logs.compression", "gzip");
    props.put("otel.exporter.otlp.logs.timeout", "15s");
    LogExporter logExporter = LogExporterConfiguration.configureOtlpLogs(DefaultConfigProperties.createForTest(props), MeterProvider.noop());
    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"));
}
Also used : HashMap(java.util.HashMap) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) Test(org.junit.jupiter.api.Test)

Example 3 with LogExporter

use of io.opentelemetry.sdk.logs.export.LogExporter in project opentelemetry-java by open-telemetry.

the class OtlpGrpcConfigTest method configureLogExporter.

@Test
public void configureLogExporter() {
    // 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", "gzip");
    props.put("otel.exporter.otlp.timeout", "10s");
    props.put("otel.exporter.otlp.logs.endpoint", "https://localhost:" + server.httpsPort());
    props.put("otel.exporter.otlp.logs.certificate", certificate.certificateFile().getAbsolutePath());
    props.put("otel.exporter.otlp.logs.headers", "header-key=header-value");
    props.put("otel.exporter.otlp.logs.compression", "gzip");
    props.put("otel.exporter.otlp.logs.timeout", "15s");
    try (LogExporter logExporter = LogExporterConfiguration.configureOtlpLogs(DefaultConfigProperties.createForTest(props), MeterProvider.noop())) {
        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"));
    }
}
Also used : HashMap(java.util.HashMap) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) Test(org.junit.jupiter.api.Test)

Example 4 with LogExporter

use of io.opentelemetry.sdk.logs.export.LogExporter in project opentelemetry-java by open-telemetry.

the class LogEmitterProviderConfiguration method configureLogProcessors.

// Visible for testing
static List<LogProcessor> configureLogProcessors(Map<String, LogExporter> exportersByName, MeterProvider meterProvider) {
    Map<String, LogExporter> exportersByNameCopy = new HashMap<>(exportersByName);
    List<LogProcessor> logProcessors = new ArrayList<>();
    LogExporter exporter = exportersByNameCopy.remove("logging");
    if (exporter != null) {
        logProcessors.add(SimpleLogProcessor.create(exporter));
    }
    if (!exportersByNameCopy.isEmpty()) {
        LogExporter compositeLogExporter = LogExporter.composite(exportersByNameCopy.values());
        logProcessors.add(BatchLogProcessor.builder(compositeLogExporter).setMeterProvider(meterProvider).build());
    }
    return logProcessors;
}
Also used : HashMap(java.util.HashMap) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) ArrayList(java.util.ArrayList) LogProcessor(io.opentelemetry.sdk.logs.LogProcessor) SimpleLogProcessor(io.opentelemetry.sdk.logs.export.SimpleLogProcessor) BatchLogProcessor(io.opentelemetry.sdk.logs.export.BatchLogProcessor)

Example 5 with LogExporter

use of io.opentelemetry.sdk.logs.export.LogExporter in project opentelemetry-java by open-telemetry.

the class LogExporterConfiguration method configureLogExporters.

// Visible for test
static Map<String, LogExporter> configureLogExporters(ConfigProperties config, MeterProvider meterProvider, BiFunction<? super LogExporter, ConfigProperties, ? extends LogExporter> logExporterCustomizer) {
    Set<String> exporterNames = DefaultConfigProperties.getSet(config, "otel.logs.exporter");
    // Default to no exporter
    if (exporterNames.isEmpty()) {
        exporterNames = Collections.singleton(EXPORTER_NONE);
    }
    if (exporterNames.contains(EXPORTER_NONE)) {
        if (exporterNames.size() > 1) {
            throw new ConfigurationException("otel.logs.exporter contains " + EXPORTER_NONE + " along with other exporters");
        }
        return Collections.emptyMap();
    }
    Map<String, LogExporter> exportersByName = new HashMap<>();
    for (String name : exporterNames) {
        LogExporter logExporter = configureExporter(name, config, meterProvider);
        if (logExporter != null) {
            LogExporter customizedLogExporter = logExporterCustomizer.apply(logExporter, config);
            exportersByName.put(name, customizedLogExporter);
        }
    }
    return Collections.unmodifiableMap(exportersByName);
}
Also used : ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) HashMap(java.util.HashMap) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) OtlpGrpcLogExporter(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter) OtlpHttpLogExporter(io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogExporter) SystemOutLogExporter(io.opentelemetry.exporter.logging.SystemOutLogExporter)

Aggregations

LogExporter (io.opentelemetry.sdk.logs.export.LogExporter)15 HashMap (java.util.HashMap)9 Test (org.junit.jupiter.api.Test)9 OtlpGrpcLogExporter (io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter)7 OtlpHttpLogExporter (io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogExporter)4 SystemOutLogExporter (io.opentelemetry.exporter.logging.SystemOutLogExporter)3 OtlpGrpcLogExporterBuilder (io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporterBuilder)3 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)3 Config (io.opentelemetry.instrumentation.api.config.Config)2 SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)2 ConfigurationException (io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)2 SimpleLogProcessor (io.opentelemetry.sdk.logs.export.SimpleLogProcessor)2 MetricExporter (io.opentelemetry.sdk.metrics.export.MetricExporter)2 SpanExporter (io.opentelemetry.sdk.trace.export.SpanExporter)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 BatchingLogsProcessor (com.splunk.opentelemetry.logs.BatchingLogsProcessor)1 SpanContextualizer (com.splunk.opentelemetry.profiler.context.SpanContextualizer)1 EventPeriods (com.splunk.opentelemetry.profiler.events.EventPeriods)1 MeterProvider (io.opentelemetry.api.metrics.MeterProvider)1