Skip to content

Commit

Permalink
OTEL-738: Add support for custom container tags (datadog.container.ta…
Browse files Browse the repository at this point in the history
…g.* namespace)

This PR is a follow up to DataDog/opentelemetry-mapping-go#193 which adds support for custom container tags via resource attributes prefixed by `datadog.container.tag`.

This PR also brings a couple other changes:
- Stop extracting container tags from span attributes, but only extract from resource attributes. The semantic conventions we are using to extract the container tags are meant for resource attributes, so we should only check resource attributes.
- Stop setting the DD Format container tags as span tags, but only set these in the dedicated container tag (_dd.container.tag). We currently set the DD mapped container tags both as span tag, and in the `_dd.tags.container`. This should only be set in `_dd.tags.container`. In fact container tags are treated differently than span tags (searchable without @, have a dedicated container tab in the UI...etc)
  • Loading branch information
mackjmr committed Nov 10, 2023
1 parent 4e241a7 commit 25c8244
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 152 deletions.
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ require (
github.com/DataDog/go-tuf v1.0.2-0.5.2
github.com/DataDog/gopsutil v1.2.2
github.com/DataDog/nikos v1.12.1
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.8.0
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.8.1
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.8.0
github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.8.0
github.com/DataDog/sketches-go v1.4.2
Expand Down Expand Up @@ -220,7 +220,7 @@ require (
go.opentelemetry.io/collector/exporter v0.87.0
go.opentelemetry.io/collector/exporter/loggingexporter v0.87.0
go.opentelemetry.io/collector/exporter/otlpexporter v0.87.0
go.opentelemetry.io/collector/pdata v1.0.0-rcv0016
go.opentelemetry.io/collector/pdata v1.0.0-rcv0017
go.opentelemetry.io/collector/processor/batchprocessor v0.87.0
go.opentelemetry.io/collector/receiver v0.87.0
go.opentelemetry.io/collector/receiver/otlpreceiver v0.87.0
Expand All @@ -233,14 +233,14 @@ require (
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d
golang.org/x/arch v0.5.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/net v0.17.0
golang.org/x/net v0.18.0
golang.org/x/sync v0.4.0
golang.org/x/sys v0.14.1-0.20231108175955-e4099bfacb8c
golang.org/x/text v0.14.0
golang.org/x/time v0.3.0
golang.org/x/tools v0.14.0
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto v0.0.0-20231030173426-d783a09b4405 // indirect
google.golang.org/grpc v1.59.0
google.golang.org/grpc/examples v0.0.0-20221020162917-9127159caf5a
google.golang.org/protobuf v1.31.0
Expand All @@ -267,10 +267,10 @@ require (
)

require (
cloud.google.com/go v0.110.7 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go v0.110.9 // indirect
cloud.google.com/go/compute v1.23.2 // indirect
cloud.google.com/go/compute/metadata v0.2.4-0.20230617002413-005d2dfb6b68 // indirect
cloud.google.com/go/iam v1.1.2 // indirect
cloud.google.com/go/iam v1.1.4 // indirect
cloud.google.com/go/storage v1.31.0 // indirect
code.cloudfoundry.org/cfhttp/v2 v2.0.0 // indirect
code.cloudfoundry.org/clock v1.0.0 // indirect
Expand Down Expand Up @@ -527,7 +527,7 @@ require (
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector/consumer v0.87.0
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0016 // indirect
go.opentelemetry.io/collector/semconv v0.87.0 // indirect
go.opentelemetry.io/collector/semconv v0.88.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.19.0 // indirect
Expand All @@ -541,10 +541,10 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/mod v0.13.0
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/term v0.14.0 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
google.golang.org/api v0.134.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down Expand Up @@ -673,8 +673,8 @@ require (
golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
honnef.co/go/tools v0.3.2 // indirect
inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a // indirect
Expand Down
48 changes: 24 additions & 24 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 3 additions & 14 deletions pkg/trace/api/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func (o *OTLPReceiver) ReceiveResourceSpans(ctx context.Context, rspans ptrace.R
}
tracesByID := make(map[uint64]pb.Trace)
priorityByID := make(map[uint64]sampler.SamplingPriority)
ctags := make(map[string]string)
var spancount int64
for i := 0; i < rspans.ScopeSpans().Len(); i++ {
libspans := rspans.ScopeSpans().At(i)
Expand All @@ -226,7 +225,7 @@ func (o *OTLPReceiver) ReceiveResourceSpans(ctx context.Context, rspans ptrace.R
if tracesByID[traceID] == nil {
tracesByID[traceID] = pb.Trace{}
}
ddspan := o.convertSpan(rattr, lib, span, ctags)
ddspan := o.convertSpan(rattr, lib, span)
if !srcok {
// if we didn't find a hostname at the resource level
// try and see if the span has a hostname set
Expand Down Expand Up @@ -284,6 +283,7 @@ func (o *OTLPReceiver) ReceiveResourceSpans(ctx context.Context, rspans ptrace.R
LanguageVersion: tagstats.LangVersion,
TracerVersion: tagstats.TracerVersion,
}
ctags := attributes.ContainerTagsFromResourceAttributes(attr)
payloadTags := flatten(ctags)
if tags := getContainerTags(o.conf.ContainerTags, containerID); tags != "" {
appendTags(payloadTags, tags)
Expand Down Expand Up @@ -499,9 +499,7 @@ func setMetricOTLP(s *pb.Span, k string, v float64) {

// 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.
//
// ctags will be used to write container tags to. Existing ones are not overridden.
func (o *OTLPReceiver) convertSpan(rattr map[string]string, lib pcommon.InstrumentationScope, in ptrace.Span, ctags map[string]string) *pb.Span {
func (o *OTLPReceiver) convertSpan(rattr map[string]string, lib pcommon.InstrumentationScope, in ptrace.Span) *pb.Span {
traceID := [16]byte(in.TraceID())
span := &pb.Span{
TraceID: traceIDToUint64(traceID),
Expand Down Expand Up @@ -539,15 +537,6 @@ func (o *OTLPReceiver) convertSpan(rattr map[string]string, lib pcommon.Instrume
}
return true
})
for k, v := range attributes.ContainerTagFromAttributes(span.Meta) {
if _, ok := span.Meta[k]; !ok {
// overwrite only if it does not exist
setMetaOTLP(span, k, v)
}
if _, ok := ctags[k]; !ok {
ctags[k] = v
}
}
if _, ok := span.Meta["env"]; !ok {
if env := span.Meta[string(semconv.AttributeDeploymentEnvironment)]; env != "" {
setMetaOTLP(span, "env", traceutil.NormalizeTag(env))
Expand Down
Loading

0 comments on commit 25c8244

Please sign in to comment.