Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic tracing to Cloudflare Workers #243

Closed
wants to merge 7 commits into from
Closed

Conversation

thaddeus
Copy link
Contributor

@thaddeus thaddeus commented Oct 17, 2023

Adds auto and manual instrumentation to the cloudflare workers.

A tracer is initialized by reading the OTEL_ENDPOINT environment variable, which tells the tracer where to send the processed results.

When the worker is triggered, a new trace operation is started automatically by the instrument call in main.js. First, the head sampler determines if the request should be actually sampled and logged, using the ratio value. Ratio can be set by setting a TRACE_RATIO environment variable to a value between 0 (never) and 1 (always). By default, production will sample 0.05 (5%) of the requests from there it automatically instruments things like fetch calls, and KV loads. Non-production environments will default to 1.0 (100%) sample rates.

All traces are set to tag the traces with a service name of tarkov-api, a namespace of tarkov-dev.{ENVIRONMENT}, and a version of {TAPI_COMMIT_REF} (intended to be set on deploy), falling back to unknown.

Several methods of some interest have been manually instrumented, by wrapping them in the tracer.startActiveSpan call. Each instrumented span will record the duration the function took to execute. Spans can have attributes and events associated with them, to add extra details for analysis and debugging.

Important note: To make this possible, I had to remove the node_compat flag, and replace it with nodejs_compat - this does require some care when integrating with some libraries that don't support the node: prefix for built-in packages

@thaddeus thaddeus requested a review from a team as a code owner October 17, 2023 01:07
@github-actions
Copy link
Contributor

👋 Thanks for opening a pull request!

If you are new, please check out the trimmed down summary of our deployment process below:

  1. 👀 Observe the CI jobs and tests to ensure they are passing

  2. ✔️ Obtain an approval/review on this pull request

  3. 🚀 Deploy your pull request to the development environment with .deploy to development

  4. 🚀 Deploy your pull request to the production environment with .deploy

    If anything goes wrong, rollback with .deploy main

  5. 🎉 Merge!

Need help? Type .help as a comment or visit the usage guide for more details

Please note, if you have a more complex change, it is advised to claim a deployment lock with .lock <environment> --reason <reason> to prevent other deployments from happening while you are working on your change.

Once your PR has been merged, you can remove the lock with .unlock <environment>.

@GrantBirki
Copy link
Member

1.  AssertionError  correct item shortName                      
                     expected 'Car battery' to equal 'Car batt.' 
                     at assertion:5 in test-script               
                     inside "Item by Name - Detailed"

Well that is odd 🤔 logs

@GrantBirki
Copy link
Member

image

Looks like the short name changed

The shortname for the Car battery seems to have changed. This fixes that in our CI tests
@thaddeus
Copy link
Contributor Author

Closing as outdated

@thaddeus thaddeus closed this Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants