Documentation
¶
Overview ¶
Package otlp provides shared helpers for decoding OTLP payloads and converting common OTLP values into cliutils point primitives.
Index ¶
- Constants
- Variables
- func AnyValueToInterface(value *common.AnyValue) (any, bool)
- func AnyValueToString(value *common.AnyValue) (string, bool)
- func AttributesToStringMap(attrs []*common.KeyValue, opts StringMapOptions) map[string]string
- func AttributesToTagMap(attrs []*common.KeyValue, opts StringMapOptions) map[string]string
- func Base64RawID(id []byte) string
- func ChunkStringByRuneLength(s string, size int) []string
- func DBHostFromAttributes(resourceAttrs, spanAttrs map[string]string) string
- func DecimalIDFromLast8Bytes(id []byte) (string, bool)
- func DefaultHostName(attrs []*common.KeyValue) string
- func DefaultLogServiceAndSource(attrs []*common.KeyValue) (service string, source string)
- func FindAttribute(attrs []*common.KeyValue, key string) (*common.KeyValue, int, bool)
- func HexID(id []byte) string
- func IsZeroID(id []byte) bool
- func LogStatusFromSeverityNumber(severityNumber int32, fallback string) string
- func MergeStringMapsAsFields(maps ...map[string]string) point.KVs
- func MergeStringMapsAsTags(maps ...map[string]string) point.KVs
- func MetricMeasurementFromAttribute(pointAttrs map[string]string, fallback string) string
- func MetricNameFromAttribute(pointAttrs map[string]string, fallback string) string
- func NormalizeContentType(contentType string) string
- func NumberDataPointToPoint(measurement, field string, kvs point.KVs, pt *metrics.NumberDataPoint, ...) *point.Point
- func NumberDataPointValue(pt *metrics.NumberDataPoint) (any, bool)
- func ParseLogRequest(resourceLogs []*logs.ResourceLogs, opts LogsParserOptions) []*point.Point
- func ParseResourceMetricsV2(resmcs []*metrics.ResourceMetrics, opts MetricsParserOptions) []*point.Point
- func PublicAttributeAlias(key string) (string, bool)
- func SelectPublicTraceAttributes(attrs []*common.KeyValue) (point.KVs, []*common.KeyValue)
- func ShouldDropMetricAttribute(key string) bool
- func SpanKindName(kind int32) string
- func SummaryDataPointToPoint(measurement, field string, kvs point.KVs, summary *metrics.SummaryDataPoint, ...) *point.Point
- func SystemNameForService(attrs map[string]string) string
- func TraceSourceTypeFromTags(tags point.KVs) string
- func TraceStatusFromCode(code int32) string
- func Unmarshal(body []byte, contentType string, msg proto.Message) error
- type LogsParserOptions
- type MetricsParserOptions
- type StringMapOptions
- type TraceBatch
- type TracesParserOptions
Constants ¶
const ( ContentTypeJSON = "application/json" ContentTypeProtobuf = "application/x-protobuf" ContentTypeAltProtobuf = "application/protobuf" )
const ( DefaultLogSource = "otel_logs" DefaultLogService = "unSetServiceName" DefaultSchemaURLKey = "schema_url" DefaultMessageField = "message" DefaultTraceIDField = "trace_id" DefaultSpanIDField = "span_id" DefaultStatusTag = "status" DefaultServiceTag = "service" DefaultSourceTag = "source" DefaultHostTag = "host" DefaultFingerprintTag = "dk_fingerprint" DefaultMaxMessageLength = 32 * 1024 )
const ( DefaultMetricMeasurement = "otel_service" DefaultMetricTemporality = "__temporality" DefaultCollectorSourceTag = "collector_source_ip" DefaultScopeNameKey = "scope_name" )
const ( AttrServiceName = "service.name" AttrDBSystem = "db.system" AttrMessagingSystem = "messaging.system" AttrRPCSystem = "rpc.system" EventException = "exception" AttrExceptionType = "exception.type" AttrExceptionMessage = "exception.message" AttrExceptionStacktrace = "exception.stacktrace" )
const ( MetricTagUnit = "unit" MetricTagLE = "le" MetricSuffixBucket = "_bucket" MetricSuffixSum = "_sum" MetricSuffixCount = "_count" MetricSuffixAvg = "_avg" MetricSuffixMin = "_min" MetricSuffixMax = "_max" MetricSuffixInf = "+Inf" )
const ( SpanStatusInfo = "info" SpanStatusOK = "ok" SpanStatusError = "error" )
const ( DefaultTracePointName = "tracing" DefaultUnknownService = "unknown_service" DefaultTraceSource = "opentelemetry" DefaultParentSpanID = "0" DefaultTraceBaseServiceTag = "base_service" DefaultTraceStatusTag = "status" DefaultTraceSpanTypeTag = "span_type" DefaultTraceSpanKindTag = "span_kind" DefaultTraceSourceTypeTag = "source_type" DefaultTraceFingerprintTag = "dk_fingerprint" DefaultTraceServiceTag = "service" DefaultTraceSourceTag = "source" DefaultTraceTraceIDField = "trace_id" DefaultTraceParentIDField = "parent_id" DefaultTraceSpanIDField = "span_id" DefaultTraceResourceField = "resource" DefaultTraceStartField = "start" DefaultTraceDurationField = "duration" DefaultTraceMessageField = "message" DefaultTraceRuntimeIDField = "runtime_id" DefaultTraceDBHostTag = "db_host" TraceSourceTypeWeb = "web" TraceSourceTypeDB = "db" TraceSourceTypeMessage = "message_queue" TraceSourceTypeCustomer = "custom" )
Variables ¶
var ErrUnsupportedContentType = errors.New("unsupported OTLP content type")
var PublicAttributeAliases = map[string]string{
"db.system": "db_system",
"db.operation": "db_operation",
"db.name": "db_name",
"db.statement": "db_statement",
"server.address": "server_address",
"net.host.name": "net_host_name",
"server.port": "server_port",
"net.host.port": "net_host_port",
"network.peer.address": "network_peer_address",
"network.peer.port": "network_peer_port",
"network.transport": "network_transport",
"http.request.method": "http_method",
"http.method": "http_method",
"error.type": "error_type",
"http.response.status_code": "http_status_code",
"http.status_code": "http_status_code",
"http.route": "http_route",
"http.target": "http_target",
"http.scheme": "http_scheme",
"http.url": "http_url",
"url.full": "url_full",
"url.scheme": "url_scheme",
"url.path": "url_path",
"url.query": "url_query",
"client.address": "client_address",
"client.port": "client_port",
"messaging.system": "messaging_system",
"messaging.operation": "messaging_operation",
"messaging.message.id": "messaging_message.id",
"messaging.destination.name": "messaging_destination.name",
"rpc.service": "rpc_service",
"rpc.system": "rpc_system",
"exception": "exception",
"exception.type": "exception_type",
"exception.message": "exception_message",
"exception.stacktrace": "exception_stacktrace",
"container.name": "container_name",
"process.pid": "process_pid",
"project": "project",
"version": "version",
"env": "env",
"host": "host",
"pod_name": "pod_name",
"pod_namespace": "pod_namespace",
"telemetry.sdk.language": "sdk_language",
"telemetry.sdk.name": "sdk_name",
"telemetry.sdk.version": "sdk_version",
}
var SpanKindNames = map[int32]string{
0: "unspecified",
1: "internal",
2: "server",
3: "client",
4: "producer",
5: "consumer",
}
Functions ¶
func AnyValueToInterface ¶
AnyValueToInterface converts an OTLP AnyValue into a Go value.
func AnyValueToString ¶
AnyValueToString converts an OTLP AnyValue into a string form suitable for tags or fields.
func AttributesToStringMap ¶
func AttributesToStringMap(attrs []*common.KeyValue, opts StringMapOptions) map[string]string
AttributesToStringMap converts OTLP attributes to a string map.
func AttributesToTagMap ¶
func AttributesToTagMap(attrs []*common.KeyValue, opts StringMapOptions) map[string]string
func Base64RawID ¶
Base64RawID converts an OTLP binary ID into raw base64 without padding.
func ChunkStringByRuneLength ¶
ChunkStringByRuneLength splits s into chunks measured by rune count.
func DBHostFromAttributes ¶
func DecimalIDFromLast8Bytes ¶
DecimalIDFromLast8Bytes converts the last 8 bytes of id as a big-endian uint64.
func DefaultHostName ¶
func FindAttribute ¶
FindAttribute returns the first attribute with key and its position.
func LogStatusFromSeverityNumber ¶
LogStatusFromSeverityNumber maps OTLP log severity numbers to a status string.
func MergeStringMapsAsFields ¶
MergeStringMapsAsFields merges maps into point fields, replacing dots in keys.
func MergeStringMapsAsTags ¶
MergeStringMapsAsTags merges maps into point tags, replacing dots in keys.
func MetricNameFromAttribute ¶
func NormalizeContentType ¶
NormalizeContentType strips parameters and normalizes a content-type value.
func NumberDataPointToPoint ¶
func NumberDataPointToPoint(measurement, field string, kvs point.KVs, pt *metrics.NumberDataPoint, kvOpts []point.KVOption) *point.Point
NumberDataPointToPoint converts an OTLP NumberDataPoint into a metric point.
func NumberDataPointValue ¶
func NumberDataPointValue(pt *metrics.NumberDataPoint) (any, bool)
NumberDataPointValue extracts the scalar value from an OTLP NumberDataPoint.
func ParseLogRequest ¶
func ParseLogRequest(resourceLogs []*logs.ResourceLogs, opts LogsParserOptions) []*point.Point
func ParseResourceMetricsV2 ¶
func ParseResourceMetricsV2(resmcs []*metrics.ResourceMetrics, opts MetricsParserOptions) []*point.Point
func PublicAttributeAlias ¶
PublicAttributeAlias returns the normalized alias of a semantic-convention attribute key.
func ShouldDropMetricAttribute ¶
ShouldDropMetricAttribute reports whether a resource or datapoint attribute is ignored for metrics.
func SpanKindName ¶
SpanKindName returns the readable span kind. Unknown values fallback to "unspecified".
func SummaryDataPointToPoint ¶
func SummaryDataPointToPoint(measurement, field string, kvs point.KVs, summary *metrics.SummaryDataPoint, kvOpts []point.KVOption) *point.Point
SummaryDataPointToPoint converts an OTLP SummaryDataPoint into a metric point.
func SystemNameForService ¶
SystemNameForService returns db/rpc/messaging system value for service-name fallback.
func TraceSourceTypeFromTags ¶
func TraceStatusFromCode ¶
TraceStatusFromCode maps OTLP trace status code to a compact status string.
Types ¶
type LogsParserOptions ¶
type LogsParserOptions struct {
CollectorSourceIP string
CollectorSourceIPTag string
DKFingerprint string
DKFingerprintTag string
ResourceStringOptions StringMapOptions
ScopeStringOptions StringMapOptions
RecordStringOptions StringMapOptions
SchemaURLKey string
ScopeNameKey string
MessageField string
TraceIDField string
SpanIDField string
StatusTag string
ServiceTag string
SourceTag string
HostTag string
MaxMessageLen int
GlobalFields map[string]any
GlobalTags map[string]string
IDConverter func([]byte) string
ServiceAndSource func([]*common.KeyValue) (service, source string)
HostName func([]*common.KeyValue) string
SeverityMapper func(logs.SeverityNumber, string) string
PointOptions func(ts time.Time) []point.Option
}
type MetricsParserOptions ¶
type MetricsParserOptions struct {
Measurement string
CollectorSourceIP string
CollectorSourceIPTag string
ScopeNameKey string
TemporalityTagKey string
ResourceStringOptions StringMapOptions
ScopeStringOptions StringMapOptions
PointStringOptions StringMapOptions
FieldName func(metric *metrics.Metric, pointAttrs map[string]string) string
MeasurementFromPointAttr func(metric *metrics.Metric, pointAttrs map[string]string) string
KVOptions func(metric *metrics.Metric) []point.KVOption
PointOptions func(ts time.Time) []point.Option
ExponentialHistogramAvg func(sum float64, count uint64) any
}
type StringMapOptions ¶
type StringMapOptions struct {
KeyNormalizer func(string) string
MaxValueLen int
DropKeys map[string]struct{}
}
func DefaultMetricStringMapOptions ¶
func DefaultMetricStringMapOptions() StringMapOptions
type TraceBatch ¶
func ParseResourceSpans ¶
func ParseResourceSpans(resourceSpans []*trace.ResourceSpans, opts TracesParserOptions) []TraceBatch
type TracesParserOptions ¶
type TracesParserOptions struct {
PointName string
Source string
CollectorSourceIP string
CollectorSourceIPTag string
DKFingerprint string
DKFingerprintTag string
UnknownService string
ServiceTag string
BaseServiceTag string
SpanStatusTag string
SpanTypeTag string
SpanKindTag string
SourceTag string
SourceTypeTag string
DBHostTag string
TraceIDField string
ParentIDField string
SpanIDField string
ResourceField string
StartField string
DurationField string
MessageField string
RuntimeIDField string
GlobalTags map[string]string
IDConverter func([]byte) string
SelectAttrs func([]*common.KeyValue) (point.KVs, []*common.KeyValue)
ScopeKVs func(*trace.ScopeSpans) point.KVs
SpanType func(spanID, parentID string, spanIDs, parentIDs map[string]bool) string
SpanStatus func(*trace.Status) string
SpanKind func(int32) string
SourceType func(point.KVs) string
BaseService func(map[string]string) string
DecorateKVs func(point.KVs, *trace.ResourceSpans, *trace.ScopeSpans, *trace.Span) point.KVs
MessageEncoder func(*trace.Span) (string, error)
CleanSpan func(*trace.Span) *trace.Span
}