Strawberry Python Metrics Plugin
The Stellate GraphQL Strawberry Metrics Plugin is a powerful tool designed to integrate Stellate with your existing GraphQL Strawberry APIs with just a few lines of code.
Designed for modern development and developer friendly use, Strawberry is a GraphQL library for Python. For details, read GraphQL Strawbery .
Simple and easy to integrate, our Strawberry Metrics Plugin enables schema syncing and metrics logging, allowing for a seamless connection with the Stellate service for performance insights and analytics.
Benefits
The primary benefit of using our Strawberry Metrics Plugin is to be able to collect metrics without setting up the Stellate Edge proxy. For more information about the Stellate Edge proxy, read Stellate Edge proxy . In addition, the Strawberry Metrics Plugin features:
- Straightforward setup and integration with standard services.
- Simple way to add an extension to your Strawberry GraphQL schema class with a
create_stellate_extension
method. This extension captures and logs detailed information about your StrawberryGraphQL requests and their execution. This data is invaluable for debugging, monitoring performance, and understanding your GraphQL Strawberry API usage patterns. - Automatically synchronize your GraphQL schema with your Stellate service, ensuring that your Stellate metrics can show you which types and fields are (un)used.
Before you Begin
Before you install and use the Stellate Strawberry Plugin, you need to have a Python environment set up with Strawberry. Additionally, you need to:
Set Up a Stellate Service
You must have an active Stellate service set up. Our GraphQL Apollo Server Plugin is designed to work with your Stellate service. It provides performance insights and analytics for Apollo Server-based APIs.
Create a Logging Token
To implement this plugin, you need to create a logging token specific to your Stellate service. This token is used to authenticate and log metrics data from your GraphQL API to your Stellate dashboard. You can get your logging token by going to your Stellate Dashboard > Services > Your Service > Config > Token.
Once these prerequisites are met, you can install the GraphQL Strawberry Metrics Plugin.
Setup the Strawberry Metrics Plugin
To install and set up and use the Strawberry Metrics Plugin use the following simple setup steps:
-
Before you can make use of this plugin, you must have set up a Stellate service and create a logging token.
-
Install the Strawberry Metrics Plugin using a standard package manager for Python, such as
pip
-
The installation command is typically:
pip install strawberry-graphql
-
Import necessary functions from the plugin, such as
create_stellate_extension
, and add them as extension to the Strawberry schema. The allows you to add extensions to the Strawberry GraphQL schema.from stellate_strawberry import create_stellate_extension service_name = "my-service" # The name of your Stellate service token = "stl8_xyz" # The logging token for above service schema = strawberry.Schema( query=Query, extensions=[create_stellate_extension(service_name, token)] )
-
Start the server and send some requests to your API.
-
Refresh your dashboard to show the incoming requests and metrics, highlighting the plugin’s capability to track Strawberry GraphQL API usage.
Schema Syncing
The GraphQL Strawberry Metrics Plugin allows schema syncing, which ensures that the GraphQL schema stays in sync with the service being used. You can enable schema syncing on server startup by adding the following code:
from stellate_strawberry import sync_schema_to_stellate
service_name = "my-service" # The name of your Stellate service
token = "stl8_xyz" # The logging token for above service
schema = strawberry.Schema(query=Query)
# This will send schema information to stellate
sync_schema_to_stellate(schema, service_name, token)