opentelemetry-js-contrib
opentelemetry-js-contrib copied to clipboard
automatic tracing of ws
Is it applicable for Node or Browser or both Node
Do you expect this plugin to be commonly used Weekly Downloads: 10M (https://www.npmjs.com/package/ws)
What version of plugin are you interested in using Versions: 5 - 7 (cover last 2 years of releases)
Additional context
- Is there a reference you could point for the well-defined lifecycle methods
I believe only elastic implemented an intrumentation for this module (https://github.com/elastic/apm-agent-nodejs/blob/master/lib/instrumentation/modules/ws.js)
Should we also support web socket on web too then ?
Does websocket have a place to put the traceparent? afaik there is no way to add the tracing info without potentially modifying the user's payload?
@obecny I believe we should at some point but i would prefer to open a dedicated issue
@dyladan The websocket handshake is done in http, so we could use that i believe. It depend if we want one trace per connection or one trace per packet
One per connection is of dubious value... Most websocket use cases are long running and encompass many user actions.
I would love to take this task. Would take me some time to solve though.
@nstawski Feel free to ping me if you need any help or guidance on that, i've already looked up on how to implement that in the past.
Moving to contrib repo, also @nstawski did you started to work on that ?
I for one would love this on both the node and browser side. I'd happily modify my payload with trace/span info to get tracing. Has anyone started to work on a solution for this? @vmarchaud
@dajulia3 I think nobody is currently working on it. @nstawski started working on it a while ago but she's not been involved in the project recently
No sign from @nstawski, i'll assign it to you @dajulia3 then
@dajulia3 can you please confirm you are working on that ?
@vmarchaud @obecny I'm not actively working on instrumenting that library per se... I'm about to implement a bit of custom instrumentation for socket stream rpc calls which an older node app is using. If there are any relevant learnings from that I'll be happy to share them.
I'd really like to make this a thing -- does anyone have any insight into if this is harder than it seems or half baked work we could adapt into a PR?
I'd really like to make this a thing -- does anyone have any insight into if this is harder than it seems or half baked work we could adapt into a PR?
I don't think this is specially hard but it depend on what you want to achieve:
- making a new websocket connection create a span
- sending a msg on a websocket connection create a span
- do one of above while propagating the context (aka sending the span/trace id when sending a msg)
The last task is quite complicated because the ws protocol doesnt have any way to add metadata for a given message (as i said in one of my first messages is that you could do it for each connection but thats not for every use case). I would suggest to start by creating a span for each message and see from there
we just released a socket.io plugin check it out
we just released a socket.io plugin check it out
Will this work with
ws
package?
no, only with the socket.io
package
I put together this instrumentation for the ws
library here: https://www.npmjs.com/package/opentelemetry-instrumentation-ws , it traces the client side connection initiation and the server side, including the upgrade
event and WebSocket
initiation. We use the normal http propagators for http requests right now such that if you make a server to server ws connection propagation works great, but in the browser, I think we'll need something different because you can't set arbitrary headers on outgoing websocket HTTP requests. I think that will have to be done within whatever websocket protocol you're using as there's no other sidechannel I am aware of. We're gonna work on this for graphql-ws
as well using it's ConnectionInit
protocol message.
We've been running it in production for a few weeks now and it has helped us understand our websocket woes a lot better. We'd would love any feedback from some early adopters, especially around what should constitute a new trace vs a span within a long lived connection like a websocket. I think we'll love to upstream it to this contrib repo after building a bit more confidence it is the right shape! Source here: https://github.com/gadget-inc/opentelemetry-instrumentations/tree/main/packages/opentelemetry-instrumentation-ws
@airhorns nice work on opentelemetry-instrumentation-ws
package. Any idea if something similar exists for websocket server initialized with Fastify
?
I am running a fastify server and using @opentelemetry/instrumentation-fastify
package to collect traces for http requests. But it doesn't seem to work with fastify websocket server.
Are there any plans to migrate the ws instrumentation to this repository?