Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPORTER] Fix the format of SpanLink for ETW #3054

Merged
merged 6 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@
# define ETW_FIELD_SPAN_KIND "Kind" /* Span Kind */
# define ETW_FIELD_SPAN_LINKS "Links" /* Span Links array */

# define ETW_FIELD_SPAN_LINKS_TO_SPAN_ID "toSpanId" /* Span Links toSpanId */
# define ETW_FIELD_SPAN_LINKS_TO_TRACE_ID "toTraceId" /* Span Links toTraceId */

# define ETW_FIELD_PAYLOAD_NAME "Name" /* ETW Payload["Name"] */

/* Span option constants */
Expand All @@ -136,7 +139,7 @@
/* Log specific */
# define ETW_FIELD_LOG_BODY "body" /* Log body */
# define ETW_FIELD_LOG_SEVERITY_TEXT "severityText" /* Sev text */
# define ETW_FIELD_LOG_SEVERITY_NUM "severityNumber" /* Sev num */
# define ETW_FIELD_LOG_SEVERITY_NUM "severityNumber" /* Sev num */

#endif

Expand Down
29 changes: 25 additions & 4 deletions exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,38 @@ class Tracer : public opentelemetry::trace::Tracer,
{
size_t idx = 0;
std::string linksValue;

// reserve space for all the SpanLinks.
// A single SpanLink will be outptut as:
// [{"toSpanId":"9a43c801557f26b7","toTraceId":"ac6cd70ac4bb168a99cb7651b048d965"}]
// The second and above link output to string are 1 byte less than the first link.
const size_t linkValueSize = 80;
lalitb marked this conversation as resolved.
Show resolved Hide resolved
linksValue.reserve(linkValueSize + (links.size() - 1) * (linkValueSize - 1));
linksValue += "[";

links.ForEachKeyValue([&](opentelemetry::trace::SpanContext ctx,
const opentelemetry::common::KeyValueIterable &) {
if (!linksValue.empty())
if (idx == 0)
ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved
{
linksValue += "{\"" ETW_FIELD_SPAN_LINKS_TO_SPAN_ID "\":\"";
}
else
{
linksValue += ',';
linksValue += ToLowerBase16(ctx.span_id());
linksValue += ",{\"" ETW_FIELD_SPAN_LINKS_TO_SPAN_ID "\":\"";
}

linksValue += ToLowerBase16(ctx.span_id());
linksValue += "\",\"" ETW_FIELD_SPAN_LINKS_TO_TRACE_ID "\":\"";
linksValue += ToLowerBase16(ctx.trace_id());
linksValue += "\"}";

idx++;
return true;
});
attributes[ETW_FIELD_SPAN_LINKS] = linksValue;

linksValue += "]";

attributes[ETW_FIELD_SPAN_LINKS] = std::move(linksValue);
}
}

Expand Down
Loading