Skip to content

Commit

Permalink
[opentracing-shim] Add check for sampled context (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
chusitoo authored Oct 30, 2023
1 parent 17da6d8 commit 758687c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
21 changes: 14 additions & 7 deletions opentracing-shim/src/tracer_shim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,20 @@ opentracing::expected<std::unique_ptr<opentracing::SpanContext>> TracerShim::ext
auto span_context = opentelemetry::trace::GetSpan(context)->GetContext();
auto baggage = opentelemetry::baggage::GetBaggage(context);

// If the extracted SpanContext is invalid AND the extracted Baggage is empty,
// this operation MUST return a null value, and otherwise it MUST return a
// SpanContext Shim instance with the extracted values.
SpanContextShim *context_shim = (!span_context.IsValid() && utils::isBaggageEmpty(baggage))
? nullptr
: new (std::nothrow) SpanContextShim(span_context, baggage);

// The operation MUST return a `SpanContext` Shim instance with the extracted values if any of
// these conditions are met:
// * `SpanContext` is valid.
// * `SpanContext` is sampled.
// * `SpanContext` contains non-empty extracted `Baggage`.
// Otherwise, the operation MUST return null or empty value.
SpanContextShim *context_shim =
(!span_context.IsValid() && !span_context.IsSampled() && utils::isBaggageEmpty(baggage))
? nullptr
: new (std::nothrow) SpanContextShim(span_context, baggage);

// Note: Invalid but sampled `SpanContext` instances are returned as a way to support
// jaeger-debug-id headers (https://github.com/jaegertracing/jaeger-client-java#via-http-headers)
// which are used to force propagation of debug information.
return opentracing::make_expected(std::unique_ptr<opentracing::SpanContext>(context_shim));
}

Expand Down
1 change: 1 addition & 0 deletions opentracing-shim/test/tracer_shim_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ TEST_F(TracerShimTest, ExtractOnlyBaggage)
auto span_context_shim = static_cast<shim::SpanContextShim *>(span_context.value().get());
ASSERT_TRUE(span_context_shim != nullptr);
ASSERT_FALSE(span_context_shim->context().IsValid());
ASSERT_FALSE(span_context_shim->context().IsSampled());
ASSERT_FALSE(shim::utils::isBaggageEmpty(span_context_shim->baggage()));

std::string value;
Expand Down

2 comments on commit 758687c

@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 api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 758687c Previous: 17da6d8 Ratio
BM_SpinLockThrashing/1/process_time/real_time 0.6818230946858724 ms/iter 0.16735544744527564 ms/iter 4.07
BM_NaiveSpinLockThrashing/1/process_time/real_time 0.7478619053353012 ms/iter 0.13336841133637542 ms/iter 5.61
BM_NaiveSpinLockThrashing/2/process_time/real_time 0.6769612778064816 ms/iter 0.25272197551555464 ms/iter 2.68
BM_ThreadYieldSpinLockThrashing/1/process_time/real_time 21.539608637491863 ms/iter 7.0999860763549805 ms/iter 3.03

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

@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: 758687c Previous: 17da6d8 Ratio
BM_LockFreeBuffer/1 701532.1271639344 ns/iter 348607.98604060523 ns/iter 2.01

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

Please sign in to comment.