Skip to content

Introduce Multiplexing Transport #5185

Closed
@AbhiPrasad

Description

@AbhiPrasad

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%22Feature%3A+Multiple+hubs%2Fclients%22

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions