Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/trace/api/otlp: support APM peer.service in OTLP #16490

Merged
merged 10 commits into from
Apr 27, 2023
28 changes: 23 additions & 5 deletions pkg/trace/api/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,25 @@ func setMetricOTLP(s *pb.Span, k string, v float64) {
}
}

// peerServiceDefaults specifies default keys used to find a value for _dd.peer.service.source, applied in the order defined below.
songy23 marked this conversation as resolved.
Show resolved Hide resolved
var peerServiceDefaults = []string{
// Always use peer.service when it's present
semconv.AttributePeerService,
// Service-to-service gRPC scenario
semconv.AttributeRPCService,
// Database
semconv.AttributeDBSystem,
"db.instance",
// Service-to-service HTTP scenario & server-based data streams
// Also fallback in case the above attributes are not present
semconv.AttributeNetPeerName,
// Serverless Database
semconv.AttributeAWSDynamoDBTableNames,
// Blob storage
"bucket.name",
semconv.AttributeFaaSDocumentCollection,
}

// convertSpan converts the span in to a Datadog span, and uses the rattr resource tags and the lib instrumentation
// library attributes to further augment it.
//
Expand All @@ -515,6 +534,7 @@ func (o *OTLPReceiver) convertSpan(rattr map[string]string, lib pcommon.Instrume
setMetaOTLP(span, k, v)
}
setMetaOTLP(span, "otel.trace_id", hex.EncodeToString(traceID[:]))
setMetaOTLP(span, "span.kind", spanKindName(in.Kind()))
if _, ok := span.Meta["version"]; !ok {
if ver := rattr[string(semconv.AttributeServiceVersion)]; ver != "" {
setMetaOTLP(span, "version", ver)
Expand All @@ -526,11 +546,6 @@ func (o *OTLPReceiver) convertSpan(rattr map[string]string, lib pcommon.Instrume
if in.Links().Len() > 0 {
setMetaOTLP(span, "_dd.span_links", marshalLinks(in.Links()))
}
if svc, ok := in.Attributes().Get(semconv.AttributePeerService); ok {
// the span attribute "peer.service" takes precedence over any resource attributes,
// in the same way that "service.name" does as part of setMetaOTLP
span.Service = svc.Str()
}
in.Attributes().Range(func(k string, v pcommon.Value) bool {
switch v.Type() {
case pcommon.ValueTypeDouble:
Expand All @@ -542,6 +557,9 @@ func (o *OTLPReceiver) convertSpan(rattr map[string]string, lib pcommon.Instrume
}
return true
})
if svc := getFirstFromMap(span.Meta, peerServiceDefaults...); svc != "" {
setMetaOTLP(span, "_dd.peer.service.source", svc)
}
songy23 marked this conversation as resolved.
Show resolved Hide resolved
for k, v := range attributes.ContainerTagFromAttributes(span.Meta) {
if _, ok := span.Meta[k]; !ok {
// overwrite only if it does not exist
Expand Down
Loading