Skip to content

Commit 2963b58

Browse files
authored
feat: add support for sentry v8 (#92)
```js import { fullStoryIntegration } from '@sentry/fullstory'; // ... Sentry.init({ dsn: '__DSN__', integrations: [ fullStoryIntegration('__SENTRY_ORG_SLUG__', { client: FullStory }), ], // ... }); ```
1 parent 3137ffc commit 2963b58

File tree

6 files changed

+72
-80
lines changed

6 files changed

+72
-80
lines changed

.github/workflows/deploy-prep.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Cache node modules
1818
uses: actions/setup-node@v2
1919
with:
20-
node-version: '12'
20+
node-version: '18'
2121
cache: 'yarn'
2222

2323
- name: Install node modules

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
},
2525
"homepage": "https://github.com/getsentry/sentry-fullstory#readme",
2626
"peerDependencies": {
27-
"@sentry/core": "4.x || 5.x || 6.x || 7.x"
27+
"@sentry/core": "8.x"
2828
},
2929
"dependencies": {},
3030
"devDependencies": {
3131
"@babel/core": "^7.7.2",
32-
"@sentry/types": "^7.18.0",
32+
"@sentry/types": "^8.4.0",
3333
"rimraf": "^3.0.0",
3434
"rollup": "^1.26.3",
3535
"rollup-plugin-babel": "^4.3.3",

src/SentryFullStory.ts

+39-65
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { EventProcessor, Hub, Integration } from '@sentry/types';
1+
import type { Integration } from '@sentry/types';
22
import type { FullStoryClient } from './types';
33
import {
44
doesFullStoryExist,
5+
getFullStoryUrl,
56
getOriginalExceptionProperties,
67
getSentryUrl,
78
} from './util';
@@ -17,83 +18,56 @@ type Options = {
1718
baseSentryUrl?: string;
1819
};
1920

20-
class SentryFullStory implements Integration {
21-
public readonly name: string = SentryFullStory.id;
22-
public static id: string = 'SentryFullStory';
23-
sentryOrg: string;
24-
baseSentryUrl: string;
25-
client: FullStoryClient;
26-
27-
constructor(sentryOrg: string, options: Options) {
28-
this.sentryOrg = sentryOrg;
29-
this.client = options.client;
30-
this.baseSentryUrl = options.baseSentryUrl || 'https://sentry.io';
31-
}
32-
33-
getFullStoryUrl = (): Promise<string> | string => {
34-
// getCurrentSessionURL isn't available until after the FullStory script is fully bootstrapped.
35-
// If an error occurs before getCurrentSessionURL is ready, make a note in Sentry and move on.
36-
// More on getCurrentSessionURL here: https://help.fullstory.com/develop-js/getcurrentsessionurl
37-
try {
38-
const res = this.client.getCurrentSessionURL?.(true);
39-
if (!res) {
40-
throw new Error('No FullStory session URL found');
41-
}
42-
43-
return res;
44-
} catch (e) {
45-
const reason = e instanceof Error ? e.message : String(e);
46-
throw new Error(`Unable to get url: ${reason}`);
47-
}
48-
};
21+
const INTEGRATION_NAME = 'SentryFullStory';
4922

50-
setupOnce(
51-
addGlobalEventProcessor: (callback: EventProcessor) => void,
52-
getCurrentHub: () => Hub
53-
) {
54-
let fullStoryUrl: string | undefined;
23+
export function fullStoryIntegration(
24+
sentryOrg: string,
25+
options: Options
26+
): Integration {
27+
const fullStoryClient = options.client;
28+
const baseSentryUrl = options.baseSentryUrl || 'https://sentry.io';
29+
let fullStoryUrl: string | undefined;
5530

56-
addGlobalEventProcessor(async (event, hint) => {
57-
const hub = getCurrentHub();
58-
const self = hub.getIntegration(SentryFullStory);
31+
return {
32+
name: INTEGRATION_NAME,
33+
async processEvent(event, hint, client) {
34+
const self = client.getIntegrationByName(INTEGRATION_NAME);
5935
// Run the integration ONLY when it was installed on the current Hub AND isn't a transaction
60-
if (self && event.type !== 'transaction' && doesFullStoryExist()) {
36+
if (self && event.type === undefined && doesFullStoryExist()) {
6137
if (!fullStoryUrl) {
6238
try {
63-
fullStoryUrl = await this.getFullStoryUrl();
39+
fullStoryUrl = await getFullStoryUrl(fullStoryClient);
6440
} catch (e) {
6541
const reason = e instanceof Error ? e.message : String(e);
6642
console.error(`Unable to get FullStory session URL: ${reason}`);
6743
}
6844
}
45+
}
6946

70-
if (fullStoryUrl) {
71-
event.contexts = {
72-
...event.contexts,
73-
fullStory: {
74-
fullStoryUrl,
75-
},
76-
};
77-
}
47+
if (fullStoryUrl) {
48+
event.contexts = {
49+
...event.contexts,
50+
fullStory: {
51+
fullStoryUrl,
52+
},
53+
};
54+
}
7855

79-
try {
80-
this.client.event('Sentry Error', {
81-
sentryUrl: getSentryUrl({
82-
baseSentryUrl: this.baseSentryUrl,
83-
sentryOrg: this.sentryOrg,
84-
hint,
85-
hub,
86-
}),
87-
...getOriginalExceptionProperties(hint),
88-
});
89-
} catch (e) {
90-
console.debug('Unable to report sentry error details to FullStory');
91-
}
56+
try {
57+
fullStoryClient.event('Sentry Error', {
58+
sentryUrl: getSentryUrl({
59+
baseSentryUrl: baseSentryUrl,
60+
sentryOrg,
61+
hint,
62+
client,
63+
}),
64+
...getOriginalExceptionProperties(hint),
65+
});
66+
} catch (e) {
67+
console.debug('Unable to report sentry error details to FullStory');
9268
}
9369

9470
return event;
95-
});
96-
}
71+
},
72+
};
9773
}
98-
99-
export default SentryFullStory;

src/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import SentryFullStory from './SentryFullStory';
2-
3-
export default SentryFullStory;
1+
export { fullStoryIntegration } from './SentryFullStory';

src/util.ts

+25-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { EventHint, Hub } from '@sentry/types';
1+
import type { Client, EventHint } from '@sentry/types';
2+
import { FullStoryClient } from './types';
23

34
/**
45
* Returns true if Fullstory is installed correctly.
@@ -15,7 +16,7 @@ export const getProjectIdFromSentryDsn = (dsn: string) => {
1516
return new URL(dsn).pathname.replace('/', '');
1617
};
1718

18-
const isError = (exception: string | Error): exception is Error => {
19+
const isError = (exception: unknown): exception is Error => {
1920
return (exception as Error).message !== undefined;
2021
};
2122

@@ -41,16 +42,16 @@ export function getSentryUrl({
4142
hint,
4243
sentryOrg,
4344
baseSentryUrl,
44-
hub,
45+
client,
4546
}: {
4647
hint?: EventHint;
4748
sentryOrg: string;
4849
baseSentryUrl: string;
49-
hub: Hub;
50+
client: Client;
5051
}) {
5152
try {
5253
// No docs on this but the SDK team assures me it works unless you bind another Sentry client
53-
const { dsn } = hub.getClient()?.getOptions() || {};
54+
const { dsn } = client.getOptions();
5455
if (!dsn) {
5556
console.error('No sn');
5657
return 'Could not retrieve url';
@@ -67,3 +68,22 @@ export function getSentryUrl({
6768
return 'Could not retrieve url';
6869
}
6970
}
71+
72+
export function getFullStoryUrl(
73+
fullStoryClient: FullStoryClient
74+
): Promise<string> | string {
75+
// getCurrentSessionURL isn't available until after the FullStory script is fully bootstrapped.
76+
// If an error occurs before getCurrentSessionURL is ready, make a note in Sentry and move on.
77+
// More on getCurrentSessionURL here: https://help.fullstory.com/develop-js/getcurrentsessionurl
78+
try {
79+
const res = fullStoryClient.getCurrentSessionURL?.(true);
80+
if (!res) {
81+
throw new Error('No FullStory session URL found');
82+
}
83+
84+
return res;
85+
} catch (e) {
86+
const reason = e instanceof Error ? e.message : String(e);
87+
throw new Error(`Unable to get url: ${reason}`);
88+
}
89+
}

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@
134134
lodash "^4.17.13"
135135
to-fast-properties "^2.0.0"
136136

137-
"@sentry/types@^7.18.0":
138-
version "7.18.0"
139-
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.18.0.tgz#8b0eacd19cc9bcd1f14ca5dcaf7065ebd3186632"
140-
integrity sha512-bOnyoK1S1chPJ+dAeWJo0srxZ9U48WE5dZFtvKeXoog6JNHY3nqAR/P/uxh9djB4bbwQRMdnGk1zm0bxhOOC6w==
137+
"@sentry/types@^8.4.0":
138+
version "8.4.0"
139+
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-8.4.0.tgz#42500005a198ff8c247490434ed55e0a9f975ad1"
140+
integrity sha512-mHUaaYEQCNukzYsTLp4rP2NNO17vUf+oSGS6qmhrsGqmGNICKw2CIwJlPPGeAkq9Y4tiUOye2m5OT1xsOtxLIw==
141141

142142
"@types/estree@*":
143143
version "0.0.39"

0 commit comments

Comments
 (0)