OAuth Logs & LogQL Queries
Plugged.in uses structured JSON logging with automatic redaction and Loki integration for powerful log aggregation and querying.Log Structure
All OAuth logs follow a consistent JSON structure:Log Fields
Log level: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal
Unix timestamp in milliseconds
Always “pluggedin-app” for the main application
Application version (from package.json)
Unique trace ID for correlating related logs across operations
Event type (e.g., “oauth_token_refresh_success”, “oauth_integrity_violation”)
Human-readable log message
Error details including stack trace (only for errors)
OAuth Event Types
Flow Events
PKCE Events
Token Events
Security Events
Cleanup Events
LogQL Queries
Basic Queries
All OAuth events from last hour:Security Monitoring
Critical security events (P0):Performance Analysis
Token refresh operations over 2 seconds:Error Tracking
OAuth errors in last 24h:Trace Correlation
Complete OAuth flow by trace_id:Alerting Queries
Token reuse in last 5 minutes (CRITICAL ALERT):Log Aggregation Patterns
Count Events by Type
Top Error Messages
Users with Most OAuth Activity
Servers Requiring Most Token Refreshes
Sensitive Data Redaction
Sensitive fields are automatically redacted in logs: Example redacted log:Best Practices
Use Trace IDs
Correlate related operations across services using
trace_id fieldFilter by Time Range
Always specify time ranges to avoid scanning entire log history
Index by Service
Use
service_name label for efficient querying in multi-service deploymentsAlert on Security Events
Set up Grafana alerts for critical security events (token reuse, code injection)
Monitor Performance
Track p50, p95, p99 for token refresh duration to detect degradation
Example Grafana Queries
Panel: OAuth Flow Success Rate (Last 24h)
Query:Panel: Top OAuth Errors (Last 6h)
Query:Panel: Security Events Timeline
Query:Troubleshooting
Logs not structured JSON
Logs not structured JSON
Check environment:Development mode uses pino-pretty for human-readable logs.
Sensitive data appearing in logs
Sensitive data appearing in logs
Verify redaction is enabled in
lib/observability/logger.ts:LogQL query timeout
LogQL query timeout
- Reduce time range
- Add more specific filters before parsing JSON
- Use indexed labels (service_name) first
- Consider using metric queries instead for aggregations
Missing trace_id in logs
Missing trace_id in logs
Ensure
trace_id is generated for each request:Next Steps
Metrics & PromQL
Explore Prometheus metrics for OAuth
Grafana Dashboards
Build custom dashboards combining logs and metrics

