Documentation ¶
Overview ¶
Package xray provides a simple API for tracing and monitoring AWS X-Ray.
Index ¶
- Constants
- Variables
- func AddAnnotationBool(ctx context.Context, key string, value bool)
- func AddAnnotationFloat64(ctx context.Context, key string, value float64)
- func AddAnnotationInt64(ctx context.Context, key string, value int64)
- func AddAnnotationString(ctx context.Context, key, value string)
- func AddAnnotationUint64(ctx context.Context, key string, value uint64)
- func AddError(ctx context.Context, err error) bool
- func AddMetadata(ctx context.Context, key string, value any)
- func AddMetadataToNamespace(ctx context.Context, namespace, key string, value any)
- func AddPanic(ctx context.Context, err any) bool
- func AddPlugin(plugin Plugin)
- func Capture(ctx context.Context, name string, f func(context.Context) error) error
- func Configure(cfg *Config)
- func ContextTraceID(ctx context.Context) string
- func DetachContextSegment(ctx context.Context) context.Context
- func NewSegmentID() string
- func NewTraceID() string
- func SetAWS(ctx context.Context, awsData schema.AWS)
- func SetError(ctx context.Context)
- func SetFault(ctx context.Context)
- func SetHTTPRequest(ctx context.Context, request *schema.HTTPRequest)
- func SetHTTPResponse(ctx context.Context, response *schema.HTTPResponse)
- func SetNamespace(ctx context.Context, namespace string)
- func SetSQL(ctx context.Context, sql *schema.SQL)
- func SetThrottle(ctx context.Context)
- func SetUser(ctx context.Context, user string)
- func WithClient(ctx context.Context, client *Client) context.Context
- func WithSegment(ctx context.Context, seg *Segment) context.Context
- type Client
- type Config
- type NullDaemon
- type Plugin
- type SamplingDecision
- type Segment
- func BeginDummySegment(ctx context.Context) (context.Context, *Segment)
- func BeginSegment(ctx context.Context, name string) (context.Context, *Segment)
- func BeginSegmentAt(ctx context.Context, now time.Time, name string) (context.Context, *Segment)
- func BeginSegmentWithHeader(ctx context.Context, name, header string) (context.Context, *Segment)
- func BeginSegmentWithRequest(ctx context.Context, name string, r *http.Request) (context.Context, *Segment)
- func BeginSubsegment(ctx context.Context, name string) (context.Context, *Segment)
- func BeginSubsegmentAt(ctx context.Context, now time.Time, name string) (context.Context, *Segment)
- func ContextSegment(ctx context.Context) *Segment
- func (seg *Segment) AddAnnotationBool(key string, value bool)
- func (seg *Segment) AddAnnotationFloat64(key string, value float64)
- func (seg *Segment) AddAnnotationInt64(key string, value int64)
- func (seg *Segment) AddAnnotationString(key, value string)
- func (seg *Segment) AddAnnotationUint64(key string, value uint64)
- func (seg *Segment) AddError(err error) bool
- func (seg *Segment) AddMetadata(key string, value any)
- func (seg *Segment) AddMetadataToNamespace(namespace, key string, value any)
- func (seg *Segment) AddPanic(err any) bool
- func (seg *Segment) Close()
- func (seg *Segment) Namespace() string
- func (seg *Segment) Sampled() bool
- func (seg *Segment) SetAWS(awsData schema.AWS)
- func (seg *Segment) SetError()
- func (seg *Segment) SetFault()
- func (seg *Segment) SetHTTPRequest(request *schema.HTTPRequest)
- func (seg *Segment) SetHTTPResponse(response *schema.HTTPResponse)
- func (seg *Segment) SetNamespace(namespace string)
- func (seg *Segment) SetSQL(sql *schema.SQL)
- func (seg *Segment) SetThrottle()
- func (seg *Segment) SetUser(user string)
- type StreamingStrategy
- type TestDaemon
- type TraceHeader
Constants ¶
const Name = "X-Ray YA-SDK for Go"
Name records which X-Ray SDK customer uses.
const TraceIDHeaderKey string = "x-amzn-trace-id"
TraceIDHeaderKey is the HTTP header name used for tracing.
const Version = "1.8.1"
Version records the current X-Ray Go SDK version.
Variables ¶
var ServiceData = &schema.Service{ Runtime: runtime.Compiler, RuntimeVersion: runtime.Version(), }
ServiceData is the metadata of the user service. It is used by all segments that X-Ray YA-SDK sends.
Functions ¶
func AddAnnotationBool ¶
AddAnnotationBool adds a boolean type annotation.
func AddAnnotationFloat64 ¶
AddAnnotationFloat64 adds a 64 bit integer type annotation.
func AddAnnotationInt64 ¶
AddAnnotationInt64 adds a 64 bit integer type annotation.
func AddAnnotationString ¶
AddAnnotationString adds a string type annotation.
func AddAnnotationUint64 ¶
AddAnnotationUint64 adds a 64 bit integer type annotation.
func AddMetadata ¶
AddMetadata adds metadata.
func AddMetadataToNamespace ¶
AddMetadataToNamespace adds metadata.
func Capture ¶
Capture traces the provided synchronous function by beginning and closing a subsegment around its execution.
func Configure ¶ added in v0.0.2
func Configure(cfg *Config)
Configure replaces the default client with the cfg.
func ContextTraceID ¶ added in v1.0.0
ContextTraceID returns the trace id associated ctx.
func DetachContextSegment ¶ added in v1.2.0
DetachContextSegment returns a new context with the existing segment. All values associated with ctx are also associated with the new context. This is useful for creating background tasks which won't be cancelled when a request completes.
On Go 1.21 or later, this function is just an alias of context.WithoutCancel. Use context.WithoutCancel directly.
func NewSegmentID ¶
func NewSegmentID() string
NewSegmentID generates a string format of segment ID.
func SetAWS ¶
SetAWS sets the information about the AWS resource on which your application served the request.
func SetHTTPRequest ¶
func SetHTTPRequest(ctx context.Context, request *schema.HTTPRequest)
SetHTTPRequest sets the information of HTTP requests.
func SetHTTPResponse ¶
func SetHTTPResponse(ctx context.Context, response *schema.HTTPResponse)
SetHTTPResponse sets the information of HTTP requests.
func SetNamespace ¶
SetNamespace sets namespace
func WithClient ¶
WithClient returns new context with the client.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for AWS X-Ray daemon.
func ContextClient ¶
ContextClient returns the client of current context.
type Config ¶
type Config struct { // DaemonAddress is the address for connecting AWS X-Ray daemon. // It overwrites the address from the AWS_XRAY_DAEMON_ADDRESS environment value. // By default, the SDK uses 127.0.0.1:2000 for both trace data (UDP) and sampling (TCP). // The format is "address:port" or "tcp:address:port udp:address:port". DaemonAddress string // Disabled disables X-Ray tracing. // It overwrites the setting from the AWS_XRAY_SDK_ENABLED environment value. Disabled bool StreamingStrategy StreamingStrategy SamplingStrategy sampling.Strategy // ContextMissingStrategy specifies the strategy to use when a segment is not associated with a context. ContextMissingStrategy ctxmissing.Strategy }
Config is a configure for connecting AWS X-Ray daemon.
type NullDaemon ¶
type NullDaemon struct {
// contains filtered or unexported fields
}
NullDaemon receives segment documents, but ignore them.
func NewNullDaemon ¶
func NewNullDaemon() (context.Context, *NullDaemon)
NewNullDaemon creates new NullDaemon.
type Plugin ¶
type Plugin interface { // HandleSegment is called by AWS X-Ray YA-SDK // before submitting the root segment. // The document is the raw data of the segment, and plugins can rewrite it. HandleSegment(segment *Segment, document *schema.Segment) // Origin returns the type of AWS resource that the plugin detected. // If the plugin can't detect any type, it returns empty string. Origin() string }
Plugin is the interface of AWS X-Ray plugin.
type SamplingDecision ¶
type SamplingDecision rune
SamplingDecision is whether or not the current segment has been sampled.
const ( // SamplingDecisionSampled indicates the current segment has been // sampled and will be sent to the X-Ray daemon. SamplingDecisionSampled SamplingDecision = '1' // SamplingDecisionNotSampled indicates the current segment has // not been sampled. SamplingDecisionNotSampled SamplingDecision = '0' // SamplingDecisionRequested indicates sampling decision will be // made by the downstream service and propagated // back upstream in the response. SamplingDecisionRequested SamplingDecision = '?' // SamplingDecisionUnknown indicates no sampling decision will be made. SamplingDecisionUnknown SamplingDecision = 0 )
type Segment ¶
type Segment struct {
// contains filtered or unexported fields
}
Segment is a segment.
func BeginDummySegment ¶ added in v0.0.4
BeginDummySegment creates a new segment that traces nothing.
func BeginSegment ¶
BeginSegment creates a new Segment for a given name and context.
Caller should close the segment when the work is done.
func BeginSegmentAt ¶ added in v1.7.4
BeginSegmentAt creates a new Segment for a given time, name and context.
Caller should close the segment when the work is done.
func BeginSegmentWithHeader ¶ added in v0.0.3
BeginSegmentWithHeader creates a new Segment for a given name, context, and trace header. It is used for recovering the trace context. e.g. the receiver component of Amazon SQS. https://docs.aws.amazon.com/xray/latest/devguide/xray-services-sqs.html#xray-services-sqs-retrieving
Caller should close the segment when the work is done.
func BeginSegmentWithRequest ¶
func BeginSegmentWithRequest(ctx context.Context, name string, r *http.Request) (context.Context, *Segment)
BeginSegmentWithRequest creates a new Segment for a given name and context. The trace id is set by the x-amzn-trace-id header of the request.
Caller should close the segment when the work is done.
func BeginSubsegment ¶
BeginSubsegment creates a new Segment for a given name and context.
Caller should close the segment when the work is done.
func BeginSubsegmentAt ¶ added in v1.7.4
BeginSubsegmentAt creates a new Segment for a given time, name and context.
Caller should close the segment when the work is done.
func ContextSegment ¶
ContextSegment return the segment of current context.
func (*Segment) AddAnnotationBool ¶
AddAnnotationBool adds a boolean type annotation.
func (*Segment) AddAnnotationFloat64 ¶
AddAnnotationFloat64 adds a 64 bit integer type annotation.
func (*Segment) AddAnnotationInt64 ¶
AddAnnotationInt64 adds a 64 bit integer type annotation.
func (*Segment) AddAnnotationString ¶
AddAnnotationString adds a string type annotation.
func (*Segment) AddAnnotationUint64 ¶
AddAnnotationUint64 adds a 64 bit integer type annotation.
func (*Segment) AddMetadata ¶
AddMetadata adds metadata.
func (*Segment) AddMetadataToNamespace ¶
AddMetadataToNamespace adds metadata.
func (*Segment) SetAWS ¶
SetAWS sets the information about the AWS resource on which your application served the request.
func (*Segment) SetHTTPRequest ¶
func (seg *Segment) SetHTTPRequest(request *schema.HTTPRequest)
SetHTTPRequest sets the information of HTTP requests.
func (*Segment) SetHTTPResponse ¶
func (seg *Segment) SetHTTPResponse(response *schema.HTTPResponse)
SetHTTPResponse sets the information of HTTP requests.
func (*Segment) SetNamespace ¶
SetNamespace sets namespace
type StreamingStrategy ¶
StreamingStrategy provides an interface for implementing streaming strategies.
func NewStreamingStrategyBatchAll ¶
func NewStreamingStrategyBatchAll() StreamingStrategy
NewStreamingStrategyBatchAll returns a streaming strategy.
func NewStreamingStrategyLimitSubsegment ¶
func NewStreamingStrategyLimitSubsegment(limit int) StreamingStrategy
NewStreamingStrategyLimitSubsegment returns a streaming strategy.
type TestDaemon ¶
type TestDaemon struct { // ContextMissing is callback function for the context missing strategy. // If it is nil, ignore context missing errors. ContextMissing func(ctx context.Context, v any) // contains filtered or unexported fields }
TestDaemon is the mock server of AWS X-Ray daemon.
func NewTestDaemon ¶
func NewTestDaemon(handler http.Handler) (context.Context, *TestDaemon)
NewTestDaemon creates new TestDaemon
type TraceHeader ¶
type TraceHeader struct { TraceID string ParentID string SamplingDecision SamplingDecision AdditionalData map[string]string }
TraceHeader is the value of X-Amzn-Trace-Id.
func DownstreamHeader ¶
func DownstreamHeader(ctx context.Context) TraceHeader
DownstreamHeader returns a header for passing to downstream calls.
func ParseTraceHeader ¶
func ParseTraceHeader(s string) TraceHeader
ParseTraceHeader parses X-Amzn-Trace-Id header.
func (TraceHeader) String ¶
func (h TraceHeader) String() string
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package ctxmissing provides the context missing strategy.
|
Package ctxmissing provides the context missing strategy. |
Package sampling provides the sampling strategy.
|
Package sampling provides the sampling strategy. |
Package schema provides types for [AWS X-Ray Segment Documents].
|
Package schema provides types for [AWS X-Ray Segment Documents]. |
Package xraylog implements a logger with a log level, and an interface for a custom logger.
|
Package xraylog implements a logger with a log level, and an interface for a custom logger. |
Package xrayslog provides utilities for interfacing with the slog package.
|
Package xrayslog provides utilities for interfacing with the slog package. |