Structured Logging

Send structured logs to StatusRadar via OTLP.

Overview

OTLP logs provide:

  • Structured fields (JSON)
  • Severity levels
  • Trace correlation
  • Timestamp precision
  • Rich search capabilities

Basic Logging

Node.js

const { logs } = require('@opentelemetry/api-logs');
const logger = logs.getLogger('my-service');

logger.emit({
  severityText: 'INFO',
  body: 'User logged in',
  attributes: {
    'user.id': '12345',
    'user.email': '[email protected]',
    'login.method': 'password'
  }
});

Python

from opentelemetry._logs import get_logger

logger = get_logger(__name__)

logger.emit(
    severity_text='INFO',
    body='User logged in',
    attributes={
        'user.id': '12345',
        'user.email': '[email protected]',
        'login.method': 'password'
    }
)

Severity Levels

  • TRACE - Detailed debugging
  • DEBUG - Development info
  • INFO - Normal operations
  • WARN - Warning conditions
  • ERROR - Error events
  • FATAL - Critical failures

Trace Correlation

Link logs to traces:

const { trace, context } = require('@opentelemetry/api');

const span = tracer.startSpan('process_payment');
const spanContext = span.spanContext();

logger.emit({
  body: 'Payment processed',
  attributes: {
    'trace_id': spanContext.traceId,
    'span_id': spanContext.spanId
  }
});

Search & Filter

Dashboard β†’ Observability β†’ Apps β†’ Logs

Search syntax:

level:ERROR
user.id:12345
message:"payment failed"
timestamp:[2024-01-01 TO 2024-01-31]

Best Practices

βœ… Use structured attributes instead of string interpolation βœ… Include trace/span IDs for correlation βœ… Add user context βœ… Use appropriate severity levels

❌ Don't log sensitive data (passwords, tokens) ❌ Don't log high-frequency events (use metrics instead) ❌ Don't include large payloads

Next Steps