PaperTiger.TelemetryHandler (PaperTiger v0.7.0)

View Source

Handles telemetry events and creates Stripe events + delivers webhooks.

This module bridges the gap between resource operations and webhook delivery. When resources emit telemetry events (e.g., customer created), this handler:

  1. Creates a Stripe Event object
  2. Stores it in the Events store
  3. Delivers webhooks to registered endpoints

Event Naming Convention

Telemetry events follow the pattern: [:paper_tiger, :resource_type, :action]

Which maps to Stripe event types: resource_type.action (e.g., "customer.created")

For nested types like subscriptions: [:paper_tiger, :subscription, :created] -> "customer.subscription.created"

Summary

Functions

Attaches all telemetry handlers for PaperTiger events.

Detaches all telemetry handlers.

Handles a telemetry event by creating a Stripe event and delivering webhooks.

Functions

attach()

@spec attach() :: :ok

Attaches all telemetry handlers for PaperTiger events.

Call this during application startup.

detach()

@spec detach() :: :ok | {:error, :not_found}

Detaches all telemetry handlers.

Useful for testing or cleanup.

handle_event(event_name, measurements, metadata, config)

@spec handle_event(list(), map(), map(), any()) :: :ok

Handles a telemetry event by creating a Stripe event and delivering webhooks.