Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Micro integrations #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion methods/flex-micro.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {default_host_init} from './init.js';
import {compose_event_processor} from './lib.js';

/* All the code included in this repository is intended as example only and should NOT be
* adopted for use in production software without first undergoing full review and rigorous
Expand Down Expand Up @@ -297,12 +298,49 @@ window.SENTRY_INIT_METHODS["flex-micro"] = {
}

var init_micro_client = function() {
const integrationIndex = {};

if (!integrations?.length) {
integrations = [new sdk.Integrations.Dedupe()];
}

// Custom integration event processor to define integrations on the event
let event_processor = (event) => {
if (event) {

if (!event.sdk) {
event.sdk = {};
}

event.sdk.integrations = integrations.map(Integration => Integration.name);
}

return event;
};

integrations.forEach((integration) => {
integrationIndex[integration.name] = integration;

integration.setupOnce(
(f) => {
event_processor = event_processor
? compose_event_processor(event_processor, f)
: f;
},
() => ({
getIntegration: (integration) => integrationIndex[integration.name],
getClient: () => window.__SENTRY_MICRO__.instances[component_name].client
})
)
});

window.__SENTRY_MICRO__.instances[component_name].client = new Sentry.BrowserClient({
dsn: MICRO_DSN,
release: MICRO_RELEASE,
debug: !(debug === undefined || debug === false), /* remove this (sandbox) */
transport: ("fetch" in window ? Sentry.makeFetchTransport : Sentry.makeXHRTransport),
integrations: []
integrations: [],
beforeSend: (event, hint) => event_processor(event, hint)
});
}

Expand Down
3 changes: 3 additions & 0 deletions methods/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function compose_event_processor(...functions) {
return (event, hint) => functions.reduceRight((acc, func) => func(acc, hint), event);
}