DataDog / opentelemetry-mapping-go

Go modules that implement OpenTelemetry-to-Datadog mapping for all telemetry signals
Apache License 2.0
13 stars 6 forks source link

[pkg/inframetadata] Improve warning when host-identifying attributes are missing #314

Closed mx-psi closed 3 months ago

mx-psi commented 3 months ago

What does this PR do?

Uses AsRaw for printing resource attributes and links reference page on mapping OTLP resource attributes to hostnames.

Motivation

pcommon.Map doesn't have a very sensible formatting. With the following sample program:

package main

import (
    "go.opentelemetry.io/collector/pdata/pcommon"
    "go.uber.org/zap"
)

func main() {
    logger := zap.NewExample() // or NewProduction, or NewDevelopment
    defer logger.Sync()

    m := pcommon.NewMap()
    if err := m.FromRaw(map[string]any{"key": "value"}); err != nil {
        panic(err)
    }

    logger.Info("Testing logging of pcommon.Map", zap.Any("map", m), zap.Any("raw map", m.AsRaw()))
}

We can see the following output:

❯ go run main.go
{"level":"info","msg":"Testing logging of pcommon.Map","map":{},"raw map":{"key":"value"}}

Where map is shown as empty, when it isn't. Casting to a map with AsRaw fixes the issue