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
Make logging traceable #1685
Make logging traceable #1685
Conversation
cmd/server/handler.go
Outdated
logger.Before = func(entry *logrus.Entry, r *http.Request, _ string) *logrus.Entry { | ||
fields := make(map[string]interface{}) | ||
for key, headerKey := range headers { | ||
fields[key] = r.Header.Get(headerKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem to be compliant with the open tracing specification: https://github.com/opentracing/specification/blob/584c52365fe0700ba25effa79dce5effb845ced8/rfc/trace_identifiers.md
I would expect that this parses the HTTP Header traceparent
. I'm pretty sure that opentracing has a library to do that, so maybe we can just use that here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. And I found library to extract tracing information from header!
https://github.com/open-telemetry/opentelemetry-go
Signed-off-by: Shota Sawada <xiootas@gmail.com>
f9fefbd
to
328ee69
Compare
Signed-off-by: Shota Sawada <xiootas@gmail.com>
328ee69
to
6d6a2b7
Compare
@@ -154,6 +155,21 @@ func RunServeAll(version, build, date string) func(cmd *cobra.Command, args []st | |||
} | |||
} | |||
|
|||
func setTracingLogger(d driver.Driver, logger *negronilogrus.Middleware) { | |||
logger.Before = func(entry *logrus.Entry, r *http.Request, remoteAddr string) *logrus.Entry { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This overwrites the existing logger.Before, right? I think we have a custom Before somewhere - Maybe you could check if logger.Before
is set and if it is, execute it and then execute this logic here, but only adding the trace_id
and span_id
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, it appears that we're not actually using that here. Here's the actual function I was referring to: https://github.com/ory/x/blob/master/reqlog/middleware.go
I think it would make sense to use that function and add the trace_id in that middleware. We should also add it to both before, and after!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example: https://github.com/ory/oathkeeper/blob/master/cmd/server/server.go#L44
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it!
It seemed logger.Before
was set default(request
, method
and remote
). I realized it's not safety to consider whether logger.Before
or not, I fixed to add field.
We should also add it to both before, and after!
It's seems it's enough to add only before. Actually logs appear span_id
and trace_id
at both stating and completed handling request.
{"level":"info","method":"GET","msg":"started handling request","remote":"[::1]:56308","request":"/health/alive","time":"2020-01-11T11:09:46+09:00","trace_id":"00f067aa0ba902b7"}
{"level":"info","measure#hydra/admin: https://localhost:4444/.latency":218780,"method":"GET","msg":"completed handling request","remote":"[::1]:56308","request":"/health/alive","status":200,"text_status":"OK","time":"2020-01-11T11:09:46+09:00","took":218780,"trace_id":"00f067aa0ba902b7"}
@@ -413,3 +415,11 @@ func (v *ViperProvider) ShareOAuth2Debug() bool { | |||
func (v *ViperProvider) PKCEEnforced() bool { | |||
return viperx.GetBool(v.l, ViperKeyPKCEEnforced, false, "OAUTH2_PKCE_ENFORCED") | |||
} | |||
|
|||
func (v *ViperProvider) LogTracingPublic() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be fine with actually having this enabled always no config required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it!
Signed-off-by: sawadashota <xiootas@gmail.com>
Signed-off-by: sawadashota <xiootas@gmail.com>
Signed-off-by: sawadashota <xiootas@gmail.com>
Thank you! :) |
Signed-off-by: Shota Sawada <xiootas@gmail.com>
Related issue
#1680
Proposed changes
Add Tracing logging option.
Then, hydra logs like this.
If request doesn't have
Traceparent
header, log doesn't appeartrace_id
andspan_id
.Checklist
vulnerability, I confirm that I got green light (please contact security@ory.sh) from the maintainers to push the changes.