Skip to content

Commit

Permalink
Adding LoadOptionsFunc implementation
Browse files Browse the repository at this point in the history
- addresses #2094
  • Loading branch information
dcarbone committed Jul 5, 2023
1 parent c10c902 commit 3eae656
Show file tree
Hide file tree
Showing 3 changed files with 622 additions and 676 deletions.
27 changes: 23 additions & 4 deletions contrib/aws/aws-sdk-go-v2/aws/aws.go
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
awsconfig "github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/eventbridge"
"github.com/aws/aws-sdk-go-v2/service/kinesis"
Expand Down Expand Up @@ -62,18 +63,36 @@ const (

type spanTimestampKey struct{}

// 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.
func AppendMiddleware(awsCfg *aws.Config, opts ...Option) {
func prepConfig(opts ...Option) *config {
cfg := &config{}

defaults(cfg)
for _, opt := range opts {
opt(cfg)
}

return cfg
}

func appendMiddleware(cfg *config, opts *[]func(*middleware.Stack) error) {
tm := traceMiddleware{cfg: cfg}
awsCfg.APIOptions = append(awsCfg.APIOptions, tm.initTraceMiddleware, tm.startTraceMiddleware, tm.deserializeTraceMiddleware)
*opts = append(*opts, tm.initTraceMiddleware, tm.startTraceMiddleware, tm.deserializeTraceMiddleware)
}

// WithDataDogTracer returns an AWS config LoadOptionsFunc that adds the DataDog tracing middleware into the
// APIOptions middleware stack.
// See https://aws.github.io/aws-sdk-go-v2/docs/middleware for more information.
func WithDataDogTracer(opts ...Option) awsconfig.LoadOptionsFunc {
return func(awsOpt *awsconfig.LoadOptions) error {
appendMiddleware(prepConfig(opts...), &awsOpt.APIOptions)
return nil
}
}

// 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.
func AppendMiddleware(awsCfg *aws.Config, opts ...Option) {
appendMiddleware(prepConfig(opts...), &awsCfg.APIOptions)
}

type traceMiddleware struct {
Expand Down

0 comments on commit 3eae656

Please sign in to comment.