https://github.com/epsagon/epsagon-cloudflare
Automated tracing library for Cloudflare Workers⚡️
https://github.com/epsagon/epsagon-cloudflare
cloudflare cloudflare-workers distributed-tracing monitoring tracing
Last synced: 3 months ago
JSON representation
Automated tracing library for Cloudflare Workers⚡️
- Host: GitHub
- URL: https://github.com/epsagon/epsagon-cloudflare
- Owner: epsagon
- License: mit
- Created: 2021-07-08T10:36:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-06T12:38:58.000Z (over 2 years ago)
- Last Synced: 2025-08-26T23:58:20.337Z (6 months ago)
- Topics: cloudflare, cloudflare-workers, distributed-tracing, monitoring, tracing
- Language: JavaScript
- Homepage: https://epsagon.com
- Size: 381 KB
- Stars: 0
- Watchers: 5
- Forks: 1
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Epsagon Tracing for Cloudflare Workers
This package provides tracing to Cloudflare Workers for the collection of distributed tracing and performance metrics in [Epsagon](https://app.epsagon.com/?utm_source=github).
## Contents
- [Installation](#installation)
- [Usage](#usage)
- [Tracing Fetch Requests](#tracing-fetch-requests)
### 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:
```javascript
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request))
})
function handleRequest(request) {
//your worker code.
}
```
You can change that to:
```javascript
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:
```typescript
async function handleRequest(request) {
return request.tracer.fetch('link')
}
```