You can place this code in the main file of your application. Once initialized, you can use the logger to log your application's events.
Distributed tracing using Maxim
Learn how to use Maxim's distributed tracing solution for your GenAI application.
For this section, let's consider that you are building an enterprise search chatbot (similar to Glean).
- Companies connect their data sources like Google Drive, Dropbox, etc.
- Company employees can search for all this information using natural language on Slack or a custom search page.
System architecture
The diagram below represents the system architecture.
This system consists of 5 micro-services
- API gateway that does
- User authentication
- API routing
- Planner
- Plans execution for incoming query
- Intent detector
- Detects the intent of the given query
- Answer generator
- Generates the prompt for fetching answers based on planner instruction and context fetched from the RAG system
- RAG
- This is the RAG pipeline that fetches a relevant chunk of information from a vector database.
Setting up the Maxim dashboard
Create a new repository; let's call it 'Chatbot Production'.
Go to Settings
-> API Keys
, and generate a new API Key. Copy the API key and store it somewhere safe.
Set up SDK in your repository.
Initialize Maxim logger. We will use the generated API key and the repository id that you have created in the previous steps.
We will initialize logger in each service using the same repository id.
In your route handler (api gateway service), lets create a trace. We will use cf-request-id
as our trace id.
Once this trace is created, you can manipulate it in two ways.
- Using logger and trace id
- Creating trace object again with the same trace id
Here you don't have to pass all the parameters again. You can just reuse the trace object and update the tags.
You can manipulate every component of Maxim observability framework (Span, Generation, Retrieval, Event) in the same way.
Now lets create a span for planner, in planner service. We will use cf-request-id
as our trace id.
Now lets add LLM call i.e. Generation in the planner span.
Once you receive a response, you can log it as follows.
Maxim currently supports OpenAI messaging format. We have helper methods to convert other messaging formats to OpenAI format in the SDK. Calling .result
on a generation, also ends the generation.
Using the trace object initialized with the same cf-request-id
, you can create additional spans across your entire request lifecycle in any service. Each span represents a distinct operation or service call in your application, such as database queries, external API calls, or processing steps.
When creating spans, consider adding relevant tags that provide context about the operation being performed. These tags help in filtering and analyzing traces later. Remember to end each span once its operation completes to ensure accurate timing measurements.
As these operations are executed across your services, the logs will appear within a few seconds on your Maxim dashboard. The dashboard provides a comprehensive view of your entire request trace, including all spans, generations, and retrievals, giving you end-to-end visibility into your application's behavior and performance.