Skip to content

Revamp the Integrations API #4790

Closed
Closed
@AbhiPrasad

Description

@AbhiPrasad

Problem Statement

Warning: This is a WIP brainstorming doc

Similar to work done in #4660 for the transports, we can update things for the integrations also.

Solution Brainstorm

In this ideal world, we would like to pass in the hub directly to the integration.

Something like

interface NewIntegration {
  name: string;
  setup(hub: Hub): void;
}

The issue here is that this does not work in the node SDK, which relies on storing the hub on the domain. A new hub is constructed for every, but it re-uses the client, so the integrations will only be setup once. This means that they only get a reference to the original hub, not the new hub that comes from each domain.

setHubOnCarrier(activeDomain, new Hub(registryHubTopStack.client, Scope.clone(registryHubTopStack.scope)));

We could have two different hub modes though. In the first hub mode, there is some async storage that stores the hub (domains, async hooks, zonejs etc.) - so getCurrentHub returns the hub thats stored in async storage. In the second hub mode, getCurrentHub just returns the hub that originally created the client + passed in integrations.

interface NewIntegration {
  name: string;
  // does different things based on environment.
  setup(getCurrentHub: () => Hub): void;
}

I recognize this is kind of confusing though, so would appreciate and suggestions for a better API here. Struggling to generate ideas beyond this.

One important thing to note is event processors. We'll need to add event processors to hubs to make this change happen. In addition, we can change the event processor API so that (optionally) we give it the name of the integration that created it. This allows for easier debugging and logging, so users can understand if an event processor dropped an event, why it happened.

type addEventProcessor = (processor: EventProcessor, name?: string) => void;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions