Already created a Cloudflare Logpush or Cloudflare HTTP requests source?
Removing it and creating a new source instead will provide you much better experience with much more suitable default configuration.
Collect logs from your Cloudflare Workers.
Create a new JavaScript • Node.js source in Better Stack Logs.
Removing it and creating a new source instead will provide you much better experience with much more suitable default configuration.
Either open your existing project with Wrangler CLI if you already have it set up, or initialize new "Hello World" Worker:
Install Better Stack logging library for edge JS runtime @logtail/edge:
Import and instantiate Logtail class, add the execution context from the request, and use it for your application logs:
Deploy your worker using Wrangler CLI
Finally, open the worker's URL in your browser to run it.
You should see your logs in Better Stack → Live tail.
Instantiating the Logtail class outside of fetch handler method will allow different worker runs to share log queue.
Providing the ExecutionContext instance (usually called ctx) will ensure all logs will be sent to Better Stack. To ensure best results, always use the returned logger instance from Logtail::withExecutionContext() method.
Want to learn more about log levels and middleware?
Continue to the Advanced usage of Logtail JavaScript client.
Some environments — like Cloudflare Durable Objects — don’t expose the ExecutionContext to your log handler. When this happens, the logger can't schedule log syncing automatically, and you might see a warning like this:
ExecutionContext hasn't been passed to the log method, which means syncing logs cannot be guaranteed. To ensure your logs will reach Better Stack, use logger.withExecutionContext(ctx) to log in your handler function. See https://betterstack.com/docs/logs/js-edge-execution-context/ for details.
To safely log in these environments:
Please let us know at hello@betterstack.com.
We're happy to help! 🙏
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.