Search in sources :

Example 1 with InstrumentationLibraryLogs

use of io.opentelemetry.proto.logs.v1.InstrumentationLibraryLogs in project opentelemetry-java by open-telemetry.

the class LogsRequestMarshalerTest method toProtoResourceLogs.

@Test
// test deprecated setName method
@SuppressWarnings("deprecation")
void toProtoResourceLogs() {
    ResourceLogsMarshaler[] resourceLogsMarshalers = ResourceLogsMarshaler.create(Collections.singleton(LogDataBuilder.create(Resource.builder().put("one", 1).setSchemaUrl("http://url").build(), InstrumentationLibraryInfo.create("testLib", "1.0", "http://url")).setName(NAME).setBody(BODY).setSeverity(Severity.INFO).setSeverityText("INFO").setSpanContext(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())).setAttributes(Attributes.of(AttributeKey.booleanKey("key"), true)).setEpoch(12345, TimeUnit.NANOSECONDS).build()));
    assertThat(resourceLogsMarshalers).hasSize(1);
    ResourceLogs onlyResourceLogs = parse(ResourceLogs.getDefaultInstance(), resourceLogsMarshalers[0]);
    assertThat(onlyResourceLogs.getSchemaUrl()).isEqualTo("http://url");
    assertThat(onlyResourceLogs.getInstrumentationLibraryLogsCount()).isEqualTo(1);
    InstrumentationLibraryLogs instrumentationLibraryLogs = onlyResourceLogs.getInstrumentationLibraryLogs(0);
    assertThat(instrumentationLibraryLogs.getSchemaUrl()).isEqualTo("http://url");
    assertThat(instrumentationLibraryLogs.getInstrumentationLibrary()).isEqualTo(InstrumentationLibrary.newBuilder().setName("testLib").setVersion("1.0").build());
}
Also used : ResourceLogs(io.opentelemetry.proto.logs.v1.ResourceLogs) InstrumentationLibraryLogs(io.opentelemetry.proto.logs.v1.InstrumentationLibraryLogs) Test(org.junit.jupiter.api.Test)

Example 2 with InstrumentationLibraryLogs

use of io.opentelemetry.proto.logs.v1.InstrumentationLibraryLogs in project opentelemetry-java by open-telemetry.

the class OtlpExporterIntegrationTest method testLogExporter.

// test deprecated setName method
@SuppressWarnings("deprecation")
private static void testLogExporter(LogExporter logExporter) {
    LogData logData = LogDataBuilder.create(RESOURCE, InstrumentationLibraryInfo.create(OtlpExporterIntegrationTest.class.getName(), null)).setName("log-name").setBody("log body").setAttributes(Attributes.builder().put("key", "value").build()).setSeverity(Severity.DEBUG).setSeverityText("DEBUG").setEpoch(Instant.now()).setSpanContext(SpanContext.create(IdGenerator.random().generateTraceId(), IdGenerator.random().generateSpanId(), TraceFlags.getDefault(), TraceState.getDefault())).build();
    logExporter.export(Collections.singletonList(logData));
    await().atMost(Duration.ofSeconds(30)).untilAsserted(() -> assertThat(grpcServer.logRequests).hasSize(1));
    ExportLogsServiceRequest request = grpcServer.logRequests.get(0);
    assertThat(request.getResourceLogsCount()).isEqualTo(1);
    ResourceLogs resourceLogs = request.getResourceLogs(0);
    assertThat(resourceLogs.getResource().getAttributesList()).contains(KeyValue.newBuilder().setKey(ResourceAttributes.SERVICE_NAME.getKey()).setValue(AnyValue.newBuilder().setStringValue("integration test").build()).build());
    assertThat(resourceLogs.getInstrumentationLibraryLogsCount()).isEqualTo(1);
    InstrumentationLibraryLogs ilLogs = resourceLogs.getInstrumentationLibraryLogs(0);
    assertThat(ilLogs.getInstrumentationLibrary().getName()).isEqualTo(OtlpExporterIntegrationTest.class.getName());
    assertThat(ilLogs.getLogRecordsCount()).isEqualTo(1);
    io.opentelemetry.proto.logs.v1.LogRecord protoLog = ilLogs.getLogRecords(0);
    assertThat(protoLog.getName()).isEqualTo("log-name");
    assertThat(protoLog.getBody().getStringValue()).isEqualTo("log body");
    assertThat(protoLog.getAttributesList()).isEqualTo(Collections.singletonList(KeyValue.newBuilder().setKey("key").setValue(AnyValue.newBuilder().setStringValue("value").build()).build()));
    assertThat(protoLog.getSeverityNumber().getNumber()).isEqualTo(logData.getSeverity().getSeverityNumber());
    assertThat(protoLog.getSeverityText()).isEqualTo("DEBUG");
    assertThat(TraceId.fromBytes(protoLog.getTraceId().toByteArray())).isEqualTo(logData.getSpanContext().getTraceId());
    assertThat(SpanId.fromBytes(protoLog.getSpanId().toByteArray())).isEqualTo(logData.getSpanContext().getSpanId());
    assertThat(TraceFlags.fromByte((byte) protoLog.getFlags())).isEqualTo(logData.getSpanContext().getTraceFlags());
    assertThat(protoLog.getTimeUnixNano()).isEqualTo(logData.getEpochNanos());
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) ResourceLogs(io.opentelemetry.proto.logs.v1.ResourceLogs) ExportLogsServiceRequest(io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest) InstrumentationLibraryLogs(io.opentelemetry.proto.logs.v1.InstrumentationLibraryLogs)

Example 3 with InstrumentationLibraryLogs

use of io.opentelemetry.proto.logs.v1.InstrumentationLibraryLogs 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)

Aggregations

InstrumentationLibraryLogs (io.opentelemetry.proto.logs.v1.InstrumentationLibraryLogs)3 ResourceLogs (io.opentelemetry.proto.logs.v1.ResourceLogs)3 ExportLogsServiceRequest (io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest)2 LogData (io.opentelemetry.sdk.logs.data.LogData)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 AttributeKey.booleanArrayKey (io.opentelemetry.api.common.AttributeKey.booleanArrayKey)1 AttributeKey.doubleArrayKey (io.opentelemetry.api.common.AttributeKey.doubleArrayKey)1 AttributeKey.longArrayKey (io.opentelemetry.api.common.AttributeKey.longArrayKey)1 AttributeKey.stringArrayKey (io.opentelemetry.api.common.AttributeKey.stringArrayKey)1 Attributes (io.opentelemetry.api.common.Attributes)1 AttributesBuilder (io.opentelemetry.api.common.AttributesBuilder)1 SpanContext (io.opentelemetry.api.trace.SpanContext)1 SpanKind (io.opentelemetry.api.trace.SpanKind)1 StatusCode (io.opentelemetry.api.trace.StatusCode)1 TraceFlags (io.opentelemetry.api.trace.TraceFlags)1 TraceState (io.opentelemetry.api.trace.TraceState)1 TraceStateBuilder (io.opentelemetry.api.trace.TraceStateBuilder)1 ExportMetricsServiceRequest (io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest)1 ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)1 AnyValue (io.opentelemetry.proto.common.v1.AnyValue)1