// NewOTFilter returns a go-restful filter which add OpenTracing instrument
NewOTFilter returns a go-restful filter which add OpenTracing instrument
// NewOTFilter returns a go - restful filter which add OpenTracing instrument
func NewOTFilter(tracer opentracing.Tracer, options ...FilterOption) restful.FilterFunction {
	opts := filterOptions{
		operationNameFunc: DefaultOperationNameFunc,
		componentName:     DefaultComponentName,
	}
	for _, opt := range options {
		opt(&opts)
	}
	return func(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
		ctx, err := tracer.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(req.Request.Header))
		if err != nil {
			log.Println(err)
		}
		sp := tracer.StartSpan(opts.operationNameFunc(req), ext.RPCServerOption(ctx))
		defer sp.Finish()
		ext.HTTPMethod.Set(sp, req.Request.Method)
		ext.HTTPUrl.Set(sp, req.Request.URL.String())
		ext.Component.Set(sp, opts.componentName)
		ext.HTTPStatusCode.Set(sp, uint16(resp.StatusCode()))
		chain.ProcessFilter(req, resp)
	}
}
func NewOTFilter ( tracer opentracing . Tracer , options ... FilterOption ) restful . FilterFunction { opts := filterOptions { operationNameFunc : DefaultOperationNameFunc , componentName : DefaultComponentName , } for _ , opt := range options { opt ( & opts ) } return func ( req * restful . Request , resp * restful . Response , chain * restful . FilterChain ) { ctx , err := tracer . Extract ( opentracing . HTTPHeaders , opentracing . HTTPHeadersCarrier ( req . Request . Header ) ) if err != nil { log . Println ( err ) } sp := tracer . StartSpan ( opts . operationNameFunc ( req ) , ext . RPCServerOption ( ctx ) ) defer sp . Finish ( ) ext . HTTPMethod . Set ( sp , req . Request . Method ) ext . HTTPUrl . Set ( sp , req . Request . URL . String ( ) ) ext . Component . Set ( sp , opts . componentName ) ext . HTTPStatusCode . Set ( sp , uint16 ( resp . StatusCode ( ) ) ) chain . ProcessFilter ( req , resp ) } }
NewOTFilter returns a go-restful filter which add OpenTracing instrument
NewOTFilter returns a go - restful filter which add OpenTracing instrument
// return a go-restful filter which add OpenTracing instrument // NOTE: "filter" in go-restful is similar with "middleware" mechanism in modern web framework // record operation name // record HTTP method // record HTTP url // record component name // record HTTP status code