Skip to content

events: Add custom code for event ingestion#167

Open
Yopi wants to merge 1 commit intomainfrom
yopi/add-custom-span-api
Open

events: Add custom code for event ingestion#167
Yopi wants to merge 1 commit intomainfrom
yopi/add-custom-span-api

Conversation

@Yopi
Copy link
Contributor

@Yopi Yopi commented Mar 19, 2026

  • Adds syntactic sugar to ingest costs and llm metadata
  • Adds an easy way to ingest events and child-events (as spans)

- Adds syntactic sugar to ingest costs and llm metadata
- Adds an easy way to ingest events and child-events (as spans)
@Yopi
Copy link
Contributor Author

Yopi commented Mar 19, 2026

  // Raw API - existing
  await polar.events.ingest({ events: [{ name: "evt", customerId: "c_1", metadata: { "_cost": { amount: 100, currency: "usd" } } }] });

  // Sugar - enriches cost/llm into metadata automatically
  await polar.events.sendEvents([
    { name: "evt", externalCustomerId: "user_123", cost: { amount: 100, currency: "usd" }, llm: { ... } },
  ]);

  // Span - creates parent, returns client that auto-applies parentId + customer
  const span = await polar.events.withSpan({ name: "request", externalId: "req_1", externalCustomerId: "user_123" });
  await span.sendEvents([
    { name: "child.step", cost: { amount: 50, currency: "usd" } },
  ]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant