Skip to content

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 ☺️

@xjamundx
Copy link

Anything needed @evanderkoogh to get this moving?

@evanderkoogh
Copy link
Owner

An extra hour or two a day? :D

But seriously.. I currently have a bit more time to work on the library and get it up to speed with some of the latest releases Cloudflare has made over the past year or so. The core-logic-refactor branch has finally landed, which is hopefully going to make it a bit easier to add instrumentation support for things like this.

@jingwei99
Copy link

👋 , curious where is this going and or if there's a plan to get this going/merged

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.

5 participants