Osservabilità con logging strutturato e tracing
Veda cosa fanno realmente le sue funzioni. Scopra il logging JSON strutturato, il distributed tracing con AWS X-Ray e le metriche personalizzate per un’osservabilità di livello production.
Osservabilità con logging strutturato e tracing è una lezione Serverless Backend with AWS Lambda & API Gateway gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Serverless Backend with AWS Lambda & API Gateway, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Serverless Backend with AWS Lambda & API Gateway include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
The Three Pillars of Observability
Observability rests on logs, metrics, and traces. Together they answer what happened, how much, and where the time went across your serverless system.
Why Structured Logging?
Plain text logs are hard to search. Structured (JSON) logs let CloudWatch Logs Insights filter and aggregate by field, turning logs into queryable data.
Writing a Structured Log
Emit JSON with consistent fields so you can query by request, level, and custom attributes.
console.log(JSON.stringify({
level: "INFO",
requestId: context.awsRequestId,
action: "createOrder",
orderId: 42
}));Correlation IDs
Pass a correlation ID through every service and log it everywhere. This lets you trace a single user request across multiple functions and queues.
Querying with Logs Insights
CloudWatch Logs Insights runs SQL-like queries over structured logs.
fields @timestamp, action, orderId
| filter level = "ERROR"
| sort @timestamp desc
| limit 20Distributed Tracing with X-Ray
AWS X-Ray records a trace as a request flows through Lambda, API Gateway, DynamoDB, and more, showing a timeline of every segment.
Enabling X-Ray
Turn on active tracing for the function, then instrument the SDK so downstream calls become subsegments.
const AWSXRay = require("aws-xray-sdk-core");
const AWS = AWSXRay.captureAWS(require("aws-sdk"));Custom Subsegments
Wrap your own logic in a subsegment to measure how long a specific block takes inside the trace.
const seg = AWSXRay.getSegment().addNewSubsegment("validate");
validate(input);
seg.close();Custom Metrics with EMF
The Embedded Metric Format lets you emit metrics inside a structured log line. CloudWatch extracts them automatically — no extra API call.
Setting Alarms
Create CloudWatch alarms on error rate, p99 latency, and DLQ depth. Alarms turn passive metrics into proactive alerts before users notice.
Avoiding Log Noise
Log with intent:
- Use levels (DEBUG/INFO/ERROR) and a log-level env var
- Never log secrets or full PII
- Sample high-volume traces to control cost
Quick Check
Test your observability knowledge.
Recap
You learned production observability:
- Logs, metrics, and traces are the three pillars
- Use structured JSON logs and correlation IDs
- X-Ray gives distributed traces across services
- Emit custom metrics with EMF and alarm on them
Impara Serverless Backend with AWS Lambda & API Gateway con un tutor IA — gratis
Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.
- Corsi
- 12
- Lezioni
- 48
Domande Frequenti
La lezione «Osservabilità con logging strutturato e tracing» è gratuita?
Sì — il testo completo di «Osservabilità con logging strutturato e tracing» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Serverless Backend with AWS Lambda & API Gateway, passa a CoddyKit PRO. Il corso Serverless Backend with AWS Lambda & API Gateway include 4 lezioni in totale.
Cosa imparerò in «Osservabilità con logging strutturato e tracing»?
Veda cosa fanno realmente le sue funzioni. Scopra il logging JSON strutturato, il distributed tracing con AWS X-Ray e le metriche personalizzate per un’osservabilità di livello production. Eserciti Serverless Backend with AWS Lambda & API Gateway con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Serverless Backend with AWS Lambda & API Gateway?
Non è richiesta alcuna esperienza precedente. Serverless Backend with AWS Lambda & API Gateway su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Osservabilità con logging strutturato e tracing»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Serverless Backend with AWS Lambda & API Gateway?
Sì. Ogni lezione Serverless Backend with AWS Lambda & API Gateway include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Cold start e strategie di warm-up
- Tecniche di ottimizzazione dei costi
- Gestione degli errori e retry
- Osservabilità con logging strutturato e tracing