open-telemetry / open-telemetry/opentelemetry-cpp
Please add default constructor and move constructor/assignment op to Scope class
@lalitb is already working on this.
Since Apr 11, 2022.
- Dominant language
- C++
- Stars
- 1.4k
- Forks
- 632
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 75
Description
Is your feature request related to a problem?
I have event loop which gets objects from a queue and processes them. I want to create Span in this loop and set is as active span. Some of these objects are for health checks, and I want to exclude them from telemetry. Span objects are stored in nostd::shared_ptr, so I can declare variable first and then conditionally assign value to it. However I cannot do the same with Scope object, declaration and initialization must happen at the same time.
Describe the solution you'd like
Please add default constructor and move constructor/assignment operator to Scope class. This would allow to create empty Scope object first, and then conditionally move-assign value later.
Describe alternatives you've considered
Now I need to create two code branches - one for tracing enabled where code creates Scope object and perform processing, and another with processing only.
Additional context
This sample code presents what I would like to do:
void EventLoop()
{
while (1)
{
auto obj = queue->Dequeue();
opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span;
opentelemetry::trace::Scope scope;
if (obj->TraceEnabled())
{
span = tracer->StartSpan(obj->GetName());
scope = tracer->WithActiveSpan(span);
}
obj->Run();
if (nullptr != span)
span->End();
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.