Documentation
¶
Overview ¶
Package http contains several client/server http plugin which can be used for integration with net/http.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewServerMiddleware ¶
func NewServerMiddleware(tracer *go2sky.Tracer, options ...ServerOption) (func(http.Handler) http.Handler, error)
NewServerMiddleware returns a http.Handler middleware with tracing.
Example ¶
package main
import (
"fmt"
"log"
"net/http"
"net/http/httptest"
"time"
"github.com/SkyAPM/go2sky"
"github.com/SkyAPM/go2sky/reporter"
)
func main() {
// Use gRPC reporter for production
r, err := reporter.NewLogReporter()
if err != nil {
log.Fatalf("new reporter error %v \n", err)
}
defer r.Close()
tracer, err := go2sky.NewTracer("example", go2sky.WithReporter(r))
if err != nil {
log.Fatalf("create tracer error %v \n", err)
}
sm, err := NewServerMiddleware(tracer)
if err != nil {
log.Fatalf("create server middleware error %v \n", err)
}
client, err := NewClient(tracer)
if err != nil {
log.Fatalf("create client error %v \n", err)
}
// create test server
ts := httptest.NewServer(sm(endFunc()))
defer ts.Close()
// call end service
request, err := http.NewRequest("POST", fmt.Sprintf("%s/end", ts.URL), nil)
if err != nil {
log.Fatalf("unable to create http request: %+v\n", err)
}
res, err := client.Do(request)
if err != nil {
log.Fatalf("unable to do http request: %+v\n", err)
}
_ = res.Body.Close()
time.Sleep(time.Second)
}
func endFunc() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Printf("end func called with method: %s\n", r.Method)
time.Sleep(50 * time.Millisecond)
}
}
Types ¶
type ClientConfig ¶
type ClientConfig struct {
// contains filtered or unexported fields
}
type ClientOption ¶
type ClientOption func(*ClientConfig)
ClientOption allows optional configuration of Client.
func WithClient ¶
func WithClient(client *http.Client) ClientOption
WithClient set customer http client.
func WithClientOperationName ¶
func WithClientOperationName(name string) ClientOption
WithOperationName override default operation name.
func WithClientTag ¶
func WithClientTag(key string, value string) ClientOption
WithClientTag adds extra tag to client spans.
type ServerOption ¶
type ServerOption func(*handler)
ServerOption allows Middleware to be optionally configured.
func WithServerOperationName ¶
func WithServerOperationName(name string) ServerOption
WithOperationName override default operation name.
func WithServerTag ¶
func WithServerTag(key string, value string) ServerOption
Tag adds extra tag to server spans.
Click to show internal directories.
Click to hide internal directories.