opentelemetry-js-contrib icon indicating copy to clipboard operation
opentelemetry-js-contrib copied to clipboard

automatic tracing of ws

Open vmarchaud opened this issue 5 years ago • 20 comments

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)

vmarchaud avatar Jan 05 '20 17:01 vmarchaud

Should we also support web socket on web too then ?

obecny avatar Jan 07 '20 21:01 obecny

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?

dyladan avatar Jan 07 '20 21:01 dyladan

@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

vmarchaud avatar Jan 07 '20 21:01 vmarchaud

One per connection is of dubious value... Most websocket use cases are long running and encompass many user actions.

dyladan avatar Jan 08 '20 02:01 dyladan

I would love to take this task. Would take me some time to solve though.

nstawski avatar Jan 08 '20 18:01 nstawski

@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.

vmarchaud avatar Jan 09 '20 10:01 vmarchaud

Moving to contrib repo, also @nstawski did you started to work on that ?

vmarchaud avatar Apr 25 '20 16:04 vmarchaud

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 avatar Feb 08 '21 22:02 dajulia3

@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

dyladan avatar Feb 09 '21 15:02 dyladan

No sign from @nstawski, i'll assign it to you @dajulia3 then

vmarchaud avatar Mar 20 '21 17:03 vmarchaud

@dajulia3 can you please confirm you are working on that ?

obecny avatar Mar 22 '21 12:03 obecny

@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.

dajulia3 avatar Mar 26 '21 02:03 dajulia3

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?

airhorns avatar May 09 '21 14:05 airhorns

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

vmarchaud avatar May 09 '21 16:05 vmarchaud

we just released a socket.io plugin check it out

mottibec avatar Jun 03 '21 07:06 mottibec

we just released a socket.io plugin check it out

Will this work with ws package?

roastedmonk avatar Jun 11 '21 16:06 roastedmonk

we just released a socket.io plugin check it out

Will this work with ws package?

no, only with the socket.io package

mottibec avatar Jun 13 '21 08:06 mottibec

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 avatar Jan 18 '22 20:01 airhorns

@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.

muzammil360 avatar Jul 05 '23 14:07 muzammil360

Are there any plans to migrate the ws instrumentation to this repository?

kirrg001 avatar Jan 04 '24 12:01 kirrg001