multisource

package
v9.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SourcePropertyKey is the event property used to identify the analytics source (e.g. ios, web).
	// For PostHog, where a single API key is shared across sources, this property distinguishes events.
	SourcePropertyKey = "source"
)

Variables

This section is empty.

Functions

func RegisterMultiSourceEventReporter

func RegisterMultiSourceEventReporter(i do.Injector)

RegisterMultiSourceEventReporter registers a *MultiSourceEventReporter with the injector. Prerequisite: map[string]*analyticscfg.SourceConfig must be registered in the injector.

Types

type MultiSourceEventReporter

type MultiSourceEventReporter struct {
	// contains filtered or unexported fields
}

MultiSourceEventReporter delegates events to per-source EventReporters. The reporters map is populated at construction and never mutated afterwards, so reads need no synchronization.

func NewMultiSourceEventReporter

func NewMultiSourceEventReporter(reporters map[string]analytics.EventReporter, opts ...Option) *MultiSourceEventReporter

NewMultiSourceEventReporter returns a new MultiSourceEventReporter.

func NewMultiSourceEventReporterFromConfig

func NewMultiSourceEventReporterFromConfig(
	ctx context.Context,
	proxySources map[string]*analyticscfg.SourceConfig,
	opts ...Option,
) (*MultiSourceEventReporter, error)

NewMultiSourceEventReporterFromConfig builds a MultiSourceEventReporter from proxy sources config. For each source, attempts to create an EventReporter via NewCollector. If creation fails (e.g. missing credentials) or provider is unset, uses Noop for that source.

For PostHog: reporters are deduplicated by API key. Sources sharing the same PostHog API key reuse a single client (the source name is set as a property on each event), while sources with distinct API keys each get their own client so their credentials and circuit breaker are honored.

func (*MultiSourceEventReporter) AddUser

func (m *MultiSourceEventReporter) AddUser(ctx context.Context, source, userID string, properties map[string]any) error

AddUser identifies a user against the reporter for the given source, forwarding the user's traits. Every underlying reporter supports identify via analytics.EventReporter.AddUser.

func (*MultiSourceEventReporter) Close

Close flushes and closes every underlying reporter. Reporters shared across multiple sources (e.g. PostHog sources with the same API key) are closed exactly once.

func (*MultiSourceEventReporter) Shutdown

func (m *MultiSourceEventReporter) Shutdown(ctx context.Context) error

Shutdown implements do.Shutdowner so the DI container flushes buffered events on shutdown, and reports a failed final flush rather than swallowing it.

func (*MultiSourceEventReporter) TrackAnonymousEvent

func (m *MultiSourceEventReporter) TrackAnonymousEvent(ctx context.Context, source, event, anonymousID string, properties map[string]any) error

TrackAnonymousEvent records an event for an anonymous user.

func (*MultiSourceEventReporter) TrackEvent

func (m *MultiSourceEventReporter) TrackEvent(ctx context.Context, source, event, userID string, properties map[string]any) error

TrackEvent records an event for an identified user.

type Option

type Option func(*options)

Option configures the reporters this package constructs. The zero configuration works: an absent logger logs nowhere, an absent tracer provider traces nowhere, and an absent metrics provider records nothing.

func WithLogger

func WithLogger(logger logging.Logger) Option

WithLogger attaches a logger.

func WithMetricsProvider

func WithMetricsProvider(metricsProvider metrics.Provider) Option

WithMetricsProvider attaches a metrics provider, passed through to the per-source reporters built from config.

func WithTracerProvider

func WithTracerProvider(tracerProvider tracing.TracerProvider) Option

WithTracerProvider attaches a tracer provider, enabling spans on every event.

Jump to

Keyboard shortcuts

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