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

net/http contrib #102

Merged
merged 11 commits into from
Aug 17, 2017
Merged

net/http contrib #102

merged 11 commits into from
Aug 17, 2017

Conversation

gabsn
Copy link

@gabsn gabsn commented Aug 15, 2017

net/http support for tracing thanks to @FreekingDean.

@gabsn gabsn changed the title Http contrib net/http contrib Aug 17, 2017
@gabsn gabsn requested a review from talwai August 17, 2017 15:15
@FreekingDean
Copy link

Thank you gabsn for taking this on :)

@FreekingDean
Copy link

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: /users/:id in that this would cause a new resource for each user_id: /users/1, /users/2... I think we could alleviate that issue by allowing a path retrieval function passed into a private handler.

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. 😅

@gabsn
Copy link
Author

gabsn commented Aug 17, 2017

@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 1 resource = 1 route.


- [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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this contrib

Copy link
Author

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)

@gabsn gabsn force-pushed the http-contrib branch 2 times, most recently from accd498 to 4655c3b Compare August 17, 2017 21:55
@gabsn gabsn merged commit 25eb953 into master Aug 17, 2017
@palazzem palazzem deleted the http-contrib branch August 18, 2017 10:29
@palazzem
Copy link
Contributor

@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

@gabsn
Copy link
Author

gabsn commented Aug 18, 2017

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 master branch of the dependencies instead of a pinned version.

@palazzem
Copy link
Contributor

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.

@palazzem palazzem added this to the 0.5.1 milestone Sep 22, 2017
jdgordon pushed a commit to jdgordon/dd-trace-go that referenced this pull request May 31, 2022
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 this pull request may close these issues.

4 participants