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);
}
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();
}
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);
}
}
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());
}
Aggregations