Instrumentation refers to the measure of a product’s performance to:
Centralized logging standardizes application logging cho:
Structured logging libraries ensure:
from aws_lambda_powertools import Logger
logger = Logger(service="order-service")
@logger.inject_lambda_context
def handler(event, context):
logger.info("Processing order", extra={"order_id": event['orderId']})
# Automatically includes: request_id, function_name, cold_start
Lợi ích:
| Level | Use Case |
|---|---|
| DEBUG | Detailed diagnostic (dev only) |
| INFO | Normal operations, business events |
| WARN | Unexpected but handled situations |
| ERROR | Failures needing attention |
| CRITICAL | System-level failures |
| ✅ Log | ❌ Don’t Log |
|---|---|
| Request IDs | Passwords, tokens |
| Error messages + stack traces | Credit card numbers |
| Business events (order created) | PII (full email, SSN) |
| Performance metrics (duration) | Raw request bodies with PII |
| State transitions | API keys, secrets |
| User behavior | Sensitive data |
| System state | Compliance-restricted info |
| Anomalous events |
-- Find Lambda performance data from default log events
fields @timestamp, @duration, @billedDuration, @maxMemoryUsed
| filter @type = "REPORT"
| stats avg(@duration) as avg_duration,
max(@duration) as max_duration,
pct(@duration, 99) as p99_duration
by bin(5m)
import logging
import json
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def handler(event, context):
logger.info(json.dumps({
"action": "process_order",
"order_id": event.get("orderId"),
"remaining_ms": context.get_remaining_time_in_millis()
}))
| Environment | Retention |
|---|---|
| Dev | 1-7 days |
| Staging | 14-30 days |
| Production | 30-90 days |
| Compliance | 1-10 years (export to S3) |
Understanding multi-layered architectures và distributed systems requires more than traditional logs and infrastructure metrics. Cần kết hợp:
Exam Tip: