open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.1k stars 2.39k forks source link

[exporter/datadog] Missing custom resource attributes in datadog #36461

Closed dariogriffo closed 1 day ago

dariogriffo commented 2 days ago

Component(s)

exporter/datadog

What happened?

Description

When exporting metrics from a .net API to datadog via the collector, custom resource attributes, are not visible in datadog

Steps to Reproduce

Use the following code to export

using System.Diagnostics.Metrics;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;

var builder = WebApplication.CreateBuilder(args);
Meter m = new Meter("Meter");
var c = m.CreateCounter<int>("counter");
builder.Services.AddOpenTelemetry()
    .ConfigureResource(builder => builder
        .AddService(serviceName: "OTel.NET Getting Started")
        .AddAttributes(new Dictionary<string, object>
        {
            ["environment.name"] = "production",
            ["team.name"] = "backend"
        }))
    .WithMetrics(builder => builder
        .AddMeter(m.Name)
        .ConfigureResource(b=>b.AddAttributes(new Dictionary<string, object>
        {
            ["environment.name"] = "production",
            ["team.name"] = "backend"
        }))
        .AddConsoleExporter((exporterOptions, metricReaderOptions) =>
        {
            metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
        }).AddOtlpExporter()
    );
var app = builder.Build();

app.MapGet("/", () =>
{
    c.Add(1);
    return "Hello World!";
});

app.Run();

Resource of the attributes are present in the collector (attached image with environment and team.name attributes

IMG_20241119_213456_431

Expected Result

The 2 custom attributes set at resource level appear in datadog

Actual Result

The custom attributes won't appear in datadog. The metrics with service and version attributes appear

Collector version

0.114.0

Environment information

Environment

OS: (e.g., "Docker via debian bookworm")

OpenTelemetry Collector configuration

receivers:
  otlp:
    protocols:
      grpc:
      http:
processors:
  batch:
exporters:
  debug:
    verbosity: detailed
  otlphttp:
    endpoint: "http://seq:5341/ingest/otlp"
    tls:
      insecure: true
  otlp/aspire:
    endpoint: aspire:18889
    tls:
      insecure: true    
  datadog:
    api:
      site: MY_SITE
      key: MY_KEY
service:
  pipelines:
    logs:
      receivers: [ otlp ]
      exporters: [ otlphttp, otlp/aspire ]
      processors: [batch]      
    metrics:
        receivers: [ otlp ]
        exporters: [ datadog, otlp/aspire ]
  telemetry:
    logs:
      level: "debug"

Log output

Image attached

Additional context

No response

github-actions[bot] commented 2 days ago

Pinging code owners:

mackjmr commented 2 days ago

Hey @dariogriffo, did you set resource_attributes_as_tags (https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/datadogexporter/examples/collector.yaml#L260-L267) to true ?

dariogriffo commented 1 day ago

Resolved with the comment by @mackjmr