-
-
Notifications
You must be signed in to change notification settings - Fork 69
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 update the context in a middleware #62
Comments
Hi @rantav, The So I don't understand why it's not enought the What do you need exactly? Because, you need to store custom values in context ( |
The difference of |
Hi @savsgio, thanks for the quick response, but I'm afraid that would not be enough. In the before middleware I do: newCtx, span = trace.StartSpan(ctx, name) This operation creates a new span and returns a new context Here's how you read the span from the context: span = trace.FromContext(ctx) // ctx is supposed to be the newCtx here, otherwise it would not work Reference: https://godoc.org/go.opencensus.io/plugin/ochttp#hdr-Tracing So two pieces are missing:
For example see how the request |
Could you give me the |
Okay, i could see that Maybe i could do it something similar in atreugo to ease this functionality, trying to make it as close as possible to net / http |
Your suggestion to store the newCtx using // This returns nothing, which could be surprising to users
trace.FromContext(ctx)
// this workaround works, but is not obvious
newCtx := ctx.UserValue("traceCtx").(context.Context)
// and only now:
t := trace.FromContext(newCtx) |
I've been upload the fix, now you should do: // Before middleware
newCtx, span = trace.StartSpan(ctx, name)
ctx.AttachContext(newCtx)
// After middleware or view
trace.FromContext(ctx) I will release a new version throughout today. |
Awesome, thank you! |
Hi, what happened to |
Ohh sorry, yes i deleted it after a few minutes of release, because i want to include the fix about the attached ctx. I wil release it now. And sorry again. |
Some libraries, such as opencensus take advantage of the context, for example storing http scoped request tags into the context and then recording metrics based on this saved context in downstream handlers.
If you'd like at ochttp, an opencensus plugin for
net/http
you'd find extensive usage ofcontext.Context
, including creating a new context and passing this context to the next handler downstream. I think this pattern is common.My question is how can we simulate such behavior with atreugo/fasthttp. The
Value
method is not enough and so is the theSetUserValue
(I have read the response to #48 but I thing that won't cut it).We need a way to update the internal
context.Context
and store it inatreugo.RequestCtx
, does that make sense? (is there a way to do that currently)Thank you
The text was updated successfully, but these errors were encountered: