Documentation
¶
Overview ¶
Package restful provides functions to trace the emicklei/go-restful package (https://github.com/emicklei/go-restful).
Example ¶
To start tracing requests, add the trace filter to your go-restful router.
package main
import (
"io"
"log"
"net/http"
restfultrace "github.com/DataDog/dd-trace-go/contrib/emicklei/go-restful.v3/v2"
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
"github.com/emicklei/go-restful/v3"
)
func main() {
tracer.Start()
defer tracer.Stop()
// create new go-restful service
ws := new(restful.WebService)
// create the Datadog filter
filter := restfultrace.FilterFunc(
restfultrace.WithService("my-service"),
)
// use it
ws.Filter(filter)
// set endpoint
ws.Route(ws.GET("/hello").To(
func(_ *restful.Request, response *restful.Response) {
io.WriteString(response, "world")
}))
restful.Add(ws)
// serve request
log.Fatal(http.ListenAndServe(":8080", nil))
}
Output:
Example (SpanFromContext) ¶
package main
import (
restfultrace "github.com/DataDog/dd-trace-go/contrib/emicklei/go-restful.v3/v2"
"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
"github.com/emicklei/go-restful/v3"
)
func main() {
tracer.Start()
defer tracer.Stop()
ws := new(restful.WebService)
ws.Filter(restfultrace.FilterFunc(
restfultrace.WithService("my-service"),
))
ws.Route(ws.GET("/image/encode").To(
func(request *restful.Request, _ *restful.Response) {
// create a child span to track operation timing.
encodeSpan, _ := tracer.StartSpanFromContext(request.Request.Context(), "image.encode")
// encode a image
encodeSpan.Finish()
}))
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterFunc ¶
func FilterFunc(configOpts ...Option) restful.FilterFunction
FilterFunc returns a restful.FilterFunction which will automatically trace incoming request.
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option describes options for the go-restful integration.
type OptionFn ¶
type OptionFn func(*config)
OptionFn represents options applicable to FilterFunc.
func WithAnalytics ¶
WithAnalytics enables Trace Analytics for all started spans.
func WithAnalyticsRate ¶
WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.
func WithHeaderTags ¶
WithHeaderTags enables the integration to attach HTTP request headers as span tags. Warning: Using this feature can risk exposing sensitive data such as authorization tokens to Datadog. Special headers can not be sub-selected. E.g., an entire Cookie header would be transmitted, without the ability to choose specific Cookies.
func WithService ¶
WithService sets the service name to by used by the filter.