@epsagon/cloudflare
v1.2.0
Published
This package provides tracing to Cloudflare workers for the collection of distributed tracing and performance metrics.
Downloads
15
Maintainers
Readme
Epsagon Tracing for Cloudflare Workers
This package provides tracing to Cloudflare Workers for the collection of distributed tracing and performance metrics in Epsagon.
Contents
Installation
Installation is done via the usual npm install @epsagon/cloudflare
.
Usage
To configure the package, you need to wrap your listener with the epsagon agent. So if your current code looks something like this:
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request))
})
function handleRequest(request) {
//your worker code.
}
You can change that to:
import { epsagon } from '@epsagon/cloudflare'
const epsagon_config = {
token: 'epsagon-token',
app_name: 'application-name',
}
const listener = epsagon(epsagon_config, (event) => {
event.respondWith(handleRequest(event.request))
})
addEventListener('fetch', listener)
function handleRequest(request) {
//your worker code.
}
Tracing Fetch Requests
To be able to associate the a subrequest with the correct incoming request, you will have to use the fetch defined on the tracer described above. The method on the tracer delegates all arguments to the regular fetch method, so the tracer.fetch
function is a drop-in replacement for all fetch
function calls.
Example:
async function handleRequest(request) {
return request.tracer.fetch('link')
}