@@ -45,14 +45,16 @@ namespace NWilson {
4545 TMonotonic ExpirationTimestamp;
4646 };
4747
48- TBatch (ui64 maxSpansInBatch, ui64 maxBytesInBatch, TString serviceName )
48+ TBatch (ui64 maxSpansInBatch, ui64 maxBytesInBatch, const TMap< TString, TString>& attributes )
4949 : MaxSpansInBatch(maxSpansInBatch)
5050 , MaxBytesInBatch(maxBytesInBatch)
5151 {
5252 auto *rspan = Request.add_resource_spans ();
53- auto *serviceNameAttr = rspan->mutable_resource ()->add_attributes ();
54- serviceNameAttr->set_key (" service.name" );
55- serviceNameAttr->mutable_value ()->set_string_value (std::move (serviceName));
53+ for (const auto & [key, value] : attributes) {
54+ auto *attr = rspan->mutable_resource ()->add_attributes ();
55+ attr->set_key (key);
56+ attr->mutable_value ()->set_string_value (value);
57+ }
5658 ScopeSpans = rspan->add_scope_spans ();
5759 }
5860
@@ -107,7 +109,7 @@ namespace NWilson {
107109 bool WakeupScheduled = false ;
108110
109111 TString CollectorUrl;
110- TString ServiceName ;
112+ const TMap< TString, TString> SpanAttributes ;
111113 TMap<TString, TString> Headers;
112114
113115 TRegisterMonPageCallback RegisterMonPage;
@@ -147,11 +149,11 @@ namespace NWilson {
147149 , MaxSpanTimeInQueue(TDuration::Seconds(params.SpanExportTimeoutSeconds))
148150 , MaxExportInflight(params.MaxExportRequestsInflight)
149151 , CollectorUrl(std::move(params.CollectorUrl))
150- , ServiceName(std::move (params.ServiceName))
152+ , SpanAttributes(GetSpanAttributes (params.ServiceName))
151153 , Headers(params.Headers)
152154 , RegisterMonPage(params.RegisterMonPage)
153155 , GrpcSigner(std::move(params.GrpcSigner))
154- , CurrentBatch(MaxSpansInBatch, MaxBytesInBatch, ServiceName )
156+ , CurrentBatch(MaxSpansInBatch, MaxBytesInBatch, SpanAttributes )
155157 , DroppedSpansCounter(params.Counters ? params.Counters->GetCounter (" WilsonUploaderDroppedSpans" , true ) : MakeIntrusive<NMonitoring::TCounterForPtr>(true ))
156158 , SentSpansCounter(params.Counters ? params.Counters->GetCounter (" WilsonUploaderSentSpans" , true ) : MakeIntrusive<NMonitoring::TCounterForPtr>(true ))
157159 , SentBytesCounter(params.Counters ? params.Counters->GetCounter (" WilsonUploaderSentBytes" , true ) : MakeIntrusive<NMonitoring::TCounterForPtr>(true ))
@@ -165,6 +167,15 @@ namespace NWilson {
165167
166168 static constexpr char ActorName[] = " WILSON_UPLOADER_ACTOR" ;
167169
170+ static TMap<TString, TString> GetSpanAttributes (const TString& serviceName) {
171+ TMap<TString, TString> attributes;
172+ attributes[" service.name" ] = serviceName;
173+ if (TString podUid = getenv (" POD_UID" )) {
174+ attributes[" k8s.pod.uid" ] = podUid;
175+ }
176+ return attributes;
177+ }
178+
168179 void Bootstrap () {
169180 Become (&TThis::StateWork);
170181
@@ -265,7 +276,7 @@ namespace NWilson {
265276 return ;
266277 }
267278 BatchQueue.push (std::move (CurrentBatch).Complete ());
268- CurrentBatch = TBatch (MaxSpansInBatch, MaxBytesInBatch, ServiceName );
279+ CurrentBatch = TBatch (MaxSpansInBatch, MaxBytesInBatch, SpanAttributes );
269280 }
270281
271282 void TryToSend () {
@@ -462,7 +473,10 @@ namespace NWilson {
462473 str << " MaxSpanTimeInQueue# " << MaxSpanTimeInQueue << ' \n ' ;
463474 str << " MaxExportInflight# " << MaxExportInflight << ' \n ' ;
464475 str << " CollectorUrl# " << CollectorUrl << ' \n ' ;
465- str << " ServiceName# " << ServiceName << ' \n ' ;
476+ str << " SpanAttributes# " << ' \n ' ;
477+ for (const auto & [key, value] : SpanAttributes) {
478+ str << ' \t ' << key << " : " << value << ' \n ' ;
479+ }
466480 str << " Headers# " << ' \n ' ;
467481 for (const auto & [key, value] : Headers) {
468482 str << ' \t ' << key << " : " << value << ' \n ' ;
0 commit comments