restful

package
v1.999.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package restful provides functions to trace the emicklei/go-restful package (https://github.com/emicklei/go-restful). WARNING: The underlying v2 version of emicklei/go-restful has known security vulnerabilities that have been resolved in v3 and is no longer under active development. As such consider this package DEPRECATED. It is highly recommended that you update to the latest version available at emicklei/go-restful.v3.

Example

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

// 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))
Output:

Example (SpanFromContext)
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 Filter

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

Filter is deprecated. Please use FilterFunc.

func FilterFunc added in v1.11.0

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

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

Types

type Option added in v1.11.0

type Option func(*config)

Option specifies instrumentation configuration options.

func WithAnalytics added in v1.11.0

func WithAnalytics(on bool) Option

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate added in v1.11.0

func WithAnalyticsRate(rate float64) Option

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

func WithHeaderTags added in v1.53.0

func WithHeaderTags(headers []string) Option

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 WithServiceName added in v1.11.0

func WithServiceName(name string) Option

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL