Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbbr committed Apr 4, 2022
1 parent 99e7ece commit a169cfe
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 134 deletions.
89 changes: 5 additions & 84 deletions pkg/trace/api/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"sync"
"time"

"github.com/DataDog/datadog-agent/pkg/otlp/model/attributes"
"github.com/DataDog/datadog-agent/pkg/trace/api/apiutil"
"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/info"
Expand Down Expand Up @@ -357,7 +358,6 @@ func convertSpan(rattr map[string]string, lib pdata.InstrumentationLibrary, in p
if in.Events().Len() > 0 {
span.Meta["events"] = marshalEvents(in.Events())
}
var ctags strings.Builder // collect container tags from attributes
in.Attributes().Range(func(k string, v pdata.AttributeValue) bool {
switch v.Type() {
case pdata.AttributeValueTypeDouble:
Expand All @@ -378,19 +378,10 @@ func convertSpan(rattr map[string]string, lib pdata.InstrumentationLibrary, in p
span.Meta[k] = v.AsString()
}
}
if containerTagsAttributes[k] {
// attribute matching container tag found
if ctags.Len() > 0 {
ctags.WriteByte(',')
}
ctags.WriteString(conventionsMapping[k])
ctags.WriteByte(':')
ctags.WriteString(v.AsString())
}
return true
})
if ctags.Len() > 0 {
span.Meta[tagContainersTags] = ctags.String()
if ctags := attributes.ContainerTagFromAttributes(span.Meta); ctags != "" {
span.Meta[tagContainersTags] = ctags
}
if _, ok := span.Meta["env"]; !ok {
if env := span.Meta[string(semconv.AttributeDeploymentEnvironment)]; env != "" {
Expand All @@ -401,10 +392,10 @@ func convertSpan(rattr map[string]string, lib pdata.InstrumentationLibrary, in p
span.Meta["trace_state"] = string(in.TraceState())
}
if lib.Name() != "" {
span.Meta["otel.library.name"] = lib.Name()
span.Meta[semconv.OtelLibraryName] = lib.Name()
}
if lib.Version() != "" {
span.Meta["otel.library.version"] = lib.Version()
span.Meta[semconv.OtelLibraryVersion] = lib.Version()
}
span.Meta["otel.status_code"] = in.Status().Code().String()
status2Error(in.Status(), in.Events(), span)
Expand Down Expand Up @@ -539,73 +530,3 @@ func spanKindName(k pdata.SpanKind) string {
}
return name
}

// conventionsMappings defines the mapping between OpenTelemetry semantic conventions
// and Datadog Agent conventions
var conventionsMapping = map[string]string{
// Datadog conventions
// https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/
semconv.AttributeDeploymentEnvironment: "env",
semconv.AttributeServiceName: "service",
semconv.AttributeServiceVersion: "version",

// Containers
semconv.AttributeContainerID: "container_id",
semconv.AttributeContainerName: "container_name",
semconv.AttributeContainerImageName: "image_name",
semconv.AttributeContainerImageTag: "image_tag",

// Cloud conventions
// https://www.datadoghq.com/blog/tagging-best-practices/
semconv.AttributeCloudProvider: "cloud_provider",
semconv.AttributeCloudRegion: "region",
semconv.AttributeCloudAvailabilityZone: "zone",

// ECS conventions
// https://github.com/DataDog/datadog-agent/blob/e081bed/pkg/tagger/collectors/ecs_extract.go
semconv.AttributeAWSECSTaskFamily: "task_family",
semconv.AttributeAWSECSTaskARN: "task_arn",
semconv.AttributeAWSECSClusterARN: "ecs_cluster_name",
semconv.AttributeAWSECSTaskRevision: "task_version",
semconv.AttributeAWSECSContainerARN: "ecs_container_name",

// Kubernetes resource name (via semantic conventions)
// https://github.com/DataDog/datadog-agent/blob/e081bed/pkg/util/kubernetes/const.go
semconv.AttributeK8SContainerName: "kube_container_name",
semconv.AttributeK8SClusterName: "kube_cluster_name",
semconv.AttributeK8SDeploymentName: "kube_deployment",
semconv.AttributeK8SReplicaSetName: "kube_replica_set",
semconv.AttributeK8SStatefulSetName: "kube_stateful_set",
semconv.AttributeK8SDaemonSetName: "kube_daemon_set",
semconv.AttributeK8SJobName: "kube_job",
semconv.AttributeK8SCronJobName: "kube_cronjob",
semconv.AttributeK8SNamespaceName: "kube_namespace",
semconv.AttributeK8SPodName: "pod_name",
}

// containerTagsAttributes lists attribute names that can be converted to Datadog tags
// using the conventionsMapping map.
var containerTagsAttributes = map[string]bool{
semconv.AttributeContainerID: true,
semconv.AttributeContainerName: true,
semconv.AttributeContainerImageName: true,
semconv.AttributeContainerImageTag: true,
semconv.AttributeK8SContainerName: true,
semconv.AttributeK8SClusterName: true,
semconv.AttributeK8SDeploymentName: true,
semconv.AttributeK8SReplicaSetName: true,
semconv.AttributeK8SStatefulSetName: true,
semconv.AttributeK8SDaemonSetName: true,
semconv.AttributeK8SJobName: true,
semconv.AttributeK8SCronJobName: true,
semconv.AttributeK8SNamespaceName: true,
semconv.AttributeK8SPodName: true,
semconv.AttributeCloudProvider: true,
semconv.AttributeCloudRegion: true,
semconv.AttributeCloudAvailabilityZone: true,
semconv.AttributeAWSECSTaskFamily: true,
semconv.AttributeAWSECSTaskARN: true,
semconv.AttributeAWSECSClusterARN: true,
semconv.AttributeAWSECSTaskRevision: true,
semconv.AttributeAWSECSContainerARN: true,
}
96 changes: 50 additions & 46 deletions pkg/trace/api/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,20 @@ func TestOTLPConvertSpan(t *testing.T) {
Duration: 200000000,
Error: 1,
Meta: map[string]string{
"name": "john",
"otel.trace_id": "72df520af2bde7a5240031ead750e5f3",
"env": "staging",
"instrumentation_library.name": "ddtracer",
"instrumentation_library.version": "v2",
"service.name": "pylons",
"service.version": "v1.2.3",
"trace_state": "state",
"version": "v1.2.3",
"events": `[{"time_unix_nano":123,"name":"boom","attributes":{"key":"Out of memory","accuracy":"2.4"},"dropped_attributes_count":2},{"time_unix_nano":456,"name":"exception","attributes":{"exception.message":"Out of memory","exception.type":"mem","exception.stacktrace":"1/2/3"},"dropped_attributes_count":2}]`,
"error.msg": "Out of memory",
"error.type": "mem",
"error.stack": "1/2/3",
"name": "john",
"otel.trace_id": "72df520af2bde7a5240031ead750e5f3",
"env": "staging",
"otel.status_code": "STATUS_CODE_ERROR",
"otel.library.name": "ddtracer",
"otel.library.version": "v2",
"service.name": "pylons",
"service.version": "v1.2.3",
"trace_state": "state",
"version": "v1.2.3",
"events": `[{"time_unix_nano":123,"name":"boom","attributes":{"key":"Out of memory","accuracy":"2.4"},"dropped_attributes_count":2},{"time_unix_nano":456,"name":"exception","attributes":{"exception.message":"Out of memory","exception.type":"mem","exception.stacktrace":"1/2/3"},"dropped_attributes_count":2}]`,
"error.msg": "Out of memory",
"error.type": "mem",
"error.stack": "1/2/3",
},
Metrics: map[string]float64{
"approx": 1.2,
Expand Down Expand Up @@ -488,22 +489,23 @@ func TestOTLPConvertSpan(t *testing.T) {
Duration: 200000000,
Error: 1,
Meta: map[string]string{
"name": "john",
"env": "prod",
"deployment.environment": "prod",
"instrumentation_library.name": "ddtracer",
"otel.trace_id": "72df520af2bde7a5240031ead750e5f3",
"instrumentation_library.version": "v2",
"service.version": "v1.2.3",
"trace_state": "state",
"version": "v1.2.3",
"events": "[{\"time_unix_nano\":123,\"name\":\"boom\",\"attributes\":{\"message\":\"Out of memory\",\"accuracy\":\"2.4\"},\"dropped_attributes_count\":2},{\"time_unix_nano\":456,\"name\":\"exception\",\"attributes\":{\"exception.message\":\"Out of memory\",\"exception.type\":\"mem\",\"exception.stacktrace\":\"1/2/3\"},\"dropped_attributes_count\":2}]",
"error.msg": "Out of memory",
"error.type": "mem",
"error.stack": "1/2/3",
"http.method": "GET",
"http.route": "/path",
"peer.service": "userbase",
"name": "john",
"env": "prod",
"deployment.environment": "prod",
"otel.trace_id": "72df520af2bde7a5240031ead750e5f3",
"otel.status_code": "STATUS_CODE_ERROR",
"otel.library.name": "ddtracer",
"otel.library.version": "v2",
"service.version": "v1.2.3",
"trace_state": "state",
"version": "v1.2.3",
"events": "[{\"time_unix_nano\":123,\"name\":\"boom\",\"attributes\":{\"message\":\"Out of memory\",\"accuracy\":\"2.4\"},\"dropped_attributes_count\":2},{\"time_unix_nano\":456,\"name\":\"exception\",\"attributes\":{\"exception.message\":\"Out of memory\",\"exception.type\":\"mem\",\"exception.stacktrace\":\"1/2/3\"},\"dropped_attributes_count\":2}]",
"error.msg": "Out of memory",
"error.type": "mem",
"error.stack": "1/2/3",
"http.method": "GET",
"http.route": "/path",
"peer.service": "userbase",
},
Metrics: map[string]float64{
"approx": 1.2,
Expand Down Expand Up @@ -569,21 +571,22 @@ func TestOTLPConvertSpan(t *testing.T) {
Duration: 200000000,
Error: 1,
Meta: map[string]string{
"name": "john",
"env": "staging",
"instrumentation_library.name": "ddtracer",
"instrumentation_library.version": "v2",
"service.name": "pylons",
"service.version": "v1.2.3",
"trace_state": "state",
"version": "v1.2.3",
"otel.trace_id": "72df520af2bde7a5240031ead750e5f3",
"events": "[{\"time_unix_nano\":123,\"name\":\"boom\",\"attributes\":{\"message\":\"Out of memory\",\"accuracy\":\"2.4\"},\"dropped_attributes_count\":2},{\"time_unix_nano\":456,\"name\":\"exception\",\"attributes\":{\"exception.message\":\"Out of memory\",\"exception.type\":\"mem\",\"exception.stacktrace\":\"1/2/3\"},\"dropped_attributes_count\":2}]",
"error.msg": "Out of memory",
"error.type": "mem",
"error.stack": "1/2/3",
"http.method": "GET",
"http.route": "/path",
"name": "john",
"env": "staging",
"otel.status_code": "STATUS_CODE_ERROR",
"otel.library.name": "ddtracer",
"otel.library.version": "v2",
"service.name": "pylons",
"service.version": "v1.2.3",
"trace_state": "state",
"version": "v1.2.3",
"otel.trace_id": "72df520af2bde7a5240031ead750e5f3",
"events": "[{\"time_unix_nano\":123,\"name\":\"boom\",\"attributes\":{\"message\":\"Out of memory\",\"accuracy\":\"2.4\"},\"dropped_attributes_count\":2},{\"time_unix_nano\":456,\"name\":\"exception\",\"attributes\":{\"exception.message\":\"Out of memory\",\"exception.type\":\"mem\",\"exception.stacktrace\":\"1/2/3\"},\"dropped_attributes_count\":2}]",
"error.msg": "Out of memory",
"error.type": "mem",
"error.stack": "1/2/3",
"http.method": "GET",
"http.route": "/path",
},
Metrics: map[string]float64{
"approx": 1.2,
Expand Down Expand Up @@ -631,8 +634,9 @@ func TestOTLPConvertSpan(t *testing.T) {
semconv.AttributeK8SContainerName: "k8s-container",
"http.method": "GET",
"http.route": "/path",
"instrumentation_library.name": "ddtracer",
"instrumentation_library.version": "v2",
"otel.status_code": "STATUS_CODE_UNSET",
"otel.library.name": "ddtracer",
"otel.library.version": "v2",
"name": "john",
"otel.trace_id": "72df520af2bde7a5240031ead750e5f3",
},
Expand Down
12 changes: 8 additions & 4 deletions pkg/trace/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.17

require (
github.com/DataDog/datadog-agent/pkg/obfuscate v0.34.0
github.com/DataDog/datadog-agent/pkg/otlp/model v0.34.0
github.com/DataDog/datadog-go/v5 v5.1.0
github.com/DataDog/sketches-go v1.2.1
github.com/Microsoft/go-winio v0.5.1
Expand All @@ -12,13 +13,13 @@ require (
github.com/google/gofuzz v1.2.0
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil/v3 v3.22.2
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.7.1
github.com/tinylib/msgp v1.1.6
github.com/vmihailenco/msgpack/v4 v4.3.12
go.opentelemetry.io/collector/model v0.44.0
go.opentelemetry.io/collector/model v0.47.0
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
google.golang.org/grpc v1.44.0
google.golang.org/grpc v1.45.0
k8s.io/apimachinery v0.21.5
)

Expand All @@ -45,4 +46,7 @@ require (
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

replace github.com/DataDog/datadog-agent/pkg/obfuscate => ../obfuscate
replace (
github.com/DataDog/datadog-agent/pkg/obfuscate => ../obfuscate
github.com/DataDog/datadog-agent/pkg/otlp/model => ../otlp/model
)
6 changes: 6 additions & 0 deletions pkg/trace/go.sum

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

0 comments on commit a169cfe

Please sign in to comment.