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

Experimental Instrumentation of the cloudflare WebSocketPair API for workers #82

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Ankcorn
Copy link
Contributor

@Ankcorn Ankcorn commented Jan 9, 2024

Hey @evanderkoogh,

This instruments websocket message and close handling.

image

This is a pretty hacky PR and I would appreciate your feedback on how to make it ready to merge :)

The major issue I ran into was making sure setConfig ran before getActiveConfig was called, I didn't manage this in the end so ended up adding a hack into config.ts to make the tracing work. I have probably done something obviously wrong

It adds spanEvents for accept, send, and close such that we can see how the websocket connection is behaving on the server, it currently makes no effort to add a parent span from the client message. From what I can see there would not be a good way to infer the traceparent reliably.


export function setConfig(config: ResolvedTraceConfig, ctx = context.active()) {
// I could not get the context to work properly, so I'm using a global fallback.
// I suspect this is because I am not initialising the config properly in the WS instrumentation.
if (!fallbackConfig) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually a bug in this library and/or with context combined with websockets. I tried instrumenting WS on my own and I get the same thing as here: #14

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I think it's an async local storage issue. Happy to jump on a call and work on this together if you would like ☺️

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