Serverless Backend with AWS Lambda & API Gateway · Lekcja

Obserwowalność dzięki logowaniu strukturalnemu i śledzeniu

Zobacz, co naprawdę robią Twoje funkcje. Poznaj strukturalne logowanie JSON, rozproszone śledzenie za pomocą AWS X-Ray oraz niestandardowe metryki zapewniające obserwowalność na poziomie produkcyjnym.

Lekcja 4 z 413 kroki

Obserwowalność dzięki logowaniu strukturalnemu i śledzeniu to bezpłatna lekcja Serverless Backend with AWS Lambda & API Gateway na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Serverless Backend with AWS Lambda & API Gateway, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Serverless Backend with AWS Lambda & API Gateway zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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 20

Distributed 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
Bezpłatny start

Ucz się Serverless Backend with AWS Lambda & API Gateway dzięki korepetycjom AI — za darmo

Pisz i uruchamiaj kod w przeglądarce, otrzymuj natychmiastową pomoc od korepetytora AI dostępnego 24/7 i kontynuuj naukę w sieci lub w aplikacji.

Kursy
12
Lekcje
48

Często zadawane pytania

Czy lekcja „Obserwowalność dzięki logowaniu strukturalnemu i śledzeniu” jest bezpłatna?

Tak — pełny tekst „Obserwowalność dzięki logowaniu strukturalnemu i śledzeniu” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Serverless Backend with AWS Lambda & API Gateway, przejdź na CoddyKit PRO. Kurs Serverless Backend with AWS Lambda & API Gateway zawiera 4 lekcji w sumie.

Co nauczysz się w „Obserwowalność dzięki logowaniu strukturalnemu i śledzeniu”?

Zobacz, co naprawdę robią Twoje funkcje. Poznaj strukturalne logowanie JSON, rozproszone śledzenie za pomocą AWS X-Ray oraz niestandardowe metryki zapewniające obserwowalność na poziomie produkcyjnym. Ćwiczysz Serverless Backend with AWS Lambda & API Gateway z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Serverless Backend with AWS Lambda & API Gateway?

Nie wymagamy żadnego doświadczenia. Serverless Backend with AWS Lambda & API Gateway w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Obserwowalność dzięki logowaniu strukturalnemu i śledzeniu”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Serverless Backend with AWS Lambda & API Gateway?

Tak. Każda lekcja Serverless Backend with AWS Lambda & API Gateway zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Zimne starty i strategie rozgrzewania
  2. Techniki optymalizacji kosztów
  3. Obsługa błędów i ponawianie prób
  4. Obserwowalność dzięki logowaniu strukturalnemu i śledzeniu
← Powrót do Serverless Backend with AWS Lambda & API Gateway