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

Add support for HTTP templated paths #135

Merged
merged 3 commits into from
Jul 10, 2020
Merged

Conversation

andrewslotin
Copy link
Contributor

This PR adds support for forwarding the path template used to match an HTTP request to the handler. The template string can either be specified during the instrumentation by providing it as an argument to instana.TracingHandlerFunc() or added as a custom tag http.path_tpl to the incoming request span.

Providing path template during instrumentation

// Provide the template string as an argument to instana.TracingHandlerFunc()
instrumentedHandler := instana.TracingHandlerFunc(sensor, "/articles/{category}/{id:[0-9]+}", Handler)
// Register your instrumented handler
r.HandleFunc("/articles/{category}/{id:[0-9]+}", instrumentedHandler)

Please note that the agent will attempt to detect whether a request has been routed via pattern matching by comparing it to (*http.Request).Path and only populate the http.path_tpl if these values differ.

Adding a path template to the request span

func Handler(w http.ResponseWriter, req *http.Request) {
	// Extract the request span from context and add an `http.path_tpl` tag to it
	if parent, ok := instana.SpanFromContext(req.Context()); ok {
		parent.SetTag("http.path_tpl", "/articles/{category}/{id:[0-9]+}")
	}

	// ...
}

@andrewslotin andrewslotin force-pushed the add_http_path_tpl_support branch from eb11ba7 to e25b01e Compare July 10, 2020 13:29
@andrewslotin andrewslotin merged commit b7c323d into master Jul 10, 2020
@andrewslotin andrewslotin deleted the add_http_path_tpl_support branch July 10, 2020 13:39
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.

1 participant