Documentation
¶
Overview ¶
Package transform implements mappings from OTLP to DD semantics, and helpers
Index ¶
- Constants
- Variables
- func GetDDKeyForOTLPAttribute(k string) string
- func GetFirstFromMap(m map[string]string, keys ...string) (string, string)
- func GetOTelAttrFromEitherMap(map1 pcommon.Map, map2 pcommon.Map, normalize bool, keys ...string) string
- func GetOTelAttrVal(attrs pcommon.Map, normalize bool, keys ...string) string
- func GetOTelAttrValInResAndSpanAttrs(span ptrace.Span, res pcommon.Resource, normalize bool, keys ...string) string
- func GetOTelContainerID(span ptrace.Span, res pcommon.Resource) string
- func GetOTelContainerOrPodID(span ptrace.Span, res pcommon.Resource) string
- func GetOTelContainerTags(rattrs pcommon.Map, tagKeys []string) []string
- func GetOTelEnv(span ptrace.Span, res pcommon.Resource) string
- func GetOTelHostname(span ptrace.Span, res pcommon.Resource, tr *attributes.Translator, ...) string
- func GetOTelOperationNameV1(span ptrace.Span, res pcommon.Resource, lib pcommon.InstrumentationScope, ...) string
- func GetOTelOperationNameV2(span ptrace.Span, res pcommon.Resource) string
- func GetOTelOperationNameV2WithAccessor[A semantics.Accessor](span ptrace.Span, accessor A) string
- func GetOTelResourceV1(span ptrace.Span, res pcommon.Resource) (resName string)
- func GetOTelResourceV2(span ptrace.Span, res pcommon.Resource) string
- func GetOTelResourceV2WithAccessor[A semantics.Accessor](span ptrace.Span, accessor A) string
- func GetOTelService(span ptrace.Span, res pcommon.Resource, normalize bool) string
- func GetOTelServiceWithAccessor[A semantics.Accessor](accessor A, normalize bool) string
- func GetOTelSpanType(span ptrace.Span, res pcommon.Resource) string
- func GetOTelSpanTypeWithAccessor[A semantics.Accessor](span ptrace.Span, accessor A) string
- func GetOTelStatusCode(span ptrace.Span, res pcommon.Resource) uint32
- func GetOTelVersion(span ptrace.Span, res pcommon.Resource) string
- func GetTopLevelOTelSpans(spanByID map[pcommon.SpanID]ptrace.Span, ...) map[pcommon.SpanID]struct{}
- func IndexOTelSpans(traces ptrace.Traces) (map[pcommon.SpanID]ptrace.Span, map[pcommon.SpanID]pcommon.Resource, ...)
- func LookupSemanticFloat64(primary, secondary pcommon.Map, concept semantics.Concept) (float64, bool)
- func LookupSemanticInt64(primary, secondary pcommon.Map, concept semantics.Concept) (int64, bool)
- func LookupSemanticString(attrs pcommon.Map, concept semantics.Concept, shouldNormalize bool) string
- func LookupSemanticStringFromDualMaps(primary, secondary pcommon.Map, concept semantics.Concept, ...) string
- func LookupSemanticStringWithAccessor[A semantics.Accessor](accessor A, concept semantics.Concept, shouldNormalize bool) string
- func MarshalEvents(events ptrace.SpanEventSlice) string
- func MarshalLinks(links ptrace.SpanLinkSlice) string
- func OTelSpanIDToUint64(b [8]byte) uint64
- func OTelSpanKindName(k ptrace.SpanKind) string
- func OTelTraceIDToUint64(b [16]byte) uint64
- func ObfuscateRedisSpan(o *obfuscate.Obfuscator, span *pb.Span, removeAllArgs bool)
- func ObfuscateSQLSpan(o *obfuscate.Obfuscator, span *pb.Span) (*obfuscate.ObfuscatedQuery, error)
- func ObfuscateValkeySpan(o *obfuscate.Obfuscator, span *pb.Span, removeAllArgs bool)
- func OperationAndResourceNameV2Enabled(conf *config.AgentConfig) bool
- func OtelSpanToDDSpan(otelspan ptrace.Span, otelres pcommon.Resource, ...) *pb.Span
- func OtelSpanToDDSpanMinimal(otelspan ptrace.Span, otelres pcommon.Resource, ...) *pb.Span
- func SetMetaOTLP(s *pb.Span, k, v string)
- func SetMetaOTLPIfEmpty(s *pb.Span, k, v string)
- func SetMetricOTLP(s *pb.Span, k string, v float64)
- func SetMetricOTLPIfEmpty(s *pb.Span, k string, v float64)
- func SpanKind2Type(span ptrace.Span, res pcommon.Resource) string
- func Status2Error(status ptrace.Status, _ ptrace.SpanEventSlice, metaMap map[string]string) int32
- func TagSpanIfContainsExceptionEvent(otelspan ptrace.Span, ddspan *pb.Span)
Constants ¶
const ( // TagRedisRawCommand represents a redis raw command tag TagRedisRawCommand = "redis.raw_command" // TagValkeyRawCommand represents a redis raw command tag TagValkeyRawCommand = "valkey.raw_command" // TagMemcachedCommand represents a memcached command tag TagMemcachedCommand = "memcached.command" // TagMongoDBQuery represents a MongoDB query tag TagMongoDBQuery = "mongodb.query" // TagElasticBody represents an Elasticsearch body tag TagElasticBody = "elasticsearch.body" // TagOpenSearchBody represents an OpenSearch body tag TagOpenSearchBody = "opensearch.body" // TagSQLQuery represents a SQL query tag TagSQLQuery = "sql.query" // TagHTTPURL represents an HTTP URL tag TagHTTPURL = "http.url" // TagDBMS represents a DBMS tag TagDBMS = "db.type" )
const DefaultOTLPServiceName = "otlpresourcenoservicename"
DefaultOTLPServiceName is the default service name for OTel spans when no service name is found in the resource attributes.
const (
// TextNonParsable is the error text used when a query is non-parsable
TextNonParsable = "Non-parsable SQL query"
)
Variables ¶
var ( // SignalTypeSet is the OTel attribute set for traces. SignalTypeSet = attribute.NewSet(attribute.String("signal", "traces")) )
Functions ¶
func GetDDKeyForOTLPAttribute ¶ added in v0.65.0
GetDDKeyForOTLPAttribute looks for a key in the Datadog HTTP convention that matches the given key from the OTLP HTTP convention. Otherwise, check if it is a Datadog APM convention key - if it is, it will be handled with specialized logic elsewhere, so return an empty string. If it isn't, return the original key.
func GetFirstFromMap ¶
GetFirstFromMap checks each key in the given keys in the map and returns the first key-value pair whose key matches, or empty strings if none matches.
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 ¶
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 GetOTelContainerID ¶ added in v0.68.0
GetOTelContainerID returns the container ID based on OTel span and resource attributes, with span taking precedence.
func GetOTelContainerOrPodID ¶ added in v0.77.0
GetOTelContainerOrPodID returns the container ID based on OTel span and resource attributes, with span taking precedence.
The Kubernetes pod UID will be used as a fallback if the container ID is not found. This is only done for backward compatibility; consider using GetOTelContainerID instead.
func GetOTelContainerTags ¶ added in v0.68.0
GetOTelContainerTags returns a list of DD container tags in the OTel resource attributes. Tags are always normalized.
func GetOTelEnv ¶ added in v0.68.0
GetOTelEnv returns the environment based on OTel span and resource attributes, with span taking precedence.
func GetOTelHostname ¶ added in v0.68.0
func GetOTelHostname(span ptrace.Span, res pcommon.Resource, tr *attributes.Translator, fallbackHost string) string
GetOTelHostname returns the DD hostname based on OTel span and resource attributes, with span taking precedence.
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 ¶
GetOTelOperationNameV2 returns the DD operation name based on OTel span and resource attributes.
func GetOTelOperationNameV2WithAccessor ¶
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 ¶
GetOTelResourceV1 returns the DD resource name based on OTel span and resource attributes.
func GetOTelResourceV2 ¶
GetOTelResourceV2 returns the DD resource name based on OTel span and resource attributes.
func GetOTelResourceV2WithAccessor ¶
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 ¶
GetOTelService returns the DD service name based on OTel span and resource attributes.
func GetOTelServiceWithAccessor ¶
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 ¶
GetOTelSpanType returns the DD span type based on OTel span kind and attributes. This logic is used in ReceiveResourceSpansV2 logic
func GetOTelSpanTypeWithAccessor ¶
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 GetOTelStatusCode ¶ added in v0.68.0
GetOTelStatusCode returns the HTTP status code based on OTel span and resource attributes, with span taking precedence.
func GetOTelVersion ¶ added in v0.68.0
GetOTelVersion returns the version based on OTel span and resource attributes, with span taking precedence.
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 ¶
func IndexOTelSpans(traces ptrace.Traces) (map[pcommon.SpanID]ptrace.Span, map[pcommon.SpanID]pcommon.Resource, map[pcommon.SpanID]pcommon.InstrumentationScope)
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 ¶
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 ¶
LookupSemanticInt64 looks up a semantic concept as an int64 from two OTel attribute maps. The primary map takes precedence over secondary.
func LookupSemanticString ¶
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 ¶
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 ¶
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 MarshalEvents ¶
func MarshalEvents(events ptrace.SpanEventSlice) string
MarshalEvents marshals events into JSON.
func MarshalLinks ¶
func MarshalLinks(links ptrace.SpanLinkSlice) string
MarshalLinks marshals span links into JSON.
func OTelSpanIDToUint64 ¶
OTelSpanIDToUint64 converts an OTel span ID to an uint64
func OTelSpanKindName ¶
OTelSpanKindName converts the given SpanKind to a valid Datadog span kind name.
func OTelTraceIDToUint64 ¶
OTelTraceIDToUint64 converts an OTel trace ID to an uint64
func ObfuscateRedisSpan ¶ added in v0.63.0
func ObfuscateRedisSpan(o *obfuscate.Obfuscator, span *pb.Span, removeAllArgs bool)
ObfuscateRedisSpan obfuscates a Redis span using pkg/obfuscate logic
func ObfuscateSQLSpan ¶ added in v0.63.0
func ObfuscateSQLSpan(o *obfuscate.Obfuscator, span *pb.Span) (*obfuscate.ObfuscatedQuery, error)
ObfuscateSQLSpan obfuscates a SQL span using pkg/obfuscate logic
func ObfuscateValkeySpan ¶ added in v0.64.0
func ObfuscateValkeySpan(o *obfuscate.Obfuscator, span *pb.Span, removeAllArgs bool)
ObfuscateValkeySpan obfuscates a Valkey span using pkg/obfuscate logic
func OperationAndResourceNameV2Enabled ¶ added in v0.61.0
func OperationAndResourceNameV2Enabled(conf *config.AgentConfig) bool
OperationAndResourceNameV2Enabled checks if the new operation and resource name logic should be used
func OtelSpanToDDSpan ¶
func OtelSpanToDDSpan( otelspan ptrace.Span, otelres pcommon.Resource, lib pcommon.InstrumentationScope, conf *config.AgentConfig, ) *pb.Span
OtelSpanToDDSpan converts an OTel span to a DD span.
func OtelSpanToDDSpanMinimal ¶
func OtelSpanToDDSpanMinimal( otelspan ptrace.Span, otelres pcommon.Resource, lib pcommon.InstrumentationScope, isTopLevel, topLevelByKind bool, conf *config.AgentConfig, peerTagKeys []string, ) *pb.Span
OtelSpanToDDSpanMinimal converts an OTel span to a DD span with only the minimal fields needed for APM stats calculation. Only use with OTLPTracesToConcentratorInputs.
func SetMetaOTLP ¶
SetMetaOTLP sets the k/v OTLP attribute pair as a tag on span s.
func SetMetaOTLPIfEmpty ¶ added in v0.68.0
SetMetaOTLPIfEmpty sets the k/v OTLP attribute pair as a tag on span s, if the corresponding value hasn't been set already.
func SetMetricOTLP ¶
SetMetricOTLP sets the k/v OTLP attribute pair as a metric on span s.
func SetMetricOTLPIfEmpty ¶ added in v0.68.0
SetMetricOTLPIfEmpty sets the k/v OTLP attribute pair as a metric on span s, if the corresponding value hasn't been set already.
func SpanKind2Type ¶
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.
func Status2Error ¶
Status2Error checks the given status and events and applies any potential error and messages to the given span attributes. Note: This function uses the semantic registry for http.status_code lookup precedence. Previously it used NEW-first precedence (http.response.status_code before http.status_code).
Types ¶
This section is empty.