File tree 2 files changed +32
-7
lines changed
exporters/etw/include/opentelemetry/exporters/etw
2 files changed +32
-7
lines changed Original file line number Diff line number Diff line change 113
113
# define ETW_FIELD_SPAN_KIND " Kind" /* Span Kind */
114
114
# define ETW_FIELD_SPAN_LINKS " Links" /* Span Links array */
115
115
116
+ # define ETW_FIELD_SPAN_LINKS_TO_SPAN_ID " toSpanId" /* Span Links toSpanId */
117
+ # define ETW_FIELD_SPAN_LINKS_TO_TRACE_ID " toTraceId" /* Span Links toTraceId */
118
+
116
119
# define ETW_FIELD_PAYLOAD_NAME " Name" /* ETW Payload["Name"] */
117
120
118
121
/* Span option constants */
136
139
/* Log specific */
137
140
# define ETW_FIELD_LOG_BODY " body" /* Log body */
138
141
# define ETW_FIELD_LOG_SEVERITY_TEXT " severityText" /* Sev text */
139
- # define ETW_FIELD_LOG_SEVERITY_NUM " severityNumber" /* Sev num */
142
+ # define ETW_FIELD_LOG_SEVERITY_NUM " severityNumber" /* Sev num */
140
143
141
144
#endif
142
145
Original file line number Diff line number Diff line change @@ -212,19 +212,41 @@ class Tracer : public opentelemetry::trace::Tracer,
212
212
// Add `SpanLinks` attribute if the list is not empty
213
213
if (links.size ())
214
214
{
215
- size_t idx = 0 ;
215
+ bool first = true ;
216
216
std::string linksValue;
217
+
218
+ // reserve space for all the SpanLinks.
219
+ // A single SpanLink will be outptut as:
220
+ // [{"toSpanId":"9a43c801557f26b7","toTraceId":"ac6cd70ac4bb168a99cb7651b048d965"}]
221
+ // The second and above link output to string are 1 byte less than the first SpanLink.
222
+ const size_t kSingleSpanLinkSizeInBytes = 80 ;
223
+ linksValue.reserve (kSingleSpanLinkSizeInBytes +
224
+ (links.size () - 1 ) * (kSingleSpanLinkSizeInBytes - 1 ));
225
+ linksValue += " [" ;
226
+
217
227
links.ForEachKeyValue ([&](opentelemetry::trace::SpanContext ctx,
218
228
const opentelemetry::common::KeyValueIterable &) {
219
- if (!linksValue.empty ())
229
+ if (first)
230
+ {
231
+ first = false ;
232
+ linksValue += " {\" " ETW_FIELD_SPAN_LINKS_TO_SPAN_ID " \" :\" " ;
233
+ }
234
+ else
220
235
{
221
- linksValue += ' ,' ;
222
- linksValue += ToLowerBase16 (ctx.span_id ());
236
+ linksValue += " ,{\" " ETW_FIELD_SPAN_LINKS_TO_SPAN_ID " \" :\" " ;
223
237
}
224
- idx++;
238
+
239
+ linksValue += ToLowerBase16 (ctx.span_id ());
240
+ linksValue += " \" ,\" " ETW_FIELD_SPAN_LINKS_TO_TRACE_ID " \" :\" " ;
241
+ linksValue += ToLowerBase16 (ctx.trace_id ());
242
+ linksValue += " \" }" ;
243
+
225
244
return true ;
226
245
});
227
- attributes[ETW_FIELD_SPAN_LINKS] = linksValue;
246
+
247
+ linksValue += " ]" ;
248
+
249
+ attributes[ETW_FIELD_SPAN_LINKS] = std::move (linksValue);
228
250
}
229
251
}
230
252
You can’t perform that action at this time.
0 commit comments