Documentation ¶
Overview ¶
Package otelsns implements carrier for SNS.
Usage ¶
Use `SnsCarrierAttributes.Inject` to inject trace context into SNS publishing.
import ( "github.com/aws/aws-sdk-go-v2/service/sns" "github.com/aws/aws-sdk-go-v2/service/sns/types" "github.com/udhos/opentelemetry-trace-sqs/otelsns" ) // publish is an example function that uses SnsCarrierAttributes.Inject to // propagate tracing context with SNS publishing. // 'ctx' holds current tracing context. func publish(ctx context.Context, topicArn, msg string) { input := &sns.PublishInput{ TopicArn: aws.String(topicArn), Message: aws.String(msg), MessageAttributes: make(map[string]types.MessageAttributeValue), } // Inject the tracing context if errInject := otelsns.NewCarrier().Inject(ctx, input.MessageAttributes); errInject != nil { log.Printf("inject error: %v", errInject) } // Now invoke SNS publish for input
Index ¶
- Variables
- func SetTextMapPropagator(propagator propagation.TextMapPropagator)
- type SnsCarrierAttributes
- func (c *SnsCarrierAttributes) Get(key string) string
- func (c *SnsCarrierAttributes) Inject(ctx context.Context, messageAttributes map[string]types.MessageAttributeValue) error
- func (c *SnsCarrierAttributes) Keys() []string
- func (c *SnsCarrierAttributes) Set(key, value string)
- func (c *SnsCarrierAttributes) WithPropagator(propagator propagation.TextMapPropagator) *SnsCarrierAttributes
Constants ¶
This section is empty.
Variables ¶
var ErrMessageAttributesIsNil = errors.New("message attributes is nil")
ErrMessageAttributesIsNil rejects nil message attributes.
Functions ¶
func SetTextMapPropagator ¶
func SetTextMapPropagator(propagator propagation.TextMapPropagator)
SetTextMapPropagator optionally replaces the default propagator (B3 with single header). Please notice that SNS only supports up to 10 attributes, then be careful when picking another propagator that might consume multiple attributes.
Types ¶
type SnsCarrierAttributes ¶
type SnsCarrierAttributes struct {
// contains filtered or unexported fields
}
SnsCarrierAttributes is a message attribute carrier for SNS. https://pkg.go.dev/go.opentelemetry.io/otel/propagation#TextMapCarrier
func NewCarrier ¶ added in v1.0.0
func NewCarrier() *SnsCarrierAttributes
NewCarrier creates a carrier for SNS.
func (*SnsCarrierAttributes) Get ¶
func (c *SnsCarrierAttributes) Get(key string) string
Get returns the value for the key.
func (*SnsCarrierAttributes) Inject ¶ added in v1.0.0
func (c *SnsCarrierAttributes) Inject(ctx context.Context, messageAttributes map[string]types.MessageAttributeValue) error
Inject inserts tracing from context into the SNS message attributes. `ctx` holds current context with trace information. `messageAttributes` should point to outgoing SNS publish MessageAttributes which will carry the trace information. If `messageAttributes` is nil, error ErrMessageAttributesIsNil will be returned. Use Inject right before publishing out to SNS.
func (*SnsCarrierAttributes) Keys ¶
func (c *SnsCarrierAttributes) Keys() []string
Keys lists the keys in the carrier.
func (*SnsCarrierAttributes) Set ¶
func (c *SnsCarrierAttributes) Set(key, value string)
Set stores a key-value pair.
func (*SnsCarrierAttributes) WithPropagator ¶ added in v1.0.2
func (c *SnsCarrierAttributes) WithPropagator(propagator propagation.TextMapPropagator) *SnsCarrierAttributes
WithPropagator sets propagator for carrier. If unspecified, carrier uses default propagator defined with SetTextMapPropagator.