Search in sources :

Example 1 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java by open-telemetry.

the class OtlpHttpLogExporterTest method exportAndAssertResult.

private static ExportLogsServiceRequest exportAndAssertResult(OtlpHttpLogExporter otlpHttpLogExporter, boolean expectedResult) {
    List<LogData> logs = Collections.singletonList(generateFakeLog());
    CompletableResultCode resultCode = otlpHttpLogExporter.export(logs);
    resultCode.join(10, TimeUnit.SECONDS);
    assertThat(resultCode.isSuccess()).isEqualTo(expectedResult);
    List<ResourceLogs> resourceLogs = Arrays.stream(ResourceLogsMarshaler.create(logs)).map(marshaler -> {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            marshaler.writeBinaryTo(bos);
            return ResourceLogs.parseFrom(bos.toByteArray());
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }).collect(Collectors.toList());
    return ExportLogsServiceRequest.newBuilder().addAllResourceLogs(resourceLogs).build();
}
Also used : RecordedRequest(com.linecorp.armeria.testing.junit5.server.mock.RecordedRequest) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ExportLogsServiceResponse(io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Attributes(io.opentelemetry.api.common.Attributes) InetAddress(java.net.InetAddress) ResourceLogs(io.opentelemetry.proto.logs.v1.ResourceLogs) Duration(java.time.Duration) Level(org.slf4j.event.Level) ResourceLogsMarshaler(io.opentelemetry.exporter.internal.otlp.logs.ResourceLogsMarshaler) LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder) GzipSource(okio.GzipSource) ExportLogsServiceRequest(io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) HttpResponse(com.linecorp.armeria.common.HttpResponse) MockWebServerExtension(com.linecorp.armeria.testing.junit5.server.mock.MockWebServerExtension) Status(com.google.rpc.Status) HttpMethod(com.linecorp.armeria.common.HttpMethod) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) OkHttpExporter(io.opentelemetry.exporter.internal.okhttp.OkHttpExporter) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test) List(java.util.List) LogCapturer(io.github.netmikey.logunit.api.LogCapturer) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) HeldCertificate(okhttp3.tls.HeldCertificate) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) ServerBuilder(com.linecorp.armeria.server.ServerBuilder) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Resource(io.opentelemetry.sdk.resources.Resource) MediaType(com.linecorp.armeria.common.MediaType) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) RetryPolicy(io.opentelemetry.exporter.internal.retry.RetryPolicy) HttpStatus(com.linecorp.armeria.common.HttpStatus) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) LogData(io.opentelemetry.sdk.logs.data.LogData) LoggingEvent(org.slf4j.event.LoggingEvent) Severity(io.opentelemetry.sdk.logs.data.Severity) Buffer(okio.Buffer) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TimeUnit(java.util.concurrent.TimeUnit) RetryUtil(io.opentelemetry.exporter.internal.retry.RetryUtil) Message(com.google.protobuf.Message) Collections(java.util.Collections) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) LogData(io.opentelemetry.sdk.logs.data.LogData) ResourceLogs(io.opentelemetry.proto.logs.v1.ResourceLogs) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) UncheckedIOException(java.io.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 2 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java by open-telemetry.

the class SystemOutLogExporter method export.

@Override
public CompletableResultCode export(Collection<LogData> logs) {
    StringBuilder stringBuilder = new StringBuilder(60);
    for (LogData log : logs) {
        stringBuilder.setLength(0);
        formatLog(stringBuilder, log);
        System.out.println(stringBuilder);
    }
    return CompletableResultCode.ofSuccess();
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData)

Example 3 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java by open-telemetry.

the class SdkLogEmitterTest method logBuilder_maxAttributeLength.

@Test
void logBuilder_maxAttributeLength() {
    int maxLength = 25;
    AtomicReference<LogData> seenLog = new AtomicReference<>();
    SdkLogEmitterProvider logEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(seenLog::set).setLogLimits(() -> LogLimits.builder().setMaxAttributeValueLength(maxLength).build()).build();
    LogBuilder logBuilder = logEmitterProvider.get("test").logBuilder();
    String strVal = StringUtils.padLeft("", maxLength);
    String tooLongStrVal = strVal + strVal;
    logBuilder.setAttributes(Attributes.builder().put("string", tooLongStrVal).put("boolean", true).put("long", 1L).put("double", 1.0).put(stringArrayKey("stringArray"), Arrays.asList(strVal, tooLongStrVal)).put(booleanArrayKey("booleanArray"), Arrays.asList(true, false)).put(longArrayKey("longArray"), Arrays.asList(1L, 2L)).put(doubleArrayKey("doubleArray"), Arrays.asList(1.0, 2.0)).build()).emit();
    Attributes attributes = seenLog.get().getAttributes();
    assertThat(attributes).containsEntry("string", strVal).containsEntry("boolean", true).containsEntry("long", 1L).containsEntry("double", 1.0).containsEntry("stringArray", strVal, strVal).containsEntry("booleanArray", true, false).containsEntry("longArray", 1L, 2L).containsEntry("doubleArray", 1.0, 2.0);
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) Attributes(io.opentelemetry.api.common.Attributes) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 4 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java by open-telemetry.

the class InMemoryLogExporterTest method export_ReturnCode.

@Test
void export_ReturnCode() {
    LogData logData = createLogData(DEBUG, "message 1");
    assertThat(exporter.export(Collections.singletonList(logData)).isSuccess()).isTrue();
    exporter.shutdown();
    // After shutdown no more export.
    assertThat(exporter.export(Collections.singletonList(logData)).isSuccess()).isFalse();
    exporter.reset();
    // Reset does not do anything if already shutdown.
    assertThat(exporter.export(Collections.singletonList(logData)).isSuccess()).isFalse();
}
Also used : TestUtil.createLogData(io.opentelemetry.sdk.logs.util.TestUtil.createLogData) LogData(io.opentelemetry.sdk.logs.data.LogData) Test(org.junit.jupiter.api.Test)

Example 5 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java by open-telemetry.

the class BatchLogProcessorTest method emitLogsToMultipleExporters.

@Test
void emitLogsToMultipleExporters() {
    WaitingLogExporter waitingLogExporter1 = new WaitingLogExporter(2, CompletableResultCode.ofSuccess());
    WaitingLogExporter waitingLogExporter2 = new WaitingLogExporter(2, CompletableResultCode.ofSuccess());
    SdkLogEmitterProvider sdkLogEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(BatchLogProcessor.builder(LogExporter.composite(Arrays.asList(waitingLogExporter1, waitingLogExporter2))).setScheduleDelay(MAX_SCHEDULE_DELAY_MILLIS, TimeUnit.MILLISECONDS).build()).build();
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_2);
    List<LogData> exported1 = waitingLogExporter1.waitForExport();
    List<LogData> exported2 = waitingLogExporter2.waitForExport();
    assertThat(exported1).hasSize(2).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_1), logData -> assertThat(logData).hasBody(LOG_MESSAGE_2));
    assertThat(exported2).hasSize(2).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_1), logData -> assertThat(logData).hasBody(LOG_MESSAGE_2));
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) Test(org.junit.jupiter.api.Test)

Aggregations

LogData (io.opentelemetry.sdk.logs.data.LogData)40 Test (org.junit.jupiter.api.Test)34 Instant (java.time.Instant)8 SdkLogEmitterProvider (io.opentelemetry.sdk.logs.SdkLogEmitterProvider)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Attributes (io.opentelemetry.api.common.Attributes)5 SpanContext (io.opentelemetry.api.trace.SpanContext)4 SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)4 Clock (io.opentelemetry.sdk.common.Clock)4 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)4 Resource (io.opentelemetry.sdk.resources.Resource)4 TimeUnit (java.util.concurrent.TimeUnit)4 SpanLinkage (com.splunk.opentelemetry.profiler.context.SpanLinkage)3 EventPeriods (com.splunk.opentelemetry.profiler.events.EventPeriods)3 TraceFlags (io.opentelemetry.api.trace.TraceFlags)3 TraceState (io.opentelemetry.api.trace.TraceState)3 LogDataBuilder (io.opentelemetry.sdk.logs.data.LogDataBuilder)3 Mockito.when (org.mockito.Mockito.when)3 CONFIG_KEY_MEMORY_SAMPLER_INTERVAL (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_MEMORY_SAMPLER_INTERVAL)2 CONFIG_KEY_TLAB_ENABLED (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_TLAB_ENABLED)2