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

Guidance needed for implementing tracing API #168

Open
MobiliteDev opened this issue May 7, 2024 · 2 comments
Open

Guidance needed for implementing tracing API #168

MobiliteDev opened this issue May 7, 2024 · 2 comments

Comments

@MobiliteDev
Copy link

I am currently implementing a simplified tracing API for my uses, aiming to abstract away the complexities of manual span management. The goal is to get a straightforward API that allows me to start traces, end traces, and add subtraces without directly dealing with parent-child span relationships.

Here's what I am trying to achieve:

  • Start Trace: Initiates a new trace or a root span.

  • End Trace: Closes the currently active span and automatically manages the context to revert to the parent span.

  • Add Subtrace: Creates a new sub-span under the current active span.

I've encountered a challenge with the Span class, particularly in retrieving and managing the parent span when ending a trace. The current Span implementation exposes parentSpanId, but it doesn't provide direct access to the parent Span object, which is necessary to handle the thing properly.

Questions:

  1. Is there an existing implementation or pattern within the library that supports this kind of API, specifically for managing the parent span relationship internally?

  2. If such functionality is not currently available, is this normal because the lib is under development ? Am i missing something important ?

@blakeroberts-wk
Copy link
Contributor

Some things to keep in mind:

  1. The relationship between a parent and child is created by the child.
  2. The relationship is created when the child span is created and it is immutable.
  3. The only concrete implementation of a "trace" is the trace ID that is either created or inherited when a span is created.

With respect to the API you are trying to achieve:

  • Start Trace: when starting a span, the context the span is started with needs to contain an invalid span context. Consider this code:
    // TODO: use start span option `newRoot` instead
    if (newRoot) {
    context = api.contextWithSpanContext(context, api.SpanContext.invalid());
    }
    .
  • End Trace: The best way to manage context automatically is to use zones. When execution context leaves the zone where a span is active, the span is no longer active and thus the active context "reverts" to the parent span of the parent zone, if any.
  • Add Subtrace: Again, the best way to manage context automatically is zones. Consider the same code linked above.

I believe this answers your questions, loosely. I apologize for the brevity. It's hard to be succinct. I think the implementation of the linked function is the most succinct answer to your questions.

Aside: I am on the fence about the current implementation of contexts and their use of zones. I've been collecting my thoughts and would like to open an issue and fish for feedback regarding changes to the implementation. But the changes, or reasons for the changes, don't feel very well fleshed out yet. Maybe I still open the issue though. Perhaps folks such as yourself can help clear up the fog where I'm struggling!

@blakeroberts-wk
Copy link
Contributor

Here's the issue I made on consolidating context APIs: #185

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

2 participants