-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsqs_example_test.go
51 lines (43 loc) · 1.57 KB
/
sqs_example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package awshoney_test
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/glassechidna/awsctx/service/sqsctx"
"github.com/glassechidna/awshoney"
"github.com/honeycombio/beeline-go"
"github.com/honeycombio/beeline-go/propagation"
)
func ExampleSqs() {
// obviously it won't be too helpful if you do this. you'd want to
// pass in a context from a real span
ctx, _ := beeline.StartSpan(context.Background(), "example")
sess := session.Must(session.NewSession())
baseApi := sqs.New(sess)
api := sqsctx.New(baseApi, awshoney.Contexter)
// the other methods that aren't WithContext won't pass through
// the honeycomb trace id
_, _ = api.SendMessageWithContext(ctx, &sqs.SendMessageInput{
QueueUrl: aws.String("queue-url"),
MessageBody: aws.String("body"),
})
// the other methods that aren't WithContext won't pass through
// the honeycomb trace id
_, _ = api.SendMessageBatchWithContext(ctx, &sqs.SendMessageBatchInput{
QueueUrl: aws.String("queue-url"),
Entries: []*sqs.SendMessageBatchRequestEntry{
{
MessageBody: aws.String("body"),
},
},
})
// you don't need to use the &awshoney.Sqs{} wrapper here (but it won't hurt)
resp, _ := baseApi.ReceiveMessage(&sqs.ReceiveMessageInput{
QueueUrl: aws.String("queue-url"),
// by default sqs won't retrieve message attributes
MessageAttributeNames: []*string{aws.String(propagation.TracePropagationHTTPHeader)},
})
msg := resp.Messages[0]
ctx, _ = awshoney.StartSpanFromSqs(context.Background(), msg)
}