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 debuggingDEBUG- Development infoINFO- Normal operationsWARN- Warning conditionsERROR- Error eventsFATAL- 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