otelsns

package
v1.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 6 Imported by: 3

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

Constants

This section is empty.

Variables

View Source
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

WithPropagator sets propagator for carrier. If unspecified, carrier uses default propagator defined with SetTextMapPropagator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL