구조화된 로깅과 상관관계 ID
검색 가능한 구조화된 JSON 로그를 생성하고 상관관계 ID를 사용하여 여러 함수에 걸친 요청을 추적하는 방법을 배웁니다.
구조화된 로깅과 상관관계 ID은(는) CoddyKit의 무료 Serverless AWS Lambda Development 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Serverless AWS Lambda Development 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Serverless AWS Lambda Development 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Plain Logs Do Not Scale
Free-text log lines are hard to filter at scale. Structured logging writes each entry as JSON with consistent fields you can query.
Anatomy of a Structured Log
A good log entry has a level, a message, and contextual fields like request id and user id.
{
"level": "INFO",
"message": "order placed",
"orderId": 42,
"requestId": "abc-123"
}Emitting JSON Logs
Serialize a dictionary to JSON and print it. CloudWatch Logs Insights can then query individual fields.
import json, sys
def log(level, message, **fields):
entry = {'level': level, 'message': message}
entry.update(fields)
print(json.dumps(entry), file=sys.stdout)
log('INFO', 'order placed', orderId=42)Querying with Logs Insights
Logs Insights lets you filter and aggregate JSON fields with a query language.
fields @timestamp, orderId
| filter level = 'ERROR'
| sort @timestamp desc
| limit 20The Correlation ID
A correlation ID is a unique value attached to a request and passed to every downstream service, so you can trace one request end to end.
Generating One
Create the ID at the entry point if the incoming request does not already carry one.
import uuid
def get_correlation_id(event):
headers = event.get('headers') or {}
return headers.get('x-correlation-id') or str(uuid.uuid4())Propagating It
Pass the correlation ID forward in message attributes, HTTP headers, or event payloads so the next function logs the same ID.
sns.publish(
TopicArn=topic,
Message=body,
MessageAttributes={
'correlationId': {'DataType': 'String', 'StringValue': cid}
}
)Log Levels
Use levels (DEBUG, INFO, WARN, ERROR) and make the threshold configurable via an environment variable so production stays quiet but debuggable.
Never Log Secrets
Structured logs are searchable, which makes accidental secret logging dangerous. Redact tokens, passwords, and PII before logging.
Control Log Retention
Logs cost money to store. Set a retention period on each log group so old logs expire automatically.
aws logs put-retention-policy \
--log-group-name /aws/lambda/orders \
--retention-in-days 30Tie Logs to Traces
Include the X-Ray trace id in your structured logs so you can jump from a log line straight to the distributed trace for that request.
Quick Check
Test your logging knowledge.
Recap
You learned structured JSON logging, querying with Logs Insights, threading correlation IDs across services, redacting secrets, and setting retention.
자주 묻는 질문
“구조화된 로깅과 상관관계 ID” 강의는 무료인가요?
네 — “구조화된 로깅과 상관관계 ID” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Serverless AWS Lambda Development 강의 전체를 잠금 해제할 수 있습니다. Serverless AWS Lambda Development 강의에는 총 4개의 강의가 포함되어 있습니다.
“구조화된 로깅과 상관관계 ID”에서 뭘 배우나요?
검색 가능한 구조화된 JSON 로그를 생성하고 상관관계 ID를 사용하여 여러 함수에 걸친 요청을 추적하는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Serverless AWS Lambda Development을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Serverless AWS Lambda Development을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Serverless AWS Lambda Development은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“구조화된 로깅과 상관관계 ID” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Serverless AWS Lambda Development 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Serverless AWS Lambda Development 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.