Skip to content

Commit

Permalink
Fix empty tracestate header propagation (#1373)
Browse files Browse the repository at this point in the history
  • Loading branch information
yzsolt authored May 5, 2022
1 parent 59a48c1 commit d3c4200
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ class HttpTraceContext : public opentelemetry::context::propagation::TextMapProp
nostd::span<char, 2>{&trace_parent[kTraceIdSize + kSpanIdSize + 5], 2});

carrier.Set(kTraceParent, nostd::string_view(trace_parent, sizeof(trace_parent)));
carrier.Set(kTraceState, span_context.trace_state()->ToHeader());
const auto trace_state = span_context.trace_state()->ToHeader();
if (!trace_state.empty())
{
carrier.Set(kTraceState, trace_state);
}
}

static SpanContext ExtractContextFromTraceHeaders(nostd::string_view trace_parent,
Expand Down
8 changes: 4 additions & 4 deletions api/test/trace/propagation/http_text_format_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ TEST(TextMapPropagatorTest, NoSendEmptyTraceState)
context::Context ctx2 = format.Extract(carrier, ctx1);
TextMapCarrierTest carrier2;
format.Inject(carrier2, ctx2);
EXPECT_TRUE(carrier.headers_.count("traceparent") > 0);
EXPECT_FALSE(carrier.headers_.count("tracestate") > 0);
EXPECT_TRUE(carrier2.headers_.count("traceparent") > 0);
EXPECT_FALSE(carrier2.headers_.count("tracestate") > 0);
}

TEST(TextMapPropagatorTest, PropogateTraceState)
Expand All @@ -72,8 +72,8 @@ TEST(TextMapPropagatorTest, PropogateTraceState)
TextMapCarrierTest carrier2;
format.Inject(carrier2, ctx2);

EXPECT_TRUE(carrier.headers_.count("traceparent") > 0);
EXPECT_TRUE(carrier.headers_.count("tracestate") > 0);
EXPECT_TRUE(carrier2.headers_.count("traceparent") > 0);
EXPECT_TRUE(carrier2.headers_.count("tracestate") > 0);
EXPECT_EQ(carrier2.headers_["tracestate"], "congo=t61rcWkgMzE");
}

Expand Down

1 comment on commit d3c4200

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: d3c4200 Previous: 59a48c1 Ratio
BM_BaselineBuffer/1 9711422.92022705 ns/iter 492319.9046407952 ns/iter 19.73
BM_LockFreeBuffer/1 826029.0622711182 ns/iter 356073.58636185096 ns/iter 2.32

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.