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

Path Route #61

Closed
qgxpagamentos opened this issue Nov 8, 2022 · 1 comment
Closed

Path Route #61

qgxpagamentos opened this issue Nov 8, 2022 · 1 comment
Labels
question Further information is requested

Comments

@qgxpagamentos
Copy link

Hello,
I've been using the router for some time now, but I'm having trouble figuring out the path being called to include in the Datadog.
Below is an example of middleware, retrieves the path already with parameter value, but I would like to display it as the original path.

It is showing with the concatenated parameter and not as declared.

https://github.com/qgxpagamentos/ddfasthttp
``
func Middleware(f fasthttp.RequestHandler) fasthttp.RequestHandler {
return func(ctx *fasthttp.RequestCtx) {
if _, ok := os.LookupEnv("DATADOG_ENABLED"); !ok {
f(ctx)
return
}
spanOpts := []ddtrace.StartSpanOption{
tracer.ResourceName(string(ctx.Request.Header.Method()) + " " + string(ctx.Request.URI().Path())),
}
var r http.Request
if e := fasthttpadaptor.ConvertRequest(ctx, &r, true); e != nil {
panic(e)
}
span, context := StartRequestSpan(&r, spanOpts...)

	ctx.SetUserValue(DataDogTransaction, context)

	f(ctx)

	statusCode := ctx.Response.StatusCode()
	FinishRequestSpan(span, statusCode)
}

}
``
Screen Shot 2022-11-07 at 23 20 16
Screen Shot 2022-11-07 at 23 20 47

@savsgio
Copy link
Member

savsgio commented Nov 21, 2022

Hi @qgxpagamentos,

Sorry for my delayed answer!

If you want to get and set the declared raw router path, so group by all keys in the same span, you must get it from user values:

// set this flag in your router instance 
myrouter.SaveMatchedRoutePath = true

// and get the matched route path from user values in your request handler
matchedRoutePath := ctx.UserValue(router.MatchedRoutePathParam).(string)

Thanks!

@savsgio savsgio added the question Further information is requested label Nov 21, 2022
@savsgio savsgio closed this as completed Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants