Skip to main content

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

level
number
required
Log level: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal
time
number
required
Unix timestamp in milliseconds
service_name
string
required
Always “pluggedin-app” for the main application
version
string
required
Application version (from package.json)
trace_id
string
Unique trace ID for correlating related logs across operations
event
string
required
Event type (e.g., “oauth_token_refresh_success”, “oauth_integrity_violation”)
msg
string
required
Human-readable log message
err
object
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:
OAuth events for specific server:
OAuth events by user:

Security Monitoring

Critical security events (P0):
All integrity violations:
Failed PKCE validations:
Ownership violations by user:

Performance Analysis

Token refresh operations over 2 seconds:
OAuth flow duration distribution:
Average token refresh time:

Error Tracking

OAuth errors in last 24h:
Token refresh failures with reasons:
Discovery failures by method:

Trace Correlation

Complete OAuth flow by trace_id:
Related operations for a server:

Alerting Queries

Token reuse in last 5 minutes (CRITICAL ALERT):
High rate of code injection attempts (>10/hour):
OAuth flow success rate below 95%:
Token refresh failures spiking (>20/min):

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:
Never log these fields in plaintext:
  • access_token
  • refresh_token
  • code_verifier
  • client_secret
  • authorization_code
Example redacted log:

Best Practices

Use Trace IDs

Correlate related operations across services using trace_id field

Filter 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 deployments

Alert 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 Type: Stat Unit: Percent (0-100)

Panel: Top OAuth Errors (Last 6h)

Query:
Panel Type: Bar Chart

Panel: Security Events Timeline

Query:
Panel Type: Logs

Troubleshooting

Check environment:
Development mode uses pino-pretty for human-readable logs.
Verify redaction is enabled in lib/observability/logger.ts:
  1. Reduce time range
  2. Add more specific filters before parsing JSON
  3. Use indexed labels (service_name) first
  4. Consider using metric queries instead for aggregations
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