Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib/aws/aws-sdk-go-v2/aws: Adding LoadOptionsFunc implementation #2095

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 23 additions & 4 deletions contrib/aws/aws-sdk-go-v2/aws/aws.go
Expand Up @@ -23,6 +23,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 All @@ -43,18 +44,36 @@ func init() {

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