@@ -5,6 +5,7 @@ package datadogextension // import "github.com/open-telemetry/opentelemetry-coll
55
66import (
77 "context"
8+ "sort"
89 "sync"
910 "time"
1011
@@ -16,6 +17,7 @@ import (
1617 "go.opentelemetry.io/collector/confmap"
1718 "go.opentelemetry.io/collector/extension"
1819 "go.opentelemetry.io/collector/extension/extensioncapabilities"
20+ "go.opentelemetry.io/collector/pdata/pcommon"
1921 "go.opentelemetry.io/collector/service"
2022 "go.opentelemetry.io/collector/service/hostcapabilities"
2123 "go.uber.org/zap"
@@ -49,11 +51,12 @@ type configs struct {
4951}
5052
5153type info struct {
52- host source.Source
53- hostnameSource string
54- uuid string
55- build component.BuildInfo
56- modules service.ModuleInfos
54+ host source.Source
55+ hostnameSource string
56+ uuid string
57+ build component.BuildInfo
58+ modules service.ModuleInfos
59+ resourceAttributes []string
5760}
5861
5962type payloadSender struct {
@@ -120,6 +123,9 @@ func (e *datadogExtension) NotifyConfig(_ context.Context, conf *confmap.Conf) e
120123 buildInfo ,
121124 )
122125
126+ // Populate resource attributes collected from TelemetrySettings.Resource
127+ otelCollectorPayload .CollectorResourceAttributes = e .info .resourceAttributes
128+
123129 // Populate the full list of components available in the collector build
124130 moduleInfoJSON , err := componentchecker .PopulateFullComponentsJSON (e .info .modules , e .configs .collector )
125131 if err != nil {
@@ -313,6 +319,23 @@ func newExtension(
313319 logComponent := agentcomponents .NewLogComponent (set .TelemetrySettings )
314320 serializer := agentcomponents .NewSerializerComponent (configComponent , logComponent , host .Identifier )
315321
322+ // Collect resource attributes from TelemetrySettings.Resource
323+ // Format: ["key:value", ...]
324+ resourceMap := make (map [string ]string , set .Resource .Attributes ().Len ())
325+ set .Resource .Attributes ().Range (func (k string , v pcommon.Value ) bool {
326+ resourceMap [k ] = v .Str ()
327+ return true
328+ })
329+ keys := make ([]string , 0 , len (resourceMap ))
330+ for k := range resourceMap {
331+ keys = append (keys , k )
332+ }
333+ sort .Strings (keys )
334+ resourceList := make ([]string , 0 , len (keys ))
335+ for _ , k := range keys {
336+ resourceList = append (resourceList , k + ":" + resourceMap [k ])
337+ }
338+
316339 // configure payloadSender struct
317340 ctxWithCancel , cancel := context .WithCancel (ctx )
318341 ticker := time .NewTicker (payloadSendingInterval )
@@ -323,11 +346,12 @@ func newExtension(
323346 logger : set .Logger ,
324347 serializer : serializer ,
325348 info : & info {
326- host : host ,
327- hostnameSource : hostnameSource ,
328- uuid : uuidProvider .NewString (),
329- build : set .BuildInfo ,
330- modules : service.ModuleInfos {}, // moduleInfos will be populated in Start()
349+ host : host ,
350+ hostnameSource : hostnameSource ,
351+ uuid : uuidProvider .NewString (),
352+ build : set .BuildInfo ,
353+ modules : service.ModuleInfos {}, // moduleInfos will be populated in Start()
354+ resourceAttributes : resourceList ,
331355 },
332356 payloadSender : & payloadSender {
333357 ctx : ctxWithCancel ,
0 commit comments