β‘ Lab 4: Workflow Automation - Become the AI Cost Guardian
Duration: ~30 minutes
In this lab, youβll create automated workflows that transform you from someone who monitors AI costs to someone who controls them. This is your βhero momentβ β building automation you can take back to your team.
π― Learning Objectives
- Create a Dynatrace Workflow for AI observability
- Set up automated token usage monitoring
- Configure alerts that matter (not noise)
- Build a daily AI cost summary automation
- Understand the Dynatrace automation advantage
π Why Dynatrace? The Automation Advantage
| Capability | Other Tools | Dynatrace |
|---|---|---|
| Trace collection | β Manual thresholds | β Davis AI anomaly detection |
| Alert configuration | β You define every threshold | β Auto-baselines, smart alerts |
| Root cause | β You investigate | β Davis AI automatic RCA |
| Remediation | β External tools (PagerDuty, etc.) | β Built-in Workflows + integrations |
| Context | Token counts only | β Tokens + infrastructure + user impact |
The difference: Other tools tell you something is wrong. Dynatrace tells you whatβs wrong, why, and can fix it automatically.
Step 1: Navigate to Workflows
1.1 Access the Workflows App
- In Dynatrace, click on the Workflows app in the left navigation (or search for it)
π Choose Your Persona
From here, focus on the workflows most relevant to your role. Complete at least one workflow.
π» Developer Path
Your goal: Create workflows that alert you before users complain. Sleep better knowing automation has your back.
Must-do: Step 2 (Token Usage Alert)
π§ SRE/Platform Path
Your goal: Build the automation that makes you the AI Cost Guardian. This is your βhero momentβ!
Must-do: Step 3 (Daily Summary)
π» Step 2: Create a Token Usage Alert Workflow
This workflow will alert you when token usage exceeds a threshold β perfect for catching runaway AI costs.
2.1 Create a New Workflow
- Click + Workflow
- Name it:
Token Usage Alert - {YOUR_ATTENDEE_ID}
2.2 Set the Trigger
- Click on the trigger block (the starting point)
- Select Time Interval trigger:
- Set to run every 15 minutes for testing
2.3 Add a DQL Query Action
- Click + Add task
- Select Execute DQL query
- Enter this query:
fetch spans
| filter service.name == "ai-chat-service-{YOUR_ATTENDEE_ID}"
| filter isNotNull(gen_ai.usage.input_tokens)
| summarize
total_input_tokens = sum(gen_ai.usage.input_tokens),
total_output_tokens = sum(gen_ai.usage.output_tokens),
request_count = count()
| fieldsAdd total_tokens = total_input_tokens + total_output_tokens
| fieldsAdd estimated_cost_usd = (total_input_tokens * 2.50 + total_output_tokens * 10.00) / 1000000
- Name this task:
get_token_usage
2.4 Add a Notification Action
- Add an Email -> Send email task
- Configure your message:
π¨ AI Token Alert - {YOUR_ATTENDEE_ID}
Token usage exceeded threshold!
π Stats:
β’ Total Tokens: {{ result("get_token_usage").records[0].total_tokens }}
β’ Input Tokens: {{ result("get_token_usage").records[0].total_input_tokens }}
β’ Output Tokens: {{ result("get_token_usage").records[0].total_output_tokens }}
β’ Estimated Cost: ${{ result("get_token_usage").records[0].estimated_cost_usd | round(4) }}
β’ Request Count: {{ result("get_token_usage").records[0].request_count }}
2.4 Add a Condition
- Select Condition
-
Set the condition:
{{ result("get_token_usage").records[0].total_tokens > 1000 }}(Adjust threshold based on your expected usage)
2.6 Save and Run
- Click Create/Save draft
- Click Run
π§ Step 3: Daily AI Cost Summary Workflow
Create a workflow that sends you a daily summary β no more surprise bills!
3.1 Create a New Workflow
- Click + Workflow
- Name it:
Daily AI Summary - {YOUR_ATTENDEE_ID}
3.2 Set Schedule Trigger
- Select Fix Time trigger
- Configure: Daily at 9:00 AM (or your preferred time)
3.3 Add Comprehensive DQL Query
Add a Execute DQL query task named usage with:
fetch spans
| filter service.name == "ai-chat-service-{YOUR_ATTENDEE_ID}"
| filter isNotNull(gen_ai.usage.input_tokens)
| summarize
total_input = sum(gen_ai.usage.input_tokens),
total_output = sum(gen_ai.usage.output_tokens),
avg_input = avg(gen_ai.usage.input_tokens),
avg_output = avg(gen_ai.usage.output_tokens),
max_input = max(gen_ai.usage.input_tokens),
request_count = count(),
by: {span.name}
| sort total_input + total_output desc
| limit 10
3.4 Add Summary Query
Add another Execute DQL query task named cost with:
fetch spans
| filter service.name == "ai-chat-service-{YOUR_ATTENDEE_ID}"
| filter isNotNull(gen_ai.usage.input_tokens)
| summarize
total_input = sum(gen_ai.usage.input_tokens),
total_output = sum(gen_ai.usage.output_tokens),
total_requests = count(),
avg_latency_ms = avg(duration) / 1000000
| fieldsAdd estimated_daily_cost = (total_input * 2.50 + total_output * 10.00) / 1000000
| fieldsAdd projected_monthly_cost = estimated_daily_cost * 30
3.5 Send Daily Report
- Add an Email -> Send email task
- Configure your message:
π Daily AI Service Report - {YOUR_ATTENDEE_ID}
βββββββββββββββββββββββββββββββββββββββ
π° COST SUMMARY
βββββββββββββββββββββββββββββββββββββββ
β’ Today's Estimated Cost: ${{ result("cost").records[0].estimated_daily_cost | round(4) }}
β’ Projected Monthly Cost: ${{ result("cost").records[0].projected_monthly_cost | round(2) }}
βββββββββββββββββββββββββββββββββββββββ
π USAGE METRICS
βββββββββββββββββββββββββββββββββββββββ
β’ Total Requests: {{ result("usage").records | map(attribute="request_count") | map("int") | sum }}
β’ Total Input Tokens: {{ result("usage").records | map(attribute="total_input") | map("int") | sum }}
β’ Total Output Tokens: {{ result("usage").records | map(attribute="total_output") | map("int") | sum }}
β’ Avg Response Time: {{ result("cost").records[0].avg_latency_ms }}ms
3.6 Save and Run
- Click Create/Save draft
- Click Run
β Checkpoint
Before completing this lab, verify:
- Created a workflow
- Set up notification
- Tested workflow execution
- Understood how Davis AI can trigger workflows
- Know how to add conditions and notifications
π Troubleshooting
βWorkflow not triggeringβ
- Verify the workflow is set to Enabled
- Check that your service is generating data
- For scheduled triggers, wait for the next scheduled run
- Use Run to test manually
βDQL query returns no dataβ
- Verify your service name matches exactly
- Check the time range in your query
- Ensure your application has processed requests recently
βNotification not receivedβ
- Verify the notification channel configuration
- Check for authentication/permission issues
- Test the notification channel independently
π What Youβve Learned
π» Developer Takeaways
Youβve built automation that watches your AI service:
- β Create scheduled workflows that run DQL queries
- β Set up token usage alerts with thresholds
- β Configure notifications (Slack, Teams, Email)
- β Add conditions to avoid alert noise
Sleep better: Your workflow will alert you if token usage spikes β before users complain or the bill arrives.
π§ SRE/Platform Takeaways
Youβre now the AI Cost Guardian:
- β Build daily cost summary workflows
- β Calculate projected monthly costs automatically
- β Identify top token consumers by operation
- β Trigger workflows from Davis AI problems
Take back to your team: These workflows are production-ready. Customize the thresholds and notification channels for your environment.
π Take It Further
Ideas for production workflows:
| Workflow | Trigger | Action |
|---|---|---|
| Cost Circuit Breaker | Token rate > limit | Disable endpoint temporarily |
| Model Fallback | GPT-4 latency spike | Switch to GPT-4o-mini |
| Weekly Executive Report | Schedule (Monday 8am) | Email summary to leadership |
| Prompt Injection Alert | Unusual input patterns | Security team notification |
| SLA Violation | P95 latency > 5s | Create incident + page on-call |
π Lab Complete!
Youβve built automation that will save your team time and money. These workflows demonstrate the Dynatrace difference β not just observability, but actionable automation.