evanderkoogh / otel-cf-workers

An OpenTelemetry compatible library for instrumenting and exporting traces for Cloudflare Workers
BSD 3-Clause "New" or "Revised" License
208 stars 39 forks source link

Experimental Instrumentation of the cloudflare WebSocketPair API for workers #82

Open Ankcorn opened 5 months ago

Ankcorn commented 5 months ago

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.