Build Status GoDoc

aws package defines an exporter that publishes spans to AWS X-Ray.


go get
To Do
  • Publish spans in a separate goroutine
  • Support propagation of http spans
  • Support remote spans
  • Verified works with ELB/ALB
  • Report errors / exceptions
  • Publish partial segments; currently only completed segments are published to aws
Expand ▾ Collapse ▴



    Package aws provides Exporter support for AWS XRay for traces.



    View Source
    const (
    	// OriginEC2 span originated from EC2
    	OriginEC2 origin = "AWS::EC2::Instance"
    	// OriginECS span originated from Elastic Container Service (ECS)
    	OriginECS origin = "AWS::ECS::Container"
    	// OriginEB span originated from Elastic Beanstalk (EB)
    	OriginEB origin = "AWS::ElasticBeanstalk::Environment"


    This section is empty.


    func ParseTraceHeader

    func ParseTraceHeader(header string) (trace.SpanContext, bool)

      ParseTraceHeader parses an Amazon trace header to OpenCensus span context.

      func TraceHeader

      func TraceHeader(sc trace.SpanContext) string

        TraceHeader converts an OpenCensus span context to AWS X-Ray trace header.


        type Exporter

        type Exporter struct {
        	// contains filtered or unexported fields

          Exporter is an implementation of trace.Exporter that uploads spans to AWS XRay

          func NewExporter

          func NewExporter(opts ...Option) (*Exporter, error)

            NewExporter returns an implementation of trace.Exporter that uploads spans to AWS X-Ray

            func (*Exporter) Close

            func (e *Exporter) Close() error

              Close this exporter and publish any spans that may have been buffered

              func (*Exporter) ExportSpan

              func (e *Exporter) ExportSpan(s *trace.SpanData)

                ExportSpan exports a span to AWS X-Ray

                func (*Exporter) Flush

                func (e *Exporter) Flush()

                type HTTPFormat

                type HTTPFormat struct{}

                  HTTPFormat implements propagation.HTTPFormat to propagate traces in HTTP headers for for Amazon services: ELB, ALB, Lambda, etc.

                  func (*HTTPFormat) SpanContextFromRequest

                  func (f *HTTPFormat) SpanContextFromRequest(req *http.Request) (sc trace.SpanContext, ok bool)

                    SpanContextFromRequest extracts an AWS X-Ray Trace span context from incoming requests.

                    func (*HTTPFormat) SpanContextToRequest

                    func (f *HTTPFormat) SpanContextToRequest(sc trace.SpanContext, req *http.Request)

                      SpanContextToRequest modifies the given request to include a AWS X-Ray trace header.

                      type OnExport

                      type OnExport struct {
                      	// TraceID holds the raw aws traceID e.g. 1-581cf771-a006649127e371903a2de979
                      	TraceID string

                        OnExport structure passed when a root segment is published

                        type Option

                        type Option interface {
                        	// contains filtered or unexported methods

                        func WithAPI

                        func WithAPI(api xrayiface.XRayAPI) Option

                          WithAPI - optional manually constructed api instance

                          func WithBlacklist

                          func WithBlacklist(blacklist []*regexp.Regexp) Option

                            WithBlacklist filters out the spans those names match one of the given regexps.

                            func WithBufferSize

                            func WithBufferSize(bufferSize int) Option

                              WithBufferSize - specifies the maximum number of spans to buffer before publishing them; defaults to 100

                              func WithInterval

                              func WithInterval(interval time.Duration) Option

                                WithInterval - specifies longest time before buffered spans are published; defaults to 1s

                                func WithOnExport

                                func WithOnExport(fn func(OnExport)) Option

                                  WithOnExport - function to be called when spans are published to AWS; useful if you would like the traceID used for AWS

                                  func WithOrigin

                                  func WithOrigin(origin origin) Option

                                    WithOrigin - specifies the aws origin of the span; currently supported are OriginEC2, OriginECS, and OriginEB

                                    func WithOutput

                                    func WithOutput(w io.Writer) Option

                                      WithOutput - optional writer for error messages

                                      func WithRegion

                                      func WithRegion(region string) Option

                                        WithRegion - optional aws region to send xray messages to

                                        func WithServiceName

                                        func WithServiceName(name string) Option

                                          WithServiceName - specifies the service name the exporter will report to xray

                                          func WithVersion

                                          func WithVersion(version string) Option

                                            WithVersion - specifies the version of the application running


                                            Path Synopsis
                                            Command xray is an example program that creates spans and uploads to AWS X-Ray.
                                            Command xray is an example program that creates spans and uploads to AWS X-Ray.