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

How to remove active span and stop implicit child spans for a code path? #1911

Closed
VivekSubr opened this issue Jan 10, 2023 · 6 comments
Closed

Comments

@VivekSubr
Copy link

The java implementation seems to have a way to do this: open-telemetry/opentelemetry-java#1717

I'm looking for some way to clear the ActiveSpan, without having it destroyed, such that any new start spans won't be the child of it.

@VivekSubr VivekSubr changed the title How to remove span and stop implicit child spans for a code path How to remove span and stop implicit child spans for a code path? Jan 10, 2023
@VivekSubr VivekSubr changed the title How to remove span and stop implicit child spans for a code path? How to remove active span and stop implicit child spans for a code path? Jan 10, 2023
@VivekSubr
Copy link
Author

Setting invalid didn't seem to work,
nostd::shared_ptrtrace::Span resetSpan = nostd::shared_ptrtrace::Span(new trace::DefaultSpan(trace::DefaultSpan::GetInvalid()));
m_tracer->WithActiveSpan(resetSpan);

@lalitb
Copy link
Member

lalitb commented Jan 10, 2023

Please clarify what are you trying to achieve - Make a Span active, and then make it inactive. Why do you want to make it active at first place in that case. You can create multiple spans child of root as below without making them active.

auto span1 = tracer->StartSpan("span 1");
auto span2 = tracer->StartSpan("span 2");
...
..
span2->End();
..
span1->End();

@VivekSubr
Copy link
Author

Our application needs a way to 'suspend' or 'pause' spans, and then create completely unrelated spans... hence, the other issues I raised related to storing spans/scopes in maps.

To support that we need a way to set ActiveSpan to 'null' or 'invalid' or something like that and start afresh... and from the map, resume a span by setting it as Active again.

@lalitb
Copy link
Member

lalitb commented Jan 13, 2023

@VivekSubr - The implicit context management (using Context API) is not designed to handle these various mentioned stages of Spans - start, pause, resume , and stop. You can't remove the Span from context before it's logical completion, and replace any other span. Or cleanup the context in between. I would advice you not to use the implicit context management for your scenario, and instead directly pass the parent of span as an argument while it's creation.

@VivekSubr
Copy link
Author

okay, then it's up to application then.

@Falmarri
Copy link

Just wanted to comment this is really annoying not being able to do this. I have a client where it will lazily create a connection to the server. I want to create a separate, isolated span for the lifetime of the connection, and not have it be related to the trace of the individual request being made that happens to initiate the connection creation. This happens several levels deep in my application that includes sqlite extensions. So there's basically 0 way to pass the lifetime manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants