traceutil

package
v0.78.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package traceutil provides utilities for converting OTel semantics to DD semantics.

Index

Constants

View Source
const DefaultOTLPServiceName = "otlpresourcenoservicename"

DefaultOTLPServiceName is the default service name for OTel spans when no service name is found in the resource attributes.

Variables

View Source
var (
	// SignalTypeSet is the OTel attribute set for traces.
	SignalTypeSet = attribute.NewSet(attribute.String("signal", "traces"))
)

Functions

func GetOTelAttrFromEitherMap

func GetOTelAttrFromEitherMap(map1 pcommon.Map, map2 pcommon.Map, normalize bool, keys ...string) string

GetOTelAttrFromEitherMap returns the matched value as a string in either attribute map with the given keys. If there are multiple keys present, the first matched one is returned. If the key is present in both maps, map1 takes precedence. If normalize is true, normalize the return value with NormalizeTagValue.

func GetOTelAttrVal

func GetOTelAttrVal(attrs pcommon.Map, normalize bool, keys ...string) string

GetOTelAttrVal returns the matched value as a string in the input map with the given keys. If there are multiple keys present, the first matched one is returned. If normalize is true, normalize the return value with NormalizeTagValue.

func GetOTelAttrValInResAndSpanAttrs

func GetOTelAttrValInResAndSpanAttrs(span ptrace.Span, res pcommon.Resource, normalize bool, keys ...string) string

GetOTelAttrValInResAndSpanAttrs returns the matched value as a string in the OTel resource attributes and span attributes with the given keys. If there are multiple keys present, the first matched one is returned. If the key is present in both resource attributes and span attributes, resource attributes take precedence. If normalize is true, normalize the return value with NormalizeTagValue.

func GetOTelContainerTags

func GetOTelContainerTags(rattrs pcommon.Map, tagKeys []string) []string

GetOTelContainerTags returns a list of DD container tags in the OTel resource attributes. Tags are always normalized.

func GetOTelOperationNameV1

func GetOTelOperationNameV1(
	span ptrace.Span,
	res pcommon.Resource,
	lib pcommon.InstrumentationScope,
	spanNameAsResourceName bool,
	spanNameRemappings map[string]string,
	normalize bool) string

GetOTelOperationNameV1 returns the DD operation name based on OTel span and resource attributes and given configs.

func GetOTelOperationNameV2

func GetOTelOperationNameV2(span ptrace.Span, res pcommon.Resource) string

GetOTelOperationNameV2 returns the DD operation name based on OTel span and resource attributes.

func GetOTelOperationNameV2WithAccessor added in v0.78.0

func GetOTelOperationNameV2WithAccessor[A semantics.Accessor](span ptrace.Span, accessor A) string

GetOTelOperationNameV2WithAccessor is like GetOTelOperationNameV2 but uses a pre-created accessor to avoid repeated allocation when multiple lookups share the same span and resource attribute maps.

func GetOTelResourceV1

func GetOTelResourceV1(span ptrace.Span, res pcommon.Resource) (resName string)

GetOTelResourceV1 returns the DD resource name based on OTel span and resource attributes.

func GetOTelResourceV2

func GetOTelResourceV2(span ptrace.Span, res pcommon.Resource) string

GetOTelResourceV2 returns the DD resource name based on OTel span and resource attributes.

func GetOTelResourceV2WithAccessor added in v0.78.0

func GetOTelResourceV2WithAccessor[A semantics.Accessor](span ptrace.Span, accessor A) string

GetOTelResourceV2WithAccessor is like GetOTelResourceV2 but uses a pre-created accessor to avoid repeated allocation when multiple lookups share the same span and resource attribute maps.

func GetOTelService

func GetOTelService(span ptrace.Span, res pcommon.Resource, normalize bool) string

GetOTelService returns the DD service name based on OTel span and resource attributes.

func GetOTelServiceWithAccessor added in v0.78.0

func GetOTelServiceWithAccessor[A semantics.Accessor](accessor A, normalize bool) string

GetOTelServiceWithAccessor is like GetOTelService but uses a pre-created accessor to avoid repeated allocation when multiple lookups share the same span and resource attribute maps.

func GetOTelSpanType

func GetOTelSpanType(span ptrace.Span, res pcommon.Resource) string

GetOTelSpanType returns the DD span type based on OTel span kind and attributes. This logic is used in ReceiveResourceSpansV2 logic

func GetOTelSpanTypeWithAccessor added in v0.78.0

func GetOTelSpanTypeWithAccessor[A semantics.Accessor](span ptrace.Span, accessor A) string

GetOTelSpanTypeWithAccessor returns the DD span type based on OTel span kind and attributes, using a pre-created accessor to avoid repeated allocation when multiple lookups share the same span and resource attribute maps.

func GetTopLevelOTelSpans

func GetTopLevelOTelSpans(spanByID map[pcommon.SpanID]ptrace.Span, resByID map[pcommon.SpanID]pcommon.Resource, topLevelByKind bool) map[pcommon.SpanID]struct{}

GetTopLevelOTelSpans returns the span IDs of the top level OTel spans.

func IndexOTelSpans

IndexOTelSpans iterates over the input OTel spans and returns 3 maps: OTel spans indexed by span ID, OTel resources indexed by span ID, OTel instrumentation scopes indexed by span ID. Skips spans with invalid trace ID or span ID. If there are multiple spans with the same (non-zero) span ID, the last one wins.

func LookupSemanticFloat64 added in v0.78.0

func LookupSemanticFloat64(primary, secondary pcommon.Map, concept semantics.Concept) (float64, bool)

LookupSemanticFloat64 looks up a semantic concept as a float64 from two OTel attribute maps. The primary map takes precedence over secondary.

func LookupSemanticInt64 added in v0.78.0

func LookupSemanticInt64(primary, secondary pcommon.Map, concept semantics.Concept) (int64, bool)

LookupSemanticInt64 looks up a semantic concept as an int64 from two OTel attribute maps. The primary map takes precedence over secondary.

func LookupSemanticString added in v0.78.0

func LookupSemanticString(attrs pcommon.Map, concept semantics.Concept, shouldNormalize bool) string

LookupSemanticString looks up a semantic concept from a single OTel attribute map. It uses the semantics registry to check all equivalent attribute keys in precedence order. If shouldNormalize is true, normalize the return value with NormalizeTagValue.

func LookupSemanticStringFromDualMaps added in v0.78.0

func LookupSemanticStringFromDualMaps(primary, secondary pcommon.Map, concept semantics.Concept, shouldNormalize bool) string

LookupSemanticStringFromDualMaps looks up a semantic concept from two OTel attribute maps. The primary map (typically span attributes) takes precedence over secondary (typically resource attributes). If shouldNormalize is true, normalize the return value with NormalizeTagValue.

For functions that perform multiple lookups on the same map pair, prefer creating a single OTelSpanAccessor and calling lookupString directly to avoid repeated accessor allocation.

func LookupSemanticStringWithAccessor added in v0.78.0

func LookupSemanticStringWithAccessor[A semantics.Accessor](accessor A, concept semantics.Concept, shouldNormalize bool) string

LookupSemanticStringWithAccessor looks up a semantic concept using a pre-created accessor. Use this when performing multiple lookups on the same attribute maps to avoid repeated accessor allocation. If shouldNormalize is true, normalize the return value with NormalizeTagValue.

func OTelSpanIDToUint64

func OTelSpanIDToUint64(b [8]byte) uint64

OTelSpanIDToUint64 converts an OTel span ID to an uint64

func OTelSpanKindName

func OTelSpanKindName(k ptrace.SpanKind) string

OTelSpanKindName converts the given SpanKind to a valid Datadog span kind name.

func OTelTraceIDToUint64

func OTelTraceIDToUint64(b [16]byte) uint64

OTelTraceIDToUint64 converts an OTel trace ID to an uint64

func SpanKind2Type

func SpanKind2Type(span ptrace.Span, res pcommon.Resource) string

SpanKind2Type returns a span's type based on the given kind and other present properties. This function is used in Resource V1 logic only. See GetOtelSpanType for Resource V2 logic.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL