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

logs: incorrect `service.name` transformation #356

Open sudomateo opened 2 weeks ago

sudomateo commented 2 weeks ago

When the service.name attribute is set as a resource attribute or as an attribute on the log, the Datadog user interface shows a JSON object instead of the name of the service.

This issue actually spawns a larger discussion about how the transform function is meant to work. Specifically, the transform function retrieves the value for service, among others, from either resource attributes or attributes on the log. It then uses that service value to set the Service field on the datadogV2.HTTPLogItem. Since values can be set from both resource attributes or attributes on the log, it's not clear which method operators should be using in their code. Perhaps this should be broken out into a separate issue for further discussion. Either way, I'm bringing it up here because it was a bit confusing when reading the code.

https://github.com/DataDog/opentelemetry-mapping-go/blob/6e80d7ed923d9daa6a1245c7bc4afff2983fbbe1/pkg/otlp/logs/transform.go#L78-L80

Here's the transform processor I used to set the service.name attribute on the log.

processors:
  transform:
    log_statements:
      - context: log
        statements:
          - set(attributes["service.name"], "sudomateo")
          - set(attributes["ddtags"], "source:sudomateo")

Notice how this appears incorrectly as a JSON object in the Datadog user interface. With this incorrect behavior I cannot use service:sudomateo to filter logs.

Screenshot 2024-07-02 at 19 12 57 Screenshot 2024-07-02 at 19 12 03