Search in sources :

Example 36 with LogData

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

the class OpenTelemetryAppenderConfigTest method logStringMapMessageWithSpecialAttribute.

@Test
void logStringMapMessageWithSpecialAttribute() {
    StringMapMessage message = new StringMapMessage();
    message.put("key1", "val1");
    message.put("message", "val2");
    logger.info(message);
    List<LogData> logDataList = logExporter.getFinishedLogItems();
    assertThat(logDataList).hasSize(1);
    LogData logData = logDataList.get(0);
    assertThat(logData.getResource()).isEqualTo(resource);
    assertThat(logData.getInstrumentationLibraryInfo()).isEqualTo(instrumentationLibraryInfo);
    assertThat(logData.getBody().asString()).isEqualTo("val2");
    assertThat(logData.getAttributes().size()).isEqualTo(1);
    assertThat(logData.getAttributes().get(AttributeKey.stringKey("key1"))).isEqualTo("val1");
}
Also used : StringMapMessage(org.apache.logging.log4j.message.StringMapMessage) LogData(io.opentelemetry.sdk.logs.data.LogData) Test(org.junit.jupiter.api.Test)

Example 37 with LogData

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

the class AgentTestingExporterAccess method getExportedLogs.

@SuppressWarnings("unchecked")
public static List<LogData> getExportedLogs() {
    List<byte[]> exportRequests;
    try {
        exportRequests = (List<byte[]>) getLogExportRequests.invokeExact();
    } catch (Throwable t) {
        throw new AssertionError("Could not invoke getMetricExportRequests", t);
    }
    List<ResourceLogs> allResourceLogs = exportRequests.stream().map(serialized -> {
        try {
            return ExportLogsServiceRequest.parseFrom(serialized);
        } catch (InvalidProtocolBufferException e) {
            throw new AssertionError(e);
        }
    }).flatMap(request -> request.getResourceLogsList().stream()).collect(toList());
    List<LogData> logs = new ArrayList<>();
    for (ResourceLogs resourceLogs : allResourceLogs) {
        Resource resource = resourceLogs.getResource();
        for (InstrumentationLibraryLogs ilLogs : resourceLogs.getInstrumentationLibraryLogsList()) {
            InstrumentationLibrary instrumentationLibrary = ilLogs.getInstrumentationLibrary();
            for (LogRecord logRecord : ilLogs.getLogsList()) {
                logs.add(createLogData(logRecord, io.opentelemetry.sdk.resources.Resource.create(fromProto(resource.getAttributesList())), InstrumentationLibraryInfo.create(instrumentationLibrary.getName(), instrumentationLibrary.getVersion())));
            }
        }
    }
    return logs;
}
Also used : TraceFlags(io.opentelemetry.api.trace.TraceFlags) LongPointData(io.opentelemetry.sdk.metrics.data.LongPointData) KeyValue(io.opentelemetry.proto.common.v1.KeyValue) EventData(io.opentelemetry.sdk.trace.data.EventData) Sum(io.opentelemetry.proto.metrics.v1.Sum) StatusCode(io.opentelemetry.api.trace.StatusCode) ImmutableSummaryPointData(io.opentelemetry.sdk.metrics.internal.data.ImmutableSummaryPointData) Attributes(io.opentelemetry.api.common.Attributes) ResourceLogs(io.opentelemetry.proto.logs.v1.ResourceLogs) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Resource(io.opentelemetry.proto.resource.v1.Resource) LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder) AttributeKey.stringArrayKey(io.opentelemetry.api.common.AttributeKey.stringArrayKey) ExportLogsServiceRequest(io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ValueAtPercentile(io.opentelemetry.sdk.metrics.data.ValueAtPercentile) SpanContext(io.opentelemetry.api.trace.SpanContext) SummaryPointData(io.opentelemetry.sdk.metrics.data.SummaryPointData) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) AttributeKey.doubleArrayKey(io.opentelemetry.api.common.AttributeKey.doubleArrayKey) SpanKind(io.opentelemetry.api.trace.SpanKind) Collectors(java.util.stream.Collectors) ArrayValue(io.opentelemetry.proto.common.v1.ArrayValue) List(java.util.List) InstrumentationLibraryMetrics(io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) SpanData(io.opentelemetry.sdk.trace.data.SpanData) AttributeKey.longArrayKey(io.opentelemetry.api.common.AttributeKey.longArrayKey) AnyValue(io.opentelemetry.proto.common.v1.AnyValue) MetricData(io.opentelemetry.sdk.metrics.data.MetricData) Pattern(java.util.regex.Pattern) ImmutableValueAtPercentile(io.opentelemetry.sdk.metrics.internal.data.ImmutableValueAtPercentile) HistogramDataPoint(io.opentelemetry.proto.metrics.v1.HistogramDataPoint) MethodHandle(java.lang.invoke.MethodHandle) StatusData(io.opentelemetry.sdk.trace.data.StatusData) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) ImmutableSummaryData(io.opentelemetry.sdk.metrics.internal.data.ImmutableSummaryData) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) ArrayList(java.util.ArrayList) TraceState(io.opentelemetry.api.trace.TraceState) Metric(io.opentelemetry.proto.metrics.v1.Metric) DoublePointData(io.opentelemetry.sdk.metrics.data.DoublePointData) HistogramPointData(io.opentelemetry.sdk.metrics.data.HistogramPointData) TraceStateBuilder(io.opentelemetry.api.trace.TraceStateBuilder) LogData(io.opentelemetry.sdk.logs.data.LogData) ImmutableGaugeData(io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData) Severity(io.opentelemetry.sdk.logs.data.Severity) ImmutableSumData(io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData) AggregationTemporality(io.opentelemetry.sdk.metrics.data.AggregationTemporality) LogRecord(io.opentelemetry.proto.logs.v1.LogRecord) SeverityNumber(io.opentelemetry.proto.logs.v1.SeverityNumber) ExportMetricsServiceRequest(io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest) Span(io.opentelemetry.proto.trace.v1.Span) AttributesBuilder(io.opentelemetry.api.common.AttributesBuilder) NumberDataPoint(io.opentelemetry.proto.metrics.v1.NumberDataPoint) TimeUnit(java.util.concurrent.TimeUnit) ImmutableHistogramPointData(io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData) Collectors.toList(java.util.stream.Collectors.toList) MethodType(java.lang.invoke.MethodType) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) ResourceMetrics(io.opentelemetry.proto.metrics.v1.ResourceMetrics) InstrumentationLibraryLogs(io.opentelemetry.proto.logs.v1.InstrumentationLibraryLogs) AttributeKey.booleanArrayKey(io.opentelemetry.api.common.AttributeKey.booleanArrayKey) ImmutableHistogramData(io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData) LinkData(io.opentelemetry.sdk.trace.data.LinkData) SummaryDataPoint(io.opentelemetry.proto.metrics.v1.SummaryDataPoint) Status(io.opentelemetry.proto.trace.v1.Status) TestSpanData(io.opentelemetry.sdk.testing.trace.TestSpanData) LogData(io.opentelemetry.sdk.logs.data.LogData) ResourceLogs(io.opentelemetry.proto.logs.v1.ResourceLogs) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ArrayList(java.util.ArrayList) Resource(io.opentelemetry.proto.resource.v1.Resource) LogRecord(io.opentelemetry.proto.logs.v1.LogRecord) InstrumentationLibraryLogs(io.opentelemetry.proto.logs.v1.InstrumentationLibraryLogs) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary)

Example 38 with LogData

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

the class OtlpInMemoryLogExporter method export.

@Override
public CompletableResultCode export(Collection<LogData> logs) {
    for (LogData log : logs) {
        logger.info("Exporting log {}", log);
    }
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        LogsRequestMarshaler.create(logs).writeBinaryTo(bos);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    collectedRequests.add(bos.toByteArray());
    return CompletableResultCode.ofSuccess();
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) UncheckedIOException(java.io.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 39 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project splunk-otel-java by signalfx.

the class StackToSpanLinkageProcessorTest method testProcessor.

@Test
void testProcessor() {
    Instant time = Instant.now();
    StackToSpanLinkage linkedSpan = new StackToSpanLinkage(time, "some stack", "event name", SpanLinkage.NONE);
    LogDataCreator logCreator = mock(LogDataCreator.class);
    BatchingLogsProcessor exportProcessor = mock(BatchingLogsProcessor.class);
    LogDataBuilder builder = LogDataBuilder.create(Resource.getDefault(), InstrumentationLibraryInfo.create("test", "1.2.3"));
    LogData log = builder.setBody("the.body").build();
    when(logCreator.apply(linkedSpan)).thenReturn(log);
    StackToSpanLinkageProcessor processor = new StackToSpanLinkageProcessor(logCreator, exportProcessor);
    processor.accept(linkedSpan);
    verify(exportProcessor).emit(log);
}
Also used : StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) BatchingLogsProcessor(com.splunk.opentelemetry.logs.BatchingLogsProcessor) LogData(io.opentelemetry.sdk.logs.data.LogData) Instant(java.time.Instant) LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder) Test(org.junit.jupiter.api.Test)

Example 40 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project splunk-otel-java by signalfx.

the class StackToSpanLinkageProcessor method accept.

@Override
public void accept(StackToSpanLinkage stackToSpanLinkage) {
    LogData log = logDataCreator.apply(stackToSpanLinkage);
    processor.emit(log);
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData)

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