Documentation
¶
Overview ¶
Package xrayhttp traces the HTTP requests.
HTTP Server ¶
Handler wraps the provided net/http.Handler. The wrapped http.Handler creates a sub-segment and collects information of the request.
namer := xrayhttp.FixedTracingNamer("myApp") h := xrayhttp.Handler(namer, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello, World!")) })) http.ListenAndServe(":8080", h)
HTTP Client ¶
Client wraps the provided net/http.Client. The wrapped net/http.Client sets HTTP-specific xray fields, and adds the trace header to the outbound request.
client := xrayhttp.Client(nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://example.com", nil) if seg.AddError(err) { panic(err) } resp, err := client.Do(req) if seg.AddError(err) { panic(err) } defer resp.Body.Close()
Index ¶
- func Client(client *http.Client) *http.Client
- func Handler(tn TracingNamer, h http.Handler) http.Handler
- func HandlerWithClient(tn TracingNamer, client *xray.Client, h http.Handler) http.Handler
- func RoundTripper(rt http.RoundTripper) http.RoundTripper
- func WithClientTrace(ctx context.Context) (context.Context, context.CancelFunc)
- type DynamicTracingNamer
- type FixedTracingNamer
- type TracingNamer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Client ¶
Client creates a shallow copy of the provided http client, defaulting to http.DefaultClient, with net/http.RoundTripper wrapped with RoundTripper.
func Handler ¶
func Handler(tn TracingNamer, h http.Handler) http.Handler
Handler wraps the provided net/http.Handler. The returned net/http.Handler creates a sub-segment and collects information of the request.
func HandlerWithClient ¶
HandlerWithClient wraps the provided net/http.Handler. The returned net/http.Handler creates a sub-segment and collects information of the request.
func RoundTripper ¶
func RoundTripper(rt http.RoundTripper) http.RoundTripper
RoundTripper wraps the provided net/http.RoundTripper. The wrapped net/http.RoundTripper sets HTTP-specific xray fields, and adds the trace header to the outbound request.
func WithClientTrace ¶
WithClientTrace returns a new context based on the provided parent ctx.
Types ¶
type DynamicTracingNamer ¶ added in v0.0.2
DynamicTracingNamer chooses names for segments generated for incoming requests by parsing the HOST header of the incoming request. If the host header matches a given recognized pattern (using the included pattern package), it is used as the segment name. Otherwise, the fallback name is used.
func (DynamicTracingNamer) TracingName ¶ added in v0.0.2
func (tn DynamicTracingNamer) TracingName(r *http.Request) string
TracingName implements TracingNamer.
type FixedTracingNamer ¶
type FixedTracingNamer string
FixedTracingNamer records the fixed name of service node.
func (FixedTracingNamer) TracingName ¶
func (tn FixedTracingNamer) TracingName(r *http.Request) string
TracingName implements TracingNamer.
type TracingNamer ¶
TracingNamer is the interface for naming service node. If it returns empty string, the value of AWS_XRAY_TRACING_NAME environment value is used.