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

[SDK] Add tracer scope configurator #3137

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

psx95
Copy link
Contributor

@psx95 psx95 commented Nov 12, 2024

Re #2641

Adds scope configurator for Tracers.

Changes

  • Updates the Trace SDK to add support for TracerConfigurator as per the spec changes.
  • Adds a TracerConfig class that can be used to configure a tracer's behavior as per spec.

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
  • Unit tests have been added
  • Changes in public API reviewed

Copy link

netlify bot commented Nov 12, 2024

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit 7c90e1b
🔍 Latest deploy log https://app.netlify.com/sites/opentelemetry-cpp-api-docs/deploys/678551947d78660007be19cb

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.85%. Comparing base (d693e95) to head (7c90e1b).

Additional details and impacted files

Impacted file tree graph

@@            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              
Files with missing lines Coverage Δ
...etry/sdk/instrumentationscope/scope_configurator.h 100.00% <100.00%> (ø)
sdk/include/opentelemetry/sdk/trace/tracer.h 100.00% <ø> (ø)
...dk/include/opentelemetry/sdk/trace/tracer_config.h 100.00% <100.00%> (ø)
...k/include/opentelemetry/sdk/trace/tracer_context.h 100.00% <ø> (ø)
sdk/src/trace/tracer.cc 83.61% <100.00%> (+1.16%) ⬆️
sdk/src/trace/tracer_config.cc 100.00% <100.00%> (ø)
sdk/src/trace/tracer_context.cc 84.00% <100.00%> (+2.19%) ⬆️
sdk/src/trace/tracer_provider.cc 89.59% <100.00%> (+0.23%) ⬆️
sdk/src/trace/tracer_provider_factory.cc 92.69% <100.00%> (+3.03%) ⬆️

@psx95 psx95 force-pushed the add-scope-config branch 11 times, most recently from dd70641 to 0370722 Compare November 16, 2024 17:26
@psx95 psx95 changed the title Add scope config [WIP] Add scope config Nov 16, 2024
@psx95 psx95 force-pushed the add-scope-config branch 2 times, most recently from b82ea68 to f6ff444 Compare November 16, 2024 17:54
@psx95 psx95 changed the title [WIP] Add scope config [WIP] Add tracer scope configurator Nov 16, 2024
@psx95 psx95 force-pushed the add-scope-config branch 10 times, most recently from 93950bf to c77065e Compare November 18, 2024 20:02
@psx95 psx95 changed the title [WIP] Add tracer scope configurator [SDK] Add tracer scope configurator Nov 18, 2024
@psx95 psx95 marked this pull request as ready for review November 18, 2024 21:09
psx95 added 5 commits December 5, 2024 21:35
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.
@psx95 psx95 requested a review from marcalff December 7, 2024 00:19
@marcalff marcalff added the pr:please-review This PR is ready for review label Dec 16, 2024
@marcalff marcalff self-assigned this Dec 19, 2024
std::unique_ptr<IdGenerator> id_generator,
std::unique_ptr<instrumentationscope::ScopeConfigurator<TracerConfig>> tracer_configurator);

/* Series of creator methods with a single processor. */
Copy link
Member

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

Comment on lines +48 to +68
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(),
};
Copy link
Member

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));
Copy link
Member

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.

Copy link
Member

@marcalff marcalff left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:please-review This PR is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants