Skip to content

Commit

Permalink
feat: Add event origin tags and also move sdkInfo into an integration (
Browse files Browse the repository at this point in the history
  • Loading branch information
jennmueng authored Jun 8, 2021
1 parent fef9ff0 commit 1ce8b46
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 33 deletions.
34 changes: 1 addition & 33 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export {
User,
} from '@sentry/types';

import { addGlobalEventProcessor } from '@sentry/core';
export {
addGlobalEventProcessor,
addBreadcrumb,
Expand All @@ -37,37 +36,6 @@ export {
withScope,
} from '@sentry/core';

import { SDK_NAME, SDK_VERSION } from './version';

export { SDK_NAME, SDK_VERSION } from './version';
export { CapacitorOptions } from './options';

export { init, nativeCrash } from './sdk';

/**
* Adds the SDK info. Make sure this is called after @sentry/capacitor's so this is the top-level SDK.
*/
function createCapacitorEventProcessor(): void {
if (addGlobalEventProcessor) {
addGlobalEventProcessor(event => {
event.platform = event.platform || 'javascript';
event.sdk = {
...event.sdk,
name: SDK_NAME,
packages: [
...((event.sdk && event.sdk.packages) || []),
{
name: 'npm:@sentry/capacitor',
version: SDK_VERSION,
},
],
version: SDK_VERSION,
};

return event;
});
}
}

createCapacitorEventProcessor();

export { SDK_NAME, SDK_VERSION };
28 changes: 28 additions & 0 deletions src/integrations/eventorigin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { EventProcessor, Integration } from '@sentry/types';

/** Default EventOrigin instrumentation */
export class EventOrigin implements Integration {
/**
* @inheritDoc
*/
public static id: string = 'EventOrigin';

/**
* @inheritDoc
*/
public name: string = EventOrigin.id;

/**
* @inheritDoc
*/
public setupOnce(addGlobalEventProcessor: (e: EventProcessor) => void): void {
addGlobalEventProcessor(event => {
event.tags = event.tags ?? {};

event.tags['event.origin'] = 'javascript';
event.tags['event.environment'] = 'javascript';

return event;
});
}
}
2 changes: 2 additions & 0 deletions src/integrations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { EventOrigin } from './eventorigin';
export { SdkInfo } from './sdkinfo';
39 changes: 39 additions & 0 deletions src/integrations/sdkinfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { EventProcessor, Integration } from '@sentry/types';

import { SDK_NAME, SDK_VERSION } from '../version';

/** Default SdkInfo instrumentation */
export class SdkInfo implements Integration {
/**
* @inheritDoc
*/
public static id: string = 'SdkInfo';

/**
* @inheritDoc
*/
public name: string = SdkInfo.id;

/**
* @inheritDoc
*/
public setupOnce(addGlobalEventProcessor: (e: EventProcessor) => void): void {
addGlobalEventProcessor(event => {
event.platform = event.platform || 'javascript';
event.sdk = {
...event.sdk,
name: SDK_NAME,
packages: [
...((event.sdk && event.sdk.packages) || []),
{
name: 'npm:@sentry/capacitor',
version: SDK_VERSION,
},
],
version: SDK_VERSION,
};

return event;
});
}
}
3 changes: 3 additions & 0 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { Hub, makeMain } from '@sentry/hub';
import { RewriteFrames } from '@sentry/integrations';

import { EventOrigin, SdkInfo } from './integrations';
import { CapacitorOptions } from './options';
import { CapacitorScope } from './scope';
import { NativeTransport } from './transports/native';
Expand Down Expand Up @@ -61,6 +62,8 @@ export function init<O>(
return frame;
},
}),
new SdkInfo(),
new EventOrigin(),
];

if (typeof finalOptions.enableNative === 'undefined') {
Expand Down

0 comments on commit 1ce8b46

Please sign in to comment.