Skip to content

Commit

Permalink
Inject returns error on max attr limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
udhos committed Nov 2, 2023
1 parent 69e8da9 commit 0cb2897
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions otelsqs/otelsqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ package otelsqs

import (
"context"
"fmt"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
Expand Down Expand Up @@ -134,18 +135,22 @@ func (c *SqsCarrierAttributes) Extract(ctx context.Context, messageAttributes ma
return c.propagator.Extract(ctx, c)
}

var ErrMaxAttrLimit = fmt.Errorf("max attribute limit reached") // ErrMaxAttrLimit signals max attribute limit reached.

// Inject inserts tracing from context into the SQS message attributes.
// `ctx` holds current context with trace information.
// `messageAttributes` should point to outgoing SQS message MessageAttributes which will carry the trace information.
// `messageAttributes` must not be nil.
// If `messageAttributes` holds 10 or more items, Inject will do nothing, since SQS refuses messages with more than 10 attributes.
// If `messageAttributes` holds 10 or more items, Inject will do nothing and return ErrMaxAttrLimit,
// since SQS refuses messages with more than 10 attributes.
// Use Inject right before sending out the SQS message.
func (c *SqsCarrierAttributes) Inject(ctx context.Context, messageAttributes map[string]types.MessageAttributeValue) {
func (c *SqsCarrierAttributes) Inject(ctx context.Context, messageAttributes map[string]types.MessageAttributeValue) error {
if len(messageAttributes) >= sqsMessageAttributeLimit {
return
return ErrMaxAttrLimit
}
c.attach(messageAttributes)
c.propagator.Inject(ctx, c)
return nil
}

// Get returns the value for the key.
Expand Down

0 comments on commit 0cb2897

Please sign in to comment.