generated from mintlify/starter
-
Notifications
You must be signed in to change notification settings - Fork 25
advanced event filtering in usage based billing guide #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Muhammad-Owais-Warsi
wants to merge
2
commits into
dodopayments:main
Choose a base branch
from
Muhammad-Owais-Warsi:advanced-event-filtering
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
187 changes: 187 additions & 0 deletions
187
developer-resources/event-filtering-usage-based-billing.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| --- | ||
| title: Advanced Event Filtering in Usage Based Billing. | ||
| description: This guide demonstrates how to implement advanced event fltering in Usage Based Billing. | ||
| icon: "credit-card" | ||
| --- | ||
|
|
||
|
|
||
| ## Creating a Meter | ||
|
|
||
| Meters define how your usage events are aggregated and measured for billing purposes. | ||
|
|
||
| Before creating a meter, plan your usage tracking strategy: | ||
| - Identify what usage events you want to track | ||
| - Determine how events should be aggregated (count, sum, etc.) | ||
| - Define any filtering requirements for specific use cases | ||
|
|
||
| ### Step-by-Step Meter Creation | ||
|
|
||
| Follow this comprehensive guide to set up your usage meter: | ||
|
|
||
| <Steps> | ||
| <Step title="Configure Basic Information"> | ||
| Set up the fundamental details for your meter. | ||
|
|
||
| <ParamField path="Meter Name" type="string" required> | ||
| Choose a clear, descriptive name that identifies what this meter tracks. | ||
|
|
||
| Examples: "Tokens", "API Calls", "Storage Usage", "Compute Hours" | ||
| </ParamField> | ||
|
|
||
| <ParamField path="Description" type="string"> | ||
| Provide a detailed explanation of what this meter measures. | ||
|
|
||
| Example: "Counts each POST /v1/orders request made by the customer" | ||
| </ParamField> | ||
|
|
||
| <ParamField path="Event Name" type="string" required> | ||
| Specify the event identifier that will trigger this meter. | ||
|
|
||
| Examples: "token", "api.call", "storage.usage", "compute.session" | ||
| </ParamField> | ||
|
|
||
| <Info> | ||
| The event name must match exactly what you send in your usage events. Event names are case-sensitive. | ||
| </Info> | ||
| </Step> | ||
|
|
||
| <Step title="Configure Aggregation Settings"> | ||
| Define how the meter calculates usage from your events. | ||
|
|
||
| <ParamField path="Aggregation Type" type="string" required> | ||
| Select how events should be aggregated: | ||
|
|
||
| <Tabs> | ||
| <Tab title="Count"> | ||
| Simply counts the number of events received. | ||
|
|
||
| Use case: API calls, page views, file uploads | ||
|
|
||
| Calculation: Total number of events | ||
| </Tab> | ||
|
|
||
| <Tab title="Sum"> | ||
| Adds up values from a specific property in your events. | ||
|
|
||
| Use case: Data transfer, storage consumption, processing time | ||
|
|
||
| Calculation: Sum of all property values | ||
| </Tab> | ||
|
|
||
|
|
||
| <Tab title="Max"> | ||
| Records the highest value of a specific property during the billing period. | ||
|
|
||
| Use case: Peak concurrent users, maximum storage used, highest bandwidth | ||
|
|
||
| Calculation: Maximum property value observed | ||
| </Tab> | ||
|
|
||
| <Tab title="Last"> | ||
| Uses the most recent value of a specific property. | ||
|
|
||
| Use case: Current plan tier, latest configuration setting | ||
|
|
||
| Calculation: Last recorded property value | ||
| </Tab> | ||
| </Tabs> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="Over Property" type="string"> | ||
| The property name from event metadata to aggregate over. | ||
|
|
||
| <Warning> | ||
| This field is required when using Sum, Max, or Last aggregation types. | ||
| </Warning> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="Measurement Unit" type="string" required> | ||
| Define the unit label for display purposes in reports and billing. | ||
|
|
||
| Examples: "calls", "GB", "hours", "tokens" | ||
| </ParamField> | ||
| </Step> | ||
|
|
||
| <Step title="Configure Event Filtering"> | ||
| Set up criteria to control which events are included in the meter. | ||
|
|
||
|
|
||
| **Enable Event Filtering** | ||
|
|
||
| Toggle **Enable Event Filtering** to activate conditional event processing. | ||
|
|
||
| **Choose Filter Logic** | ||
|
|
||
| Select how multiple conditions are evaluated: | ||
|
|
||
| <Frame> | ||
| <img src="/images/guides/advanced-event-filtering-ubb/event-filtering.png" alt="Event Filtering" /> | ||
| </Frame> | ||
|
|
||
| <Note> | ||
| Filters in the image means any event with status code of `200` at `/v1/api` by the customer with `premium` plan under `14th` hour will be counted and else ignored. | ||
| </Note> | ||
Muhammad-Owais-Warsi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| <Tabs> | ||
| <Tab title="AND Logic"> | ||
| All conditions must be true for an event to be counted. Use this when you need events to meet multiple strict criteria simultaneously. | ||
|
|
||
| **Example:** Count API calls where `user_tier = "premium"` AND `endpoint = "/api/v2/users"` | ||
| </Tab> | ||
|
|
||
| <Tab title="OR Logic"> | ||
| At least one condition must be true for an event to be counted. Use this when you want to include events that meet any of several criteria. | ||
|
|
||
| **Example:** Count events where `method = "POST"` OR `method = "PUT"` OR `method = "DELETE"` | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| **Setting Up Filter Conditions** | ||
|
|
||
| <Steps> | ||
| <Step title="Add Condition"> | ||
| Click **Add condition** to create a new filter rule. | ||
| </Step> | ||
|
|
||
| <Step title="Configure Property Key"> | ||
| Specify the property name from your event metadata. | ||
| </Step> | ||
|
|
||
| <Step title="Select Comparator"> | ||
| Choose from available operators: | ||
| - `equals` - Exact match | ||
| - `not equals` - Exclusion filter | ||
| - `greater than` - Numeric comparison | ||
| - `greater than or equals` - Numeric comparison (inclusive) | ||
| - `less than` - Numeric comparison | ||
| - `less than or equals` - Numeric comparison (inclusive) | ||
| - `contains` - String contains substring | ||
| - `does not contain` - String exclusion filter | ||
| </Step> | ||
|
|
||
| <Step title="Set Comparison Value"> | ||
| Set the target value for comparison. | ||
| </Step> | ||
|
|
||
| <Step title="Add Groups"> | ||
| Use **Add Group** to create additional condition groups for complex logic. | ||
| </Step> | ||
| </Steps> | ||
|
|
||
|
|
||
| <Warning> | ||
| Filtered properties must be included in your event metadata for the conditions to work properly. Events missing required properties will be excluded from counting. | ||
| </Warning> | ||
| </Step> | ||
|
|
||
| <Step title="Create Meter"> | ||
| Review your meter configuration and click on **Create Meter**. | ||
|
|
||
| <Check> | ||
| Your meter is now ready to receive and aggregate usage events. | ||
| </Check> | ||
|
|
||
| </Step> | ||
| </Steps> | ||
|
|
||
| This is how we can implement advanced events filtering in Usage Based Billing. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.