Documentation
¶
Overview ¶
Package opentracing is used to initialize the opentracing from the plugin, and supplies the OpenTracing http.RoundTripper and router middleware.
Index ¶
- Variables
- func HTTPHandler(handler http.Handler, opt *Option) http.Handler
- func InitOpenTracingFromPlugin(pluginPath string, config interface{}) (err error)
- func MustInitOpenTracingFromPlugin(pluginPath string, config interface{})
- func OpenTracing(opt *Option) ship.Middleware
- func RegisterPluginOpts()
- type HTTPRoundTripper
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var PluginOptGroup = gconf.NewGroup("opentracing.plugin")
PluginOptGroup is the group of the OpenTracing plugin config options.
var PluginOpts = []gconf.Opt{
gconf.StrOpt("path", "The path of the plugin implementing the OpenTracing tracer."),
gconf.StrOpt("config", "The configuration information of the plugin."),
}
PluginOpts collects the options of the OpenTracing Plugin.
Functions ¶
func HTTPHandler ¶ added in v0.16.0
HTTPHandler is the same as OpenTracing, but returns a http.Handler.
func InitOpenTracingFromPlugin ¶
InitOpenTracingFromPlugin initializes the OpenTracing implementation, which will load the implementation plugin and call the function InitOpenTracing with config.
The plugin must contain the function
func InitOpenTracing(config interface{}) error
Notice:
- If config is empty, retry the env variable "OPENTRACING_PLUGIN_CONFIG".
- If pluginPath is empty, retry the env variable "OPENTRACING_PLUGIN_PATH".
- If pluginPath is empty, it returns nil and does nothing.
func MustInitOpenTracingFromPlugin ¶
func MustInitOpenTracingFromPlugin(pluginPath string, config interface{})
MustInitOpenTracingFromPlugin is the same as InitOpenTracing, but logs the error and exits the program when an error occurs.
func OpenTracing ¶
func OpenTracing(opt *Option) ship.Middleware
OpenTracing is a middleware to support OpenTracing, which extracts the span context from the http request header, creates a new span as the server span from the span context, and put it into the request context.
func RegisterPluginOpts ¶
func RegisterPluginOpts()
RegisterPluginOpts registers the options of opentracing plugin.
Types ¶
type HTTPRoundTripper ¶
type HTTPRoundTripper struct { http.RoundTripper Option }
HTTPRoundTripper is a RoundTripper to support OpenTracing, which extracts the parent span from the context of the sent http.Request, then creates a new span by the context of the parent span for http.Request.
func NewHTTPRoundTripper ¶
func NewHTTPRoundTripper(rt http.RoundTripper, opt *Option) *HTTPRoundTripper
NewHTTPRoundTripper returns a new HTTPRoundTripper.
func (*HTTPRoundTripper) WrappedRoundTripper ¶
func (rt *HTTPRoundTripper) WrappedRoundTripper() http.RoundTripper
WrappedRoundTripper returns the wrapped http.RoundTripper.
type Option ¶
type Option struct { Tracer opentracing.Tracer // Default: opentracing.GlobalTracer() ComponentName string // Default: use ComponentNameFunc(req) // ComponentNameFunc is used to get the component name if ComponentName // is empty. // // Default: "net/http" ComponentNameFunc func(*http.Request) string // URLTagFunc is used to get the value of the tag "http.url". // // Default: url.String() URLTagFunc func(*url.URL) string // SpanFilter is used to filter the span if returning true. // // Default: return false SpanFilter func(*http.Request) bool // OperationNameFunc is used to the operation name. // // Default: fmt.Sprintf("HTTP %s %s", r.Method, r.URL.Path) OperationNameFunc func(*http.Request) string // SpanObserver is used to do extra things of the span for the request. // // For example, // OpenTracingOption { // SpanObserver: func(*http.Request, opentracing.Span) { // ext.PeerHostname.Set(span, req.Host) // }, // } // // Default: Do nothing. SpanObserver func(*http.Request, opentracing.Span) }
Option is used to configure the OpenTracing middleware and RoundTripper.
func (*Option) GetComponentName ¶
GetComponentName returns ComponentName if it is not empty. Or ComponentNameFunc(req) instead.