Open in Google Colab
Run the complete notebook in your browser
All company names (MeetingMind, Apex Legal, Stratex Consulting, TechStart Inc) and scenarios in this cookbook are entirely fictional and used for demonstration purposes only.
What You’ll Learn
Set Tenant Context
Use Netra’s native tenant tracking to attribute all traces to specific customers
Track Per-Customer Costs
Query usage and cost data per tenant via API or dashboard
Monitor SLA Compliance
Set up tier-specific alerts that trigger on latency or error rate breaches
Analyze Usage Patterns
Understand session and user behavior within each tenant
Prerequisites:
- Python >=3.10, < 3.14
- OpenAI API key
- Netra API key (Get your key here)
The MeetingMind Scenario
MeetingMind is a fictional B2B SaaS platform that provides AI-powered meeting summarization. The platform serves customers with different needs and budgets:| Customer | Industry | Tier |
|---|---|---|
| Apex Legal | Law Firm | Enterprise |
| Stratex Consulting | Consulting | Professional |
| TechStart Inc | Tech Startup | Starter |
| Tier | Model | Latency SLA | Rate Limit |
|---|---|---|---|
| Enterprise | GPT-4o-mini | P95 < 2s | 60 calls/min |
| Professional | GPT-4o-mini | P95 < 3s | 30 calls/min |
| Starter | GPT-4o-mini | Best effort | 10 calls/min |
Step 1: Install Packages
Step 2: Set Environment Variables
Step 3: Initialize Netra for Multi-Tenant Tracking
Initialize Netra at application startup with auto-instrumentation for OpenAI:Step 4: Define Tenant Configuration
Configure tier-specific settings for each customer:Step 5: Create Multi-Tenant Meeting Summarizer
Build a service that tracks costs per tenant. This class handles tenant context setting, prompt building based on feature tiers, cost calculation, and SLA compliance checking — all within Netra spans.Step 6: Test with Sample Meetings
Simulate meeting summarization requests from different tenants:Step 7: Review Usage and Cost Breakdown
Analyze per-tenant usage patterns and costs:Step 8: SLA Monitoring
Check which tenants are meeting their SLA commitments:Setting Up Tenant-Specific Alerts
In the Netra dashboard, navigate to Alert Rules and create tenant-filtered alerts:Apply Tenant Filter
Add a filter for
tenant_id = apex-legal to only monitor Enterprise tier requestsSet Threshold
- Condition: Greater than 2000ms
- Time Window: 5 minutes (to avoid alerting on single slow requests)
| Tenant | Tier | Alert Threshold | Rate Limit |
|---|---|---|---|
| apex-legal | Enterprise | > 2000ms | 60 calls/min |
| stratex-consulting | Professional | > 3000ms | 30 calls/min |
| techstart-inc | Starter | No SLA alert (best effort) | 10 calls/min |
Step 9: Querying Tenant Metrics via Netra API
Once traces are sent to Netra, query tenant-specific metrics programmatically:What You’ll See in the Dashboard
After running this cookbook, check the Netra dashboard for:- Tenant selector filtering all traces to a specific customer
- Per-tenant cost breakdown showing usage per customer
- SLA compliance dashboard with latency metrics by tier
- Comparative analytics showing which customers use which features
- User activity filtered by tenant and user ID
Key Multi-Tenant Patterns
| Pattern | Use Case | How to Implement |
|---|---|---|
| Cost attribution | Billing and profitability | Set tenant_id at request start |
| SLA monitoring | Support and escalation | Filter by tenant_id and latency threshold |
| Feature usage | Product insights | Check feature flags in tenant config |
| User segmentation | Per-user analytics | Set user_id in addition to tenant_id |