dd-trace-go.v1: gopkg.in/DataDog/dd-trace-go.v1/contrib/emicklei/go-restful Index | Examples | Files

package restful

import "gopkg.in/DataDog/dd-trace-go.v1/contrib/emicklei/go-restful"

Package restful provides functions to trace the emicklei/go-restful package (https://github.com/emicklei/go-restful).

To start tracing requests, add the trace filter to your go-restful router.

Code:

// create new go-restful service
ws := new(restful.WebService)

// create the Datadog filter
filter := restfultrace.FilterFunc(
    restfultrace.WithServiceName("my-service"),
)

// use it
ws.Filter(filter)

// set endpoint
ws.Route(ws.GET("/hello").To(
    func(request *restful.Request, response *restful.Response) {
        io.WriteString(response, "world")
    }))
restful.Add(ws)

// serve request
log.Fatal(http.ListenAndServe(":8080", nil))

Code:

ws := new(restful.WebService)
ws.Filter(restfultrace.Filter)

ws.Route(ws.GET("/image/encode").To(
    func(request *restful.Request, response *restful.Response) {
        // create a child span to track operation timing.
        encodeSpan, _ := tracer.StartSpanFromContext(request.Request.Context(), "image.encode")
        // encode a image
        encodeSpan.Finish()
    }))

Index

Examples

Package Files

option.go restful.go

func Filter Uses

func Filter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

Filter is deprecated. Please use FilterFunc.

func FilterFunc Uses

func FilterFunc(configOpts ...Option) restful.FilterFunction

FilterFunc returns a restful.FilterFunction which will automatically trace incoming request.

type Option Uses

type Option func(*config)

Option specifies instrumentation configuration options.

func WithAnalytics Uses

func WithAnalytics(on bool) Option

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate Uses

func WithAnalyticsRate(rate float64) Option

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithServiceName Uses

func WithServiceName(name string) Option

WithServiceName sets the service name to by used by the filter.

Package restful imports 7 packages (graph). Updated 2020-02-19. Refresh now. Tools for package owners.