question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce Multiplexing Transport

See original GitHub issue

Problem Statement

Usage of multiple hubs/clients has been a long standing issue within the SDK. https://github.com/getsentry/sentry-javascript/issues?q=is%3Aopen+is%3Aissue+label%3A"Feature%3A+Multiple+hubs%2Fclients"

A big use case for using multi-hub is to send Sentry event’s to different projects. By introducing an optional transport multiplexer, we can allow users to route envelopes to different DSNs (or the same envelope to multiple DSNs).

This means users can route events to different Sentry projects based on any characteristics of an event - like tags, stacktrace or contexts

Solution Brainstorm

Most transports constructors right now (makeFetchTransport, makeXHRTransport) are a function that takes some transport options and returns a transport.

transport: (options: TransportOptions) => Transport

We could then make a wrapper class typed like so:

type DsnToMatcher = {
  // TODO: Adjust matcher function type based on UX needs
  [dsn: string]: (type: string, envelopeItemBody: unknown, envelopeItem: BaseEnvelopeItem) => boolean;
}

type TransportCreator = (options: TransportOptions) => Transport
type TransportMultiplexer = (opts: DsnToMatcher, wrappedTransport: TransportCreator) => TransportCreator;

It’s just a wrapper func, so it would be used like so:

Sentry.init({
  dsn: ...,
  transport: multiplexTransport(makeFetchTransport),
});

There are a couple open questions here:

  • Do we make this errors/transaction only? What do we do about sessions, attachments and other envelope items
  • How do we easily design the API so that it can we can route to different DSNs and send envelopes to multiple DSNs at the same time.
  • Do we expose entire envelope items? Or just the body.

There is an argument that this needs can just be a code snippet in docs, instead of exporting something, but it would be nice to have this functionality out of the box to address some of the MFE concerns.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
lobsterkatiecommented, May 31, 2022

I think this is a good idea! Our current workaround (using beforeSend to do the routing) only works for errors, and it would be nice to have an easy way for folks to make this work.

A few thoughts:

Do we make this errors/transaction only? What do we do about sessions, attachments and other envelope items

I think it only makes sense if we do it for everything, otherwise you still have one project’s data getting stored in another project. (This does beg the question of what to do when there are multiple items in an envelope, of course, but I think we can figure that out.)

How do we easily design the API so that it can we can route to different DSNs and send envelopes to multiple DSNs at the same time.

The matcher that you’re envisioning - is the idea that for each DSN, we’d run the corresponding matcher, and if it returned true, we’d send to that DSN, and if it returned false, we wouldn’t?

It feels much more intuitive to me (and is probably less code for users) to have people write one function (rather than one per DSN) and have it return the DSNs which should receive the event/session/etc. (We can figure out the easiest way to handle default behavior, if users want that for most stuff by not everything.)

Do we expose entire envelope items? Or just the body.

I def think just the body. There’s nothing in the headers people need, IMHO, and besides, envelopes are an implementation detail that I’d rather not tie us to with public API.

0reactions
yordiscommented, Jun 7, 2022

I like your idea to use tags and let the user do whatever they want

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiplexing and Demultiplexing in Transport Layer
Delivering received segments at the receiver side to the correct app layer processes is called demultiplexing. Figure – Abstract view of ...
Read more >
Transport Layer Multiplexing and Demultiplexing - Medium
In this post we are going to talk about how multiplexing and demultiplexing happens at the transport layer. Before we jump into the...
Read more >
Transport Layer - Multiplexing and Demultiplexing - YouTube
... of connectionless and connection-oriented multiplexing and demultiplexing at the transport layer. ... Introduction to Computer Networks ...
Read more >
Multiplexing - Wikipedia
The multiplexing divides the capacity of the communication channel into several logical channels, one for each message signal or data stream to be...
Read more >
What is multiplexing and how does it work? - TechTarget
Multiplexing is used in a wide range of industries to facilitate both analog and digital communications. It was first introduced in the 1870s...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found