-
Notifications
You must be signed in to change notification settings - Fork 437
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
net/http contrib #102
net/http contrib #102
Conversation
Thank you gabsn for taking this on :) |
I have thought about this, and I wonder if we should build this into some form of a base handler for each of the router (httprouter/gorilla) packages. I know the main issue is that path routing would be messy as this does not take into account resource based paths: I'm not sure if I'm making sense so heres some code: //net/http/http.go
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
tracedRequest, err := traceRequest(r, GetPath, h.tracer)
...
}
func GetPath(r *http.Request) string {
return r.URL.Path
}
type PathFunc func(r *http.Request) string
func traceRequest(r *http.Request, pathFunc PathFunc, t *tracer.Tracer) (*http.Request, error) {
...
span.SetMeta(ext.HTTPURL, pathFunc(r))
...
} //gorilla/muxtrace/muxtrace.go
import(
...
httptrace "github.com/DataDog/dd-trace-go/libs/net/http"
)
func (m *MuxTracer) TraceHandleFunc(handler http.HandlerFunc) http.HandlerFunc {
...
tracedRequest, err := httptrace.traceRequest(r, GetPath, m.tracer)
...
}
func GetPath(r *http.Request) string {
route := mux.CurrentRoute(req)
path, err := route.GetPathTemplate()
if err != nil {
// when route doesn't define a path
path = "unknown"
}
return path
} I hope this makes sense and I'm not just rambling & incoherent. 😅 |
@FreekingDean Yes you're right, with this implementation we end up with a new resource per url hit. I'll do a modification to be sure that |
|
||
- [libs](https://github.com/DataDog/dd-trace-go/tree/gabin/contributions/libs): contains the different libraries supported by our APM solution. You just | ||
- [libs](https://github.com/DataDog/dd-trace-go/tree/master/libs): contains the different libraries supported by our APM solution. |
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.
call this contrib
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'll do that in another PR so it will be more clear. (it's a change of +100 files)
accd498
to
4655c3b
Compare
@gabsn probably I'm missing something, but did we merge a broken build? I see that it ended with a failure: https://circleci.com/gh/DataDog/dd-trace-go/677 Indeed, the current master is broken: https://circleci.com/gh/DataDog/dd-trace-go/679 |
Yeah the problem is not related with this PR, it's because of this PR on the grpc repo. We need to improve our testing to avoid those kind of issues, because for the moment circleci uses the |
Yea @gabsn, we should definitely improve our testing. I already have a plan about it and will write something down very soon so that we can address also other issues. |
net/http
support for tracing thanks to @FreekingDean.