İzleme ve Günlüğe Kaydetme
Performansı takip etmek ve sorunlarda hata ayıklamak için uç uygulamalarınızda izleme ve günlüğe kaydetme düzeni kurun.
İzleme ve Günlüğe Kaydetme, CoddyKit'te ücretsiz bir Edge Computing with Cloudflare Workers & Deno dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Edge Computing with Cloudflare Workers & Deno öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Edge Computing with Cloudflare Workers & Deno kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Why Monitor & Log Edge Apps?
When your applications run at the edge, they're distributed globally. This makes it challenging to know what's happening without good visibility.
Monitoring helps you track performance metrics like request times and error rates across your entire system. Logging gives you detailed records of individual events, like requests or errors, which are crucial for debugging.
Basic Logging: console.log
The simplest way to log information in a Cloudflare Worker is by using console.log(). This works much like logging in a browser or Node.js environment.
Messages sent to console.log() are captured by Cloudflare and can be viewed in your Worker's dashboard or exported using Logpush.
Basic Logging in Action
Try running this Worker. It logs the incoming request's URL to the console. When you test it, check your Worker's logs in the Cloudflare dashboard to see the output.
export default {
async fetch(request, env, ctx) {
console.log("Request received for:", request.url);
return new Response("Hello from basic logging!");
}
};The Need for Structured Logs
While console.log() is easy, plain text logs can be hard to parse and analyze at scale. Imagine sifting through thousands of lines of text!
Structured logging involves outputting logs in a consistent, machine-readable format, like JSON. This makes it much easier for monitoring tools to process and query your logs.
Cloudflare Logpush Overview
Cloudflare's Logpush service allows you to export your Worker logs to various destinations, such as cloud storage (AWS S3, Google Cloud Storage) or analytics platforms.
This is essential for long-term storage, advanced querying, and integrating with your existing monitoring infrastructure.
What to Include in Logs?
Good structured logs contain useful context. Consider including:
- Timestamp: When the event occurred.
- Level: (e.g., INFO, WARN, ERROR) for severity.
- Request ID: To trace a single request through its lifecycle.
- URL & Method: Details of the incoming request.
- Latency: How long the operation took.
- Error Details: Stack traces, error messages.
Structured Logging Example
This Worker logs request details as a JSON string, including a simple latency measurement. This format is easily parsable by log analysis tools.
export default {
async fetch(request, env, ctx) {
const start = Date.now();
const response = new Response("Hello from structured logs!");
const latency = Date.now() - start;
const logEntry = {
timestamp: new Date().toISOString(),
level: "INFO",
url: request.url,
method: request.method,
latencyMs: latency,
requestId: crypto.randomUUID()
};
console.log(JSON.stringify(logEntry));
return response;
}
};Introduction to Edge Metrics
While logs tell you 'what happened,' metrics tell you 'how much' or 'how often.' Metrics are numerical measurements captured over time, used to track the health and performance of your application.
Common metrics include requests per second, error rates, CPU usage, and memory consumption. They are aggregated and visualized in dashboards.
Custom Metrics in Workers
Cloudflare Workers provide built-in analytics, but you can also add custom metrics. One simple way is to use response headers to expose performance data that can be scraped or analyzed.
Here, we add a X-Worker-Latency header. More advanced metrics might use external services or Cloudflare's ctx.waitUntil to send data.
export default {
async fetch(request, env, ctx) {
const start = Date.now();
const response = new Response("Hello from custom metrics!");
const latency = Date.now() - start;
// Add a custom header as a simple metric
response.headers.set("X-Worker-Latency", latency.toString());
console.log(`Request processed in ${latency}ms`);
return response;
}
};Monitoring Tools & Dashboards
Once you have logs and metrics, you need tools to make sense of them. Cloudflare provides basic analytics, but for advanced analysis, you'll integrate with:
- Log Management Systems: Splunk, ELK Stack, DataDog, Sumo Logic.
- Monitoring Platforms: Grafana, Prometheus, New Relic, Dynatrace.
These tools help you visualize trends, set up alerts, and quickly identify issues.
Quick Check on Logging
You are debugging an intermittent error in your Cloudflare Worker. You've been using console.log("Error occurred!") to catch issues.
Which change would MOST improve your ability to diagnose the problem quickly?
Recap: Monitoring & Logging
Great job! In this lesson, you learned about the critical role of monitoring and logging for edge applications.
console.log()is your basic logging tool.- Structured logging (e.g., JSON) provides machine-readable, actionable insights.
- Cloudflare Logpush helps export logs for advanced analysis.
- Metrics track performance trends, often exposed via custom headers or dedicated services.
- Using external monitoring tools can greatly enhance visibility and debugging capabilities.
Keeping an eye on your edge apps ensures they perform optimally!
Sıkça Sorulan Sorular
“İzleme ve Günlüğe Kaydetme” dersi ücretsiz mi?
Evet — “İzleme ve Günlüğe Kaydetme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Edge Computing with Cloudflare Workers & Deno kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Edge Computing with Cloudflare Workers & Deno kursu toplamda 4 dersten oluşur.
“İzleme ve Günlüğe Kaydetme” dersinde ne öğreneceğim?
Performansı takip etmek ve sorunlarda hata ayıklamak için uç uygulamalarınızda izleme ve günlüğe kaydetme düzeni kurun. Edge Computing with Cloudflare Workers & Deno ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Edge Computing with Cloudflare Workers & Deno öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Edge Computing with Cloudflare Workers & Deno, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.
“İzleme ve Günlüğe Kaydetme” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Edge Computing with Cloudflare Workers & Deno dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Edge Computing with Cloudflare Workers & Deno dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Önbelleğe Alma Stratejileri
- Soğuk Başlangıçlar ve Isındırmalar
- İzleme ve Günlüğe Kaydetme
- Paket Boyutu ve Kod Optimizasyonu