Search in sources :

Example 1 with KeyValueMarshaler

use of io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler in project opentelemetry-java by open-telemetry.

the class NumberDataPointMarshaler method create.

static NumberDataPointMarshaler create(PointData point) {
    ExemplarMarshaler[] exemplarMarshalers = ExemplarMarshaler.createRepeated(point.getExemplars());
    KeyValueMarshaler[] attributeMarshalers = KeyValueMarshaler.createRepeated(point.getAttributes());
    ProtoFieldInfo valueField;
    if (point instanceof LongPointData) {
        valueField = NumberDataPoint.AS_INT;
    } else {
        assert point instanceof DoublePointData;
        valueField = NumberDataPoint.AS_DOUBLE;
    }
    return new NumberDataPointMarshaler(point.getStartEpochNanos(), point.getEpochNanos(), point, valueField, exemplarMarshalers, attributeMarshalers);
}
Also used : LongPointData(io.opentelemetry.sdk.metrics.data.LongPointData) KeyValueMarshaler(io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler) ProtoFieldInfo(io.opentelemetry.exporter.internal.marshal.ProtoFieldInfo) DoublePointData(io.opentelemetry.sdk.metrics.data.DoublePointData)

Example 2 with KeyValueMarshaler

use of io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler in project opentelemetry-java by open-telemetry.

the class LogMarshaler method create.

// name field to be removed
@SuppressWarnings("deprecation")
static LogMarshaler create(io.opentelemetry.sdk.logs.data.LogData logData) {
    KeyValueMarshaler[] attributeMarshalers = KeyValueMarshaler.createRepeated(logData.getAttributes());
    // For now, map all the bodies to String AnyValue.
    StringAnyValueMarshaler anyValueMarshaler = new StringAnyValueMarshaler(MarshalerUtil.toBytes(logData.getBody().asString()));
    SpanContext spanContext = logData.getSpanContext();
    return new LogMarshaler(logData.getEpochNanos(), toProtoSeverityNumber(logData.getSeverity()), MarshalerUtil.toBytes(logData.getSeverityText()), MarshalerUtil.toBytes(logData.getName()), anyValueMarshaler, attributeMarshalers, // TODO (trask) implement droppedAttributesCount in LogRecord
    0, spanContext.getTraceFlags(), spanContext.getTraceId().equals(INVALID_TRACE_ID) ? null : spanContext.getTraceId(), spanContext.getSpanId().equals(INVALID_SPAN_ID) ? null : spanContext.getSpanId());
}
Also used : SpanContext(io.opentelemetry.api.trace.SpanContext) StringAnyValueMarshaler(io.opentelemetry.exporter.internal.otlp.StringAnyValueMarshaler) KeyValueMarshaler(io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler)

Example 3 with KeyValueMarshaler

use of io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler in project opentelemetry-java by open-telemetry.

the class SpanMarshaler method create.

// Because SpanMarshaler is always part of a repeated field, it cannot return "null".
static SpanMarshaler create(SpanData spanData) {
    KeyValueMarshaler[] attributeMarshalers = KeyValueMarshaler.createRepeated(spanData.getAttributes());
    SpanEventMarshaler[] spanEventMarshalers = SpanEventMarshaler.createRepeated(spanData.getEvents());
    SpanLinkMarshaler[] spanLinkMarshalers = SpanLinkMarshaler.createRepeated(spanData.getLinks());
    String parentSpanId = spanData.getParentSpanContext().isValid() ? spanData.getParentSpanContext().getSpanId() : null;
    TraceState traceState = spanData.getSpanContext().getTraceState();
    byte[] traceStateUtf8 = traceState.isEmpty() ? EMPTY_BYTES : encodeTraceState(traceState).getBytes(StandardCharsets.UTF_8);
    return new SpanMarshaler(spanData.getSpanContext().getTraceId(), spanData.getSpanContext().getSpanId(), traceStateUtf8, parentSpanId, MarshalerUtil.toBytes(spanData.getName()), toProtoSpanKind(spanData.getKind()), spanData.getStartEpochNanos(), spanData.getEndEpochNanos(), attributeMarshalers, spanData.getTotalAttributeCount() - spanData.getAttributes().size(), spanEventMarshalers, spanData.getTotalRecordedEvents() - spanData.getEvents().size(), spanLinkMarshalers, spanData.getTotalRecordedLinks() - spanData.getLinks().size(), SpanStatusMarshaler.create(spanData.getStatus()));
}
Also used : W3CTraceContextEncoding.encodeTraceState(io.opentelemetry.api.trace.propagation.internal.W3CTraceContextEncoding.encodeTraceState) TraceState(io.opentelemetry.api.trace.TraceState) KeyValueMarshaler(io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler)

Example 4 with KeyValueMarshaler

use of io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler in project opentelemetry-java by open-telemetry.

the class ExemplarMarshaler method create.

private static ExemplarMarshaler create(ExemplarData exemplar) {
    KeyValueMarshaler[] attributeMarshalers = KeyValueMarshaler.createRepeated(exemplar.getFilteredAttributes());
    ProtoFieldInfo valueField;
    if (exemplar instanceof LongExemplarData) {
        valueField = io.opentelemetry.proto.metrics.v1.internal.Exemplar.AS_INT;
    } else {
        assert exemplar instanceof DoubleExemplarData;
        valueField = io.opentelemetry.proto.metrics.v1.internal.Exemplar.AS_DOUBLE;
    }
    return new ExemplarMarshaler(exemplar.getEpochNanos(), exemplar, valueField, exemplar.getSpanContext(), attributeMarshalers);
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) LongExemplarData(io.opentelemetry.sdk.metrics.data.LongExemplarData) KeyValueMarshaler(io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler) ProtoFieldInfo(io.opentelemetry.exporter.internal.marshal.ProtoFieldInfo)

Aggregations

KeyValueMarshaler (io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler)4 ProtoFieldInfo (io.opentelemetry.exporter.internal.marshal.ProtoFieldInfo)2 SpanContext (io.opentelemetry.api.trace.SpanContext)1 TraceState (io.opentelemetry.api.trace.TraceState)1 W3CTraceContextEncoding.encodeTraceState (io.opentelemetry.api.trace.propagation.internal.W3CTraceContextEncoding.encodeTraceState)1 StringAnyValueMarshaler (io.opentelemetry.exporter.internal.otlp.StringAnyValueMarshaler)1 DoubleExemplarData (io.opentelemetry.sdk.metrics.data.DoubleExemplarData)1 DoublePointData (io.opentelemetry.sdk.metrics.data.DoublePointData)1 LongExemplarData (io.opentelemetry.sdk.metrics.data.LongExemplarData)1 LongPointData (io.opentelemetry.sdk.metrics.data.LongPointData)1