aws

package
v0.0.0-...-7ebff8f Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0, BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package aws provides functions to trace aws/aws-sdk-go-v2 (https://github.com/aws/aws-sdk-go-v2).

Usage Example:

import (
	"context"
	"log"
	"os"

	"github.com/aws/aws-sdk-go-v2/aws"
	awscfg "github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
	"github.com/aws/aws-sdk-go-v2/service/s3"
	"github.com/aws/aws-sdk-go-v2/service/sqs"

	awstrace "github.com/DataDog/dd-trace-go/v2/contrib/aws/aws-sdk-go-v2/aws"
	"github.com/DataDog/dd-trace-go/v2/ddtrace/ext"
	"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
)

func Example() {
	awsCfg, err := awscfg.LoadDefaultConfig(context.Background())
	if err != nil {
		log.Fatalf(err.Error())
	}
	awstrace.AppendMiddleware(&awsCfg)
	sqsClient := sqs.NewFromConfig(awsCfg)
	sqsClient.ListQueues(context.Background(), &sqs.ListQueuesInput{})
}

// An example of the aws span inheriting a parent span from context.
func Example_context() {
	cfg, err := awscfg.LoadDefaultConfig(context.TODO(), awscfg.WithRegion("us-west-2"))
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	awstrace.AppendMiddleware(&cfg)
	client := s3.NewFromConfig(cfg)
	uploader := manager.NewUploader(client)

	// Create a root span.
	span, ctx := tracer.StartSpanFromContext(context.Background(), "parent.request",
		tracer.SpanType(ext.SpanTypeWeb),
		tracer.ServiceName("web"),
		tracer.ResourceName("/upload"),
	)
	defer span.Finish()

	// Open image file.
	filename := "my_image.png"
	file, err := os.Open(filename)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	defer file.Close()

	uploadParams := &s3.PutObjectInput{
		Bucket:      aws.String("my_bucket"),
		Key:         aws.String(filename),
		Body:        file,
		ContentType: aws.String("image/png"),
	}
	// Inherit parent span from context.
	_, err = uploader.Upload(ctx, uploadParams)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendMiddleware

func AppendMiddleware(awsCfg *aws.Config, opts ...Option)

AppendMiddleware takes the aws.Config and adds the Datadog tracing middleware into the APIOptions middleware stack. See https://aws.github.io/aws-sdk-go-v2/docs/middleware for more information.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option describes options for the AWS integration.

type OptionFn

type OptionFn func(*config)

OptionFn represents options applicable to AppendMiddleware.

func WithAnalytics

func WithAnalytics(on bool) OptionFn

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate

func WithAnalyticsRate(rate float64) OptionFn

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithErrorCheck

func WithErrorCheck(fn func(err error) bool) OptionFn

WithErrorCheck specifies a function fn which determines whether the passed error should be marked as an error. The fn is called whenever an aws operation finishes with an error.

func WithService

func WithService(name string) OptionFn

WithService sets the given service name for the dialled connection. When the service name is not explicitly set it will be inferred based on the request to AWS.

Jump to

Keyboard shortcuts

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