xrayhttp

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 16 Imported by: 6

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client(client *http.Client) *http.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

func HandlerWithClient(tn TracingNamer, client *xray.Client, h http.Handler) http.Handler

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

func WithClientTrace(ctx context.Context) (context.Context, context.CancelFunc)

WithClientTrace returns a new context based on the provided parent ctx.

Types

type DynamicTracingNamer added in v0.0.2

type DynamicTracingNamer struct {
	RecognizedHosts string
	FallbackName    string
}

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

type TracingNamer interface {
	TracingName(r *http.Request) string
}

TracingNamer is the interface for naming service node. If it returns empty string, the value of AWS_XRAY_TRACING_NAME environment value is used.

Jump to

Keyboard shortcuts

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