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"
"github.com/emicklei/go-restful"
restfultrace "git.proto.group/protoobp/pobp-trace-go/contrib/emicklei/go-restful"
)
func main() {
// create new go-restful service
ws := new(restful.WebService)
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))
}
Output:
Example (SpanFromContext) ¶
package main
import (
"github.com/emicklei/go-restful"
restfultrace "git.proto.group/protoobp/pobp-trace-go/contrib/emicklei/go-restful"
"git.proto.group/protoobp/pobp-trace-go/pobptrace/tracer"
)
func main() {
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()
}))
}
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 func(*config)
Option specifies instrumentation configuration options.
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 WithServiceName ¶
WithServiceName sets the service name to by used by the filter.
Click to show internal directories.
Click to hide internal directories.