pubsub

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MessageAttributesParamKey is the agreed-upon params map
	// key that carries message-level metadata between the
	// instrumented wrapper and the in-repo publishers. The
	// value type is map[string]string; publishers convert
	// those string pairs into their native per-system
	// representation (e.g. SNS MessageAttributeValue with
	// DataType="String"). Callers may also populate this key
	// directly to supply their own attributes.
	MessageAttributesParamKey = "MessageAttributes"
)

Metric + label names, kept in sync with observability/builtins.go. Redeclared here to avoid an import cycle (observability depends on pubsub transitively through the instrumented wrapper's lookup of telemetry.Global()).

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextualPublisher added in v0.17.0

type ContextualPublisher interface {
	Publisher
	PublishContext(ctx context.Context, topic, message string, params map[string]any) error
}

ContextualPublisher is an extension interface that adds a context-aware sibling to Publisher.Publish. Publishers shipped in the magic repository implement both interfaces; the non-Context method delegates to PublishContext with context.Background(). Third-party publishers are free to implement only Publisher, in which case the instrumented wrapper falls back to metrics-only coverage.

PublishContext receives the caller's context so that:

  • the SDK honors the context's deadline / cancellation
  • the wrapper can start a child span on that context
  • trace propagation headers produced from the span context are injected into the outbound message metadata via the standard propagator

type Publisher

type Publisher interface {
	Publish(topic string, message string, params map[string]any) error
}

type PublisherFactory

type PublisherFactory struct{}

func (PublisherFactory) GetInstance

func (s PublisherFactory) GetInstance(publisherType PublisherType, config any) (Publisher, error)

GetInstance constructs the requested publisher and wraps it with the telemetry-aware instrumentation adapter. When the observability stack has not been initialized the wrapper uses no-op instruments and adds negligible overhead; when it has, the wrapper emits a `pubsub.publish` producer span, injects W3C trace context into outbound message metadata, and records the built-in pubsub metrics.

type PublisherType

type PublisherType string
const (
	SNS PublisherType = "sns"
)

type SNSPublisher

type SNSPublisher struct {
	Client *sns.Client
	// contains filtered or unexported fields
}

func GetSNSPublisher

func GetSNSPublisher(config map[string]string) *SNSPublisher

func (*SNSPublisher) Publish

func (s *SNSPublisher) Publish(topic string, message string, params map[string]any) error

Publish delegates to PublishContext with context.Background so non-context-aware callers still get the full publish path.

func (*SNSPublisher) PublishContext added in v0.17.0

func (s *SNSPublisher) PublishContext(ctx context.Context, topic string, message string, params map[string]any) error

PublishContext sends a single message to an SNS topic, honoring the caller's context for deadline/cancellation propagation and merging any wrapper-injected trace attributes from params[MessageAttributesParamKey] into the SDK's MessageAttributes. Existing filterKey/filterValue support is preserved so calling conventions for older code paths continue to work.

Jump to

Keyboard shortcuts

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