The Moesif Cloudflare worker can also be created without using the Cloudflare Dashboard, using the Cloudflare/Wrangler CLI tool. More details on Wrangler on cloudflare site
Using Cloudflare/Wrangler
CLI allows for automated install using wrangler publish
, as well as view/tail
using wrangler tail
command
For users who are familiar with using VSCode IDE / Visual Studio Code and developing inside a container, this project includes .devcontainer
with automated wrangler
and cloudflared
installation.
You will need to install wrangler
tool using the links above to publish the worker.
Additionally, to view (wrangler tail
) log files of a worker running in cloudflare, you will need to install cloudflared
- Clone this repo
git clone [email protected]:Moesif/moesif-cloudflare
cd moesif-cloudflare
-
Modify
src/index.js
: At minimum add the Moesif Application Id"applicationId"
See README.md -
Modify
wrangler.toml
:
- Update fields
account_id
andzone_id
obtained from your cloudflare dashboard - Update field
routes
with routes you would like to use. See README.md
- Login to cloudflare using
wrangler
(as needed)
wrangler login
- Deploy to cloudflare. To create new worker and associate routes:
wrangler publish
The worker should be running and logging to moesif
Just visit your link on cloudflare using your web browser https://my-cloudflare-domain/my-path
or
curl https://my-cloudflare-domain/my-path
The API calls should show up in Moesif event stream.
For a wrangler deployed worker, view logs from cloudflare using.
wrangler tail --format pretty
Here is sample logs output:
[2021-08-04 02:09:12] [SJC] [Ok] GET https://my-domain.io/hello
| [Info] [MoesifWorker] fetchAppConfig start
| [Info] [MoesifWorker] logRequest start url=https://my-domain.io/hello
| [Info] [MoesifWorker] logging request url=https://my-domain.io/hello
| [Info] [MoesifWorker] response={"webSocket":null,"url":"https://my-domain.io/hello","redirected":false,"ok":true,"headers":{},"statusText":"OK","status":200,"bodyUsed":false,"body":{"locked":false}}
| [Info] [MoesifWorker] tryTrackRequest start url=https://my-domain.io/hello
| [Info] [MoesifWorker] makeMoesifEvent start
For detailed debug logs and troubleshooting, prior to deploying the worker, modify src/index.js
"debug": true
Remember to disable debug
for production.