Spring Boot
Revenium provides a Spring Boot Starter to easily meter method invocations in Spring Boot applications.
Installation
You'll need to add the Revenium dependency to either your pom.xml or build.gradle file.
Maven
Add the following dependency to your pom.xml
:
Gradle
Configuration
You'll need to add the following properties to your application.properties
or application.yml
file:
Usage
The Revenium Spring Boot starter provides an aspect that can be annotated on a method to send metering data to the Revenium platform. This can be applied to any method in your Spring Boot application but is typically used to meter REST controller or service method invocations.
The annotation accepts the following parameters:
subscriptionId: The subscription id identifying who is consuming the data
sourceId: The source (asset) id of the metering data
elements: A JSON string representing the metering elements to send to the Revenium platform. This can be a JSON string or a SpEL expression that evaluates to a JSON string. The SpEL expression can reference the method arguments and return value.
The metered aspect provides "result" and "args" context variables ino the SpEL expression. The "result" variable contains the return value of the method being metered and the "args" variable contains the method arguments.
Example Usage in a REST Controller
Here's an example of how to use the @Metered
annotation on a REST controller POST operation:
This example sends metering data to the Revenium platform when the summarize
method is invoked. The sourceId is statically set to "text-summarizer" and the subscriptionId is dynamically set to the second argument of the method. The metering elements are set to a JSON object containing the number of LLM tokens consumed by the method.
Last updated