aws

package
v0.0.0-...-2b7dcb4 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Starts a span and adds it to the request context.
	StartHandler = request.NamedHandler{
		Name: "opentracing.Start",
		Fn: func(r *request.Request) {
			_, ctx := opentracing.StartSpanFromContext(r.Context(), "client.request")
			r.SetContext(ctx)
		},
	}

	// Adds information about the request to the span.
	RequestInfoHandler = request.NamedHandler{
		Name: "opentracing.RequestInfo",
		Fn: func(r *request.Request) {
			span := opentracing.SpanFromContext(r.Context())
			span.SetTag("service.name", fmt.Sprintf("aws.%s", r.ClientInfo.ServiceName))
			span.SetTag("resource.name", r.Operation.Name)
			span.SetTag("http.method", r.Operation.HTTPMethod)
			span.SetTag("http.url", r.ClientInfo.Endpoint+r.Operation.HTTPPath)
			span.SetTag("out.host", r.ClientInfo.Endpoint)
			span.SetTag("aws.operation", r.Operation.Name)
		},
	}

	// Finishes the span.
	FinishHandler = request.NamedHandler{
		Name: "opentracing.Finish",
		Fn: func(r *request.Request) {
			span := opentracing.SpanFromContext(r.Context())
			span.SetTag("aws.retry_count", fmt.Sprintf("%d", r.RetryCount))

			if r.HTTPResponse != nil {
				span.SetTag("http.status_code", fmt.Sprintf("%d", r.HTTPResponse.StatusCode))
			}

			if r.Error != nil {
				span.SetTag(dd_ext.Error, r.Error)
				if _, ok := r.Error.(fmt.Formatter); ok {
					span.SetTag(dd_ext.ErrorStack, fmt.Sprintf("%+v", r.Error))
				}
				if err, ok := r.Error.(awserr.Error); ok {
					span.SetTag("aws.err.code", fmt.Sprintf("%s", err.Code()))
				}
			}

			span.Finish()
		},
	}

	// DynamoDBInfoHandler adds extra information to the span for requests
	// to DynamoDB.
	DynamoDBInfoHandler = request.NamedHandler{
		Name: "opentracing.DynamoDB",
		Fn: func(r *request.Request) {

			if r.ClientInfo.ServiceName != dynamodb.ServiceName {
				return
			}

			tableName := dynamoDBTableName(r)
			if tableName == nil {
				return
			}

			span := opentracing.SpanFromContext(r.Context())
			span.SetOperationName(r.Operation.Name)
			span.SetTag("span.type", "db")
			span.SetTag("resource.name", *tableName)
			span.SetTag("aws.dynamodb.table", *tableName)
		},
	}
)

Functions

func WithTracing

func WithTracing(s *session.Session)

WithTracing adds the necessary request handlers to an AWS session.Session object to enable tracing with opentracing.

Types

type Option

type Option func(opentracing.Span, *request.Request, error)

Option is a hook for adding span tags.

type Tracer

type Tracer struct {
	Opts []Option
}

Tracer holds tagging options for request tracing.

func New

func New(opts ...Option) *Tracer

New returns a new AWS request tracer with default tagging.

func (*Tracer) Send

func (t *Tracer) Send(ctx context.Context, r *request.Request, opts ...Option) error

Send wraps the aws request with an opentracing span.

req, output := dynamoClient.PutItemRequest(input) err := t.Send(ctx, req)

Jump to

Keyboard shortcuts

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