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

linking requests and responses #1536

Closed
Geal opened this issue Aug 18, 2022 · 3 comments · Fixed by #1663
Closed

linking requests and responses #1536

Geal opened this issue Aug 18, 2022 · 3 comments · Fixed by #1663
Assignees

Comments

@Geal
Copy link
Contributor

Geal commented Aug 18, 2022

(prompted by the work on #1501)
If we're writing a plugin with rhai, or a native one using the map_request and map_response methods, we have no way to know which request corresponds to which response, except by explicitely setting some information in the Context object.

Could we add an id to a request when it comes in and make it available throughout the entire lifecycle? (possibly in telemetry too?)
ULIDs
or the still in draft UUID v6 would work well for that

@abernix
Copy link
Member

abernix commented Aug 30, 2022

Maybe we should just use span_current_id? -@BrynCooke

@abernix abernix added this to the v1.0.0-alpha.1 milestone Aug 30, 2022
@garypen
Copy link
Contributor

garypen commented Aug 31, 2022

We should. It's (of course) slightly more complicated than that. I spoke about this with @BrynCooke and we concluded that the best thing to do would be to add a new function:

apollo_router::get_trace_id()

which would mask all the complexity of crate/traits required to retrieve this value.

garypen added a commit that referenced this issue Aug 31, 2022
Retrieve a unique trace id which can be used to link together processing
steps in a plugin (or anywhere else in the router).

If an execution trace context cannot be established, the return value
will be INVALID_TRACE (all zeros). Watch out for this. Two invalid
traces will be equal to each other. In other words, to correctly confirm
that two things are linked you would have to check:

let other_id = apollo_router::trace_id();
let my_id = apollo_router::trace_id();

if my_id != INVALID_TRACE && my_id == other_id {
    <blah...>
}

Without that first check, i.e.:

if my_id == other_id {
    <blah...>
}

you could be linking together two unrelated things which both had
invalid ids.

fixes: #1536
@garypen
Copy link
Contributor

garypen commented Aug 31, 2022

This became:

apollo_router::tracer::TraceId::new()

I've tried to hide as much complexity as I can.

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

Successfully merging a pull request may close this issue.

3 participants