-
Notifications
You must be signed in to change notification settings - Fork 446
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
[SDK] Add tracer scope configurator #3137
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
6e15bc3
to
75d84d8
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3137 +/- ##
==========================================
+ Coverage 87.73% 87.85% +0.12%
==========================================
Files 198 201 +3
Lines 6258 6316 +58
==========================================
+ Hits 5490 5548 +58
Misses 768 768
|
dd70641
to
0370722
Compare
b82ea68
to
f6ff444
Compare
93950bf
to
c77065e
Compare
2329279
to
2f1ee38
Compare
db05adc
to
31c73a3
Compare
Converting ScopeConfigurator from type alias to a dedicated class allows control over how it is initialized. This commits makes it so that ScopeConfigurator can only be initialized using the inner Builder class. This will prevent future confusion on how to initialize ScopeConfigurators.
std::unique_ptr<IdGenerator> id_generator, | ||
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator); | ||
|
||
/* Series of creator methods with a single processor. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with a vector of processors
const std::array<instrumentation_scope::InstrumentationScope *, 5> instrumentation_scopes = { | ||
std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_1")).get(), | ||
std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_2", "1.0")).get(), | ||
std::move(instrumentation_scope::InstrumentationScope::Create( | ||
"test_scope_3", | ||
"0", | ||
"https://opentelemetry.io/schemas/v1.18.0")) | ||
.get(), | ||
std::move(instrumentation_scope::InstrumentationScope::Create( | ||
"test_scope_3", | ||
"0", | ||
"https://opentelemetry.io/schemas/v1.18.0", | ||
{attr1})) | ||
.get(), | ||
std::move(instrumentation_scope::InstrumentationScope::Create( | ||
"test_scope_4", | ||
"0", | ||
"https://opentelemetry.io/schemas/v1.18.0", | ||
{attr1, attr2, attr3})) | ||
.get(), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This construct is a problem.
Either this is static test data, where the instrumentation_scopes
array is initialized with data, not code.
Ot it is constructed with code, with statements adding elements in the array.
As written, this will be very challenging to debug and interpret stack traces, should it fail at runtime.
// evaluating other condition | ||
const auto span_foo_scope_with_version_2 = tracer_foo_scope_with_version_2->StartSpan("span 1"); | ||
auto &span_foo_scope_with_version_ref_2 = *span_foo_scope_with_version_2.get(); | ||
EXPECT_EQ(typeid(span_foo_scope_with_version_ref_2), typeid(trace_api::NoopSpan)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible alternative to using OPENTELEMETRY_RTTI_ENABLED, not tested, to investigate:
- Create a noop_span using NoopTracerProvider::GetTracer() and NoopTracer::StartSpan
- Compare the pointer to the span object with the noop span.
This relies on the fact that noop spans are always the same object, per:
// Don't allocate a no-op span for every StartSpan call, but use a static
// singleton for this case.
static nostd::shared_ptr<trace::Span> noop_span(new trace::NoopSpan{this->shared_from_this()});
return noop_span;
Alternate possibility:
- check for IsRecordable(), should be false for noop span and true for real spans.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch, this is making good progress.
See another round comments on the code and tests.
Re #2641
Adds scope configurator for Tracers.
Changes
Some optional, good-to-have convenience functions were recommended by the spec to accommodate common use-cases - these have not been added in this PR.
See the TracerConfigurator spec for these recommendations. They should be added in a future PR.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes