-
Notifications
You must be signed in to change notification settings - Fork 419
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/aws, aws-sdk-go-v2/aws}: add context example #1504
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6ea14ac
contrib/aws/{aws-sdk-go/aws, aws-sdk-go-v2/aws}: add context example
mackjmr 7cc5f9d
move example to package godoc to avoid adding dependencies into go.mod
mackjmr 96d0731
add empty line
mackjmr 0c54422
add comment
mackjmr 581d34a
Merge branch 'main' into mackjmr/add-aws-sdk-go-context-example
mackjmr c5c5b20
move example to doc.go
mackjmr fa7023b
Merge branch 'mackjmr/add-aws-sdk-go-context-example' of github.com:D…
mackjmr 86f0ad3
add empty line
mackjmr 0659d6b
Merge branch 'main' into mackjmr/add-aws-sdk-go-context-example
mackjmr 71f44a7
run linters
mackjmr bec66de
Merge branch 'main' into mackjmr/add-aws-sdk-go-context-example
katiehockman 49af267
Merge branch 'main' into mackjmr/add-aws-sdk-go-context-example
katiehockman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016 Datadog, Inc. | ||
|
||
// 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 "gopkg.in/DataDog/dd-trace-go.v1/contrib/aws/aws-sdk-go-v2/aws" | ||
// "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext" | ||
// "gopkg.in/DataDog/dd-trace-go.v1/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) | ||
// } | ||
// } | ||
package aws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is just a copy of the example we already have in
example_test
, then I'm not sure it adds too much extra value. I'm not sure if @ajgajg1134 was suggesting this during his last comment, or if he was suggesting something else...I'd personally just remove this but keep the example code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func Example
is a copy fromexample_test
, butfunc Example_context
was added, which is an example that demonstrate how to pass context.The reason we moved all of this out of from example_test is to avoid adding entries to the
go.mod
that are necessary forfunc Example_context
(forgithub.com/aws/aws-sdk-go-v2/feature/s3/manager
andgithub.com/aws/aws-sdk-go-v2/service/s3
)