Documentation
¶
Overview ¶
Package srcconv holds the decoders that turn third-party wire formats (Datadog Agent, Splunk HEC, MessagePack) into OTLP messages. The gateway receivers and the relay sources share it.
Index ¶
- Constants
- Variables
- func AddTracerPayload(g *spanGroups, top map[string]any, n *int, maxSpans int) error
- func AppendKV(dst []*commonpb.KeyValue, k string, v *commonpb.AnyValue) []*commonpb.KeyValue
- func DDEventLog(e map[string]any, now uint64) *logspb.LogRecord
- func DDLog(e map[string]any, now uint64) *logspb.LogRecord
- func DDLogEntries(body []byte) ([]map[string]any, error)
- func DDLogsRequest(entries []map[string]any, now uint64) *colllogs.ExportLogsServiceRequest
- func DDSpan(m map[string]any) (*tracepb.Span, string)
- func DDSpanV05(dict []string, a []any) (map[string]any, bool)
- func DDStatsMetrics(body []byte, isMsgpack bool, maxPoints int) ([]*metricspb.Metric, error)
- func DDTagList(v any) []string
- func DDTraces(v any, maxSpans int) (*colltrace.ExportTraceServiceRequest, error)
- func DDTracesV02(body []byte, maxSpans int) (*colltrace.ExportTraceServiceRequest, error)
- func DDTracesV05(v any, maxSpans int) (*colltrace.ExportTraceServiceRequest, error)
- func DDTracesV07(top map[string]any, maxSpans int) (*colltrace.ExportTraceServiceRequest, error)
- func DecodeObjects(body []byte, max int) ([]map[string]any, error)
- func DropWt(v any) any
- func Flatten(prefix string, v any, out map[string]any)
- func HECGauges(e *HECEvt, ns, now uint64) []*metricspb.Metric
- func HECLog(e *HECEvt, ns, now uint64) *logspb.LogRecord
- func HECLogCount(req *colllogs.ExportLogsServiceRequest) (n int)
- func HECRawRequest(body string, e HECEvt, now uint64, max int) (*colllogs.ExportLogsServiceRequest, error)
- func HECRequests(evs []HECEvt, now uint64) (*colllogs.ExportLogsServiceRequest, *collmetrics.ExportMetricsServiceRequest)
- func JSONLogRecord(e map[string]any, bodyKeys []string, ns, now uint64) *logspb.LogRecord
- func JSONVal(v any) *commonpb.AnyValue
- func LogRecord(ns, now uint64, body string, attrs []*commonpb.KeyValue) *logspb.LogRecord
- func MPStr(v any) string
- func MPU64(v any) uint64
- func MsgpackDecode(b []byte) (any, error)
- func MsgpackNext(b []byte, ext bool) (any, []byte, error)
- func NewScope(req *colllogs.ExportLogsServiceRequest, attrs []*commonpb.KeyValue) *logspb.ScopeLogs
- func ParseSketches(b []byte, maxSketches int) ([]*metricspb.Metric, error)
- func ParseTime(v any, unit time.Duration) uint64
- func SeriesRequest(series []Series) *collmetrics.ExportMetricsServiceRequest
- func SetSeverity(rec *logspb.LogRecord, level string)
- func SortedKeys[V any](m map[string]V) []string
- func StrVal(s string) *commonpb.AnyValue
- func TagAttrs(attrs []*commonpb.KeyValue, tags []string) []*commonpb.KeyValue
- type HECEvt
- type Point
- type Series
Constants ¶
const (
// MPMaxValues caps decoded values (and protobuf fields) per payload.
MPMaxValues = 1 << 20
)
Variables ¶
var ( ErrDatadog = errors.New("malformed datadog payload") ErrTooLarge = errors.New("payload too large") )
ErrDatadog is a malformed Datadog payload; ErrTooLarge a payload past the field budget.
var ErrHECFormat = errors.New("invalid data format")
ErrHECFormat is a body that is not a stream of HEC events.
var ( // ErrMsgpackShort means the input ended inside a value: a stream reader should wait for more bytes. ErrMsgpackShort = errors.New("truncated msgpack") )
Functions ¶
func AddTracerPayload ¶
AddTracerPayload adds one TracerPayload's spans to g; n counts spans across the request.
func DDEventLog ¶
DDEventLog maps one event to a log record (severity from alert_type), tagged `datadog.event = true` with the event fields under `datadog.event.*`.
func DDLogEntries ¶
DDLogEntries decodes a Datadog logs body (a JSON array, numbers kept exact).
func DDLogsRequest ¶
func DDLogsRequest(entries []map[string]any, now uint64) *colllogs.ExportLogsServiceRequest
DDLogsRequest converts Datadog v2 log entries (one resource per service) to OTLP.
func DDSpan ¶
DDSpan converts one span map. trace_id is 64-bit; the high half comes from meta `_dd.p.tid`.
func DDSpanV05 ¶
DDSpanV05 expands a v0.5 span array (indices into the payload's string table) into the v0.4 map.
func DDStatsMetrics ¶
DDStatsMetrics maps the trace-agent's APM stats (msgpack when isMsgpack, else protobuf) to delta counters: dd.trace.hits, .errors, .top_level_hits and .duration_ns per service/operation/resource. More than maxPoints points is ErrTooLarge.
func DDTraces ¶
func DDTraces(v any, maxSpans int) (*colltrace.ExportTraceServiceRequest, error)
DDTraces converts a decoded v0.4 payload (an array of traces, each an array of span maps) to OTLP, one resource per service. More than maxSpans spans is ErrTooLarge.
func DDTracesV02 ¶
func DDTracesV02(body []byte, maxSpans int) (*colltrace.ExportTraceServiceRequest, error)
DDTracesV02 reads the trace-agent's AgentPayload (protobuf; the caller undoes gzip or zstd). More than maxSpans spans is ErrTooLarge.
func DDTracesV05 ¶
func DDTracesV05(v any, maxSpans int) (*colltrace.ExportTraceServiceRequest, error)
DDTracesV05 converts a decoded v0.5 payload [string table, traces] by expanding every span to the v0.4 shape and reusing DDTraces.
func DDTracesV07 ¶
DDTracesV07 reads the TracerPayload map {chunks:[{spans:[<v0.4 span map>]}], env, hostname, appVersion}.
func DecodeObjects ¶
DecodeObjects reads JSON objects from body: a single object, an array of objects, or NDJSON (numbers kept exact). Malformed input is ErrDatadog, more than max objects ErrTooLarge.
func DropWt ¶
DropWt removes reserved wt.* keys from a decoded JSON value so they cannot reach storage in the body either.
func HECGauges ¶
HECGauges maps a metric event: fields {metric_name, _value} or {"metric_name:<name>": value, ...}; every other field is a dimension.
func HECLogCount ¶
func HECLogCount(req *colllogs.ExportLogsServiceRequest) (n int)
HECLogCount is the number of log records in a HECRequests logs request.
func HECRawRequest ¶
func HECRawRequest(body string, e HECEvt, now uint64, max int) (*colllogs.ExportLogsServiceRequest, error)
HECRawRequest turns a raw body (one event per non-empty line) into logs; max lines at most.
func HECRequests ¶
func HECRequests(evs []HECEvt, now uint64) (*colllogs.ExportLogsServiceRequest, *collmetrics.ExportMetricsServiceRequest)
HECRequests converts events: log events to one logs request, `event:"metric"` events to gauges in one metrics request (nil when there are none). now is unix ns.
func JSONLogRecord ¶
JSONLogRecord turns a JSON object into a record: the first string among bodyKeys is the body (and is not repeated as an attribute); every other field becomes a flattened attribute. Without a string body the object itself, minus wt.* keys, is the body.
func JSONVal ¶
JSONVal converts a decoded JSON scalar (UseNumber) to an AnyValue; arrays become JSON text.
func MsgpackDecode ¶
MsgpackDecode decodes one value. Maps become map[string]any (non-string keys are rejected), arrays []any, strings string, bin []byte, non-negative ints uint64, negative ints int64, floats float64.
func MsgpackNext ¶
MsgpackNext decodes the first value of a stream and returns the bytes after it. With ext, the Fluent forward EventTime extension (type 0) decodes to time.Time and other extensions to []byte; without it extensions are rejected (the Datadog behaviour).
func NewScope ¶
NewScope appends a resource (wt.* attributes dropped) with one scope and returns that scope.
func ParseSketches ¶
ParseSketches decodes a SketchPayload into exponential histogram metrics; more than max sketches is ErrTooLarge.
func ParseTime ¶
ParseTime reads a number (scaled by unit) or an RFC 3339 string into ns; 0 when unparseable.
func SeriesRequest ¶
func SeriesRequest(series []Series) *collmetrics.ExportMetricsServiceRequest
SeriesRequest converts series (empty ones skipped, semantic twins added) to one OTLP request.
func SetSeverity ¶
SetSeverity fills the severity text and number from a level name.
func SortedKeys ¶
SortedKeys returns the keys of m in order.
Types ¶
type HECEvt ¶
type HECEvt struct {
Time any `json:"time"`
Host string `json:"host"`
Source string `json:"source"`
Sourcetype string `json:"sourcetype"`
Index string `json:"index"`
Service string `json:"service"`
Event any `json:"event"`
Fields map[string]any `json:"fields"`
}
HECEvt is one Splunk HTTP Event Collector event.
func HECDecode ¶
HECDecode reads a stream of concatenated JSON events (numbers exact). More than max events is ErrTooLarge.
func (*HECEvt) ServiceName ¶
ServiceName is the event's service: the top-level `service`, else fields.service, else service in a JSON event object.
type Point ¶
type Point struct{ TS, Val float64 }
Point is one series sample (TS in seconds).
func (*Point) UnmarshalJSON ¶
UnmarshalJSON reads v1 [ts, value] pairs and v2 {"timestamp":..,"value":..} objects.
type Series ¶
type Series struct {
Metric string `json:"metric"`
Type json.RawMessage `json:"type"` // v1 "gauge"|"count"|"rate"; v2 0..3
Points []Point `json:"points"`
Tags []string `json:"tags"`
Host string `json:"host"`
Interval float64 `json:"interval"`
Resources []struct{ Type, Name string } `json:"resources"`
}
Series is a Datadog v1/v2 metric series.
func SeriesFromJSON ¶
SeriesFromJSON decodes a v1 or v2 JSON series body.
func SeriesFromProto ¶
SeriesFromProto decodes the Agent 7 v2 MetricPayload (DataDog/agent-payload metrics proto): series = 1 { resources 1 {type 1, name 2}, metric 2, tags 3, points 4 {value 1 double, timestamp 2}, type 5, interval 8 }. Unknown fields are skipped; more than MPMaxValues fields is ErrTooLarge.
func (*Series) Kind ¶
Kind maps both encodings to gauge, count or rate (v2: 1 count, 2 rate, 3 gauge; 0 = gauge).
func (*Series) SemanticTwin ¶
SemanticTwin returns the OTel-named copy of a gauge series, or nil when there is none.