awsxray

package module
v0.0.0-...-0d8a60b Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2016 License: Apache-2.0 Imports: 9 Imported by: 63

README

Go AWS X-Ray License GoDoc

Go AWS X-Ray is a library to help simplify usage of AWS X-Ray for Micro

Usage

// create xray client
xray := awsxray.New(
        // Specify X-Ray Daemon Address
        awsxray.WithDaemon("localhost:2000"),
        // Or X-Ray Client
        awsxray.WithClient(xray.New(awsSession)),
)

// create segment
segment := &awsxray.Segment{
	Name: ...
	Id: ...
	TraceId: ...
	// more values
}

xray.Record(segment)
With Wrappers

Wrappers scope the library for simplified use

import "github.com/micro/go-plugins/wrapper/trace/awsxray"

opts := []awsxray.Option{
	// Used as segment name
	awsxray.WithName("go.micro.srv.greeter"),
	// Specify X-Ray Daemon Address
	awsxray.WithDaemon("localhost:2000"),
	// Or X-Ray Client
	awsxray.WithClient(xray.New(awsSession)),
}

service := micro.NewService(
	micro.Name("go.micro.srv.greeter"),
	micro.WrapCall(awsxray.NewCallWrapper(opts...)),
	micro.WrapClient(awsxray.NewClientWrapper(opts...)),
	micro.WrapHandler(awsxray.NewHandlerWrapper(opts...)),
)
With Toolkit

Register the plugin before building Micro

package main

import (
	"github.com/micro/micro/plugin"
	"github.com/aws/aws-sdk-go/service/xray"
	"github.com/micro/go-plugins/micro/trace/awsxray"
)

func init() {
	plugin.Register(awsxray.NewXRayPlugin(
		// Used as segment name
		awsxray.WithName("go.micro.http"),
		// Specify X-Ray Daemon Address
		awsxray.WithDaemon("localhost:2000"),
		// Or X-Ray Client
		awsxray.WithClient(xray.New(awsSession)),
	))
}

Example

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TraceHeader = "X-Amzn-Trace-Id"
)

Functions

func GetParentId

func GetParentId(header string) string

GetParentId returns parent id from header or blank

func GetTraceId

func GetTraceId(header string) string

GetTraceId returns trace id from header or blank

func NewContext

func NewContext(ctx context.Context, s *Segment) context.Context

func SetParentId

func SetParentId(header, parentId string) string

SetParentId will set the parent id of a trace in the header

func SetTraceId

func SetTraceId(header, traceId string) string

SetTraceId will set the trace id in the header

Types

type AWSXRay

type AWSXRay struct {
	Options Options
}

func New

func New(opts ...Option) *AWSXRay

func (*AWSXRay) Record

func (x *AWSXRay) Record(s *Segment) error

type HTTP

type HTTP struct {
	Request  *Request  `json:"request,omitempty"`
	Response *Response `json:"response,omitempty"`
}

type Option

type Option func(o *Options)

func WithClient

func WithClient(x *xray.XRay) Option

WithClient sets the XRay Client to use to send segments

func WithDaemon

func WithDaemon(addr string) Option

WithDaemon sets the address of the XRay Daemon to send segements

type Options

type Options struct {
	// XRay Client when using API
	Client *xray.XRay
	// Daemon address when using UDP
	Daemon string
}

type Request

type Request struct {
	Method    string `json:"method,omitempty"`
	URL       string `json:"url,omitempty"`
	UserAgent string `json:"user_agent,omitempty"`
	ClientIP  string `json:"client_ip,omitempty"`
}

type Response

type Response struct {
	Status int `json:"status,omitempty"`
}

type Segment

type Segment struct {
	// user expected to protect changes
	sync.RWMutex
	Name      string  `json:"name,omitempty"`
	Type      string  `json:"type,omitempty"`
	Id        string  `json:"id,omitempty"`
	TraceId   string  `json:"trace_id,omitempty"`
	ParentId  string  `json:"parent_id,omitempty"`
	StartTime float64 `json:"start_time,omitempty"`
	EndTime   float64 `json:"end_time,omitempty"`
	HTTP      *HTTP   `json:"http,omitempty"`
	Error     bool    `json:"error,omitempty"`
	Fault     bool    `json:"fault,omitempty"`
}

func FromContext

func FromContext(ctx context.Context) (*Segment, bool)

Jump to

Keyboard shortcuts

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