Skip to main content

Usage events

This document explains what a usage event is, how usage-event collections, data schemas, and API slugs shape usage events, and the ways that usage events reach Zenskar, including S3 ingestion.

This conceptual diagram shows what a usage-event collection has: a data schema with root fields and data fields, and an API slug.

Usage events: records of product consumption

A usage event is a record of product consumption by a customer at one point in time, stored in a usage-event collection. A usage event can record a single action, such as one API call. It can also record an amount at one moment, such as the number of seats in use. A usage-event collection is a named set of usage events of one kind, with one data schema and one API slug. Each usage event belongs to one usage-event collection. It has the fields that the data schema of its usage-event collection lists. A usage-event collection holds one kind of consumption, such as API calls or storage used. A usage-event collection must exist before it can receive usage events. The name of a usage-event collection cannot change after the usage-event collection is created. Two usage-event collections can have the same name. Zenskar keeps each usage event as it arrives. A usage event cannot be edited or deleted. A usage-event collection cannot be deleted.

Create a usage-event collection

This guide shows how to create a usage-event collection with its data schema and API slug.

Data schemas: the shape of every usage event

A data schema is the structure that every usage event of a usage-event collection follows: two root fields, and a nested data object that holds the data fields. Each usage-event collection has one data schema. The following usage event has both root fields and two data fields:

Root fields

A root field is a field that Zenskar requires at the top level of every usage event: customer_id or timestamp. customer_id identifies the customer of the usage event. It is always a String. A billable metric matches its value to a customer in Zenskar. timestamp is the moment of the consumption. It is always a DateTime64. Zenskar orders the usage events of a usage-event collection by timestamp.

Data fields

A data field is a named value with one data type, inside the data object of a usage event. Data fields hold the details of the consumption, such as the endpoint of an API call or the size of a file. Each data field has one of the following data types. The examples use the formats that the API accepts. A space in the name of a data field becomes an underscore. Two data fields of one data schema cannot have the same name. A data field can be added to a data schema after the usage-event collection is created. A data field cannot be removed or renamed. The data type of a data field cannot change.

Add a data field

This guide shows how to add a data field to an existing usage-event collection.

API slugs: where usage events are delivered

This conceptual diagram shows how a usage event sent through the API reaches its usage-event collection.

An API slug is the identifier of a usage-event collection in its API slug endpoint. The API slug endpoint is the web address to which the usage events of a usage-event collection are delivered. It is https://api.zenskar.com/usage/ followed by the API slug. For the API slug api_calls, the API slug endpoint is https://api.zenskar.com/usage/api_calls. A usage event sent to this API slug endpoint goes to that usage-event collection. Each request carries an API key of the organization. See API keys. By default, the API slug follows the name of the usage-event collection. The API slug is in lowercase. Each space in the name becomes an underscore. A different API slug can be chosen when the usage-event collection is created. An API slug starts and ends with a letter or a digit. In between, it can also contain underscores and hyphens. The API slug is unique in the organization. It tells apart two usage-event collections that have the same name. A query of a billable metric names a usage-event collection by its API slug. The API slug cannot change after the usage-event collection is created.

Ways to send usage events

Usage events reach a usage-event collection in four ways. All four ways store usage events in the same usage-event collection. A billable metric reads them in the same way.

Upload usage events from a CSV file

This guide shows how to upload a CSV file of usage events.

Add a single usage event

This guide shows how to add one usage event.

Send usage events through the API

This guide shows how to send usage events to the API slug endpoint.
Usage can also stay in your own database. A data source then lets a billable metric read it there.

S3 ingestion: usage events from files in Amazon S3

S3 ingestion reads usage events from CSV files in an Amazon S3 bucket of the organization. Each usage-event collection has its own folder in the bucket.

S3 ingestion

This document explains the bucket connection, the ingestion-error bucket, the folders of usage-event collections, and the files that S3 ingestion reads.