Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Migration in progress

Signed-off-by: Muthukumar <[email protected]>
  • Loading branch information
BenzeneAlcohol committed Jul 23, 2024
1 parent 4692898 commit 9423f5e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,5 @@
"hooks": {
"pre-commit": "npm-run-all -ln --parallel lint test"
}
},
"dependencies": {
"@sentry/browser": "^8.18.0"
}
}
2 changes: 1 addition & 1 deletion packages/jaeger-ui/src/types/tracking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface IWebAnalyticsFunc {

export default interface IWebAnalytics {
init: () => void;
context: boolean | Sentry.BrowserClient | null;
context: boolean | typeof Sentry.BrowserClient | null;
isEnabled: () => boolean;
trackPageView: (pathname: string, search: string | TNil) => void;
trackError: (description: string) => void;
Expand Down
15 changes: 2 additions & 13 deletions packages/jaeger-ui/src/utils/tracking/conv-raven-to-ga.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
// limitations under the License.

/* eslint-disable camelcase */
import { Event as SentryEvent } from '@sentry/browser';
import {Stacktrace, Exception, Breadcrumb} from '@sentry/browser'
import {Exception, Breadcrumb} from '@sentry/browser'

import prefixUrl from '../prefix-url';

Expand All @@ -37,16 +36,6 @@ const FETCH_SYMBOLS = [
{ sym: '__IGNORE__', word: '', rx: /\.js(\.map)?$/i },
];

interface SentryTransportOptions {
url: string;
data: any;
auth: {
sentry_version: string;
sentry_client: string;
sentry_key: string;
};
}

// eslint-disable-next-line no-console
const warn = console.warn.bind(console);

Expand Down Expand Up @@ -350,7 +339,7 @@ function getLabel(message: string, page: string, duration: number, git: string,

// Convert the Raven exception data to something that can be sent to Google
// Analytics. See <./README.md> for details.
export default function convRavenToGa({ data }: SentryTransportOptions) {
export default function convRavenToGa({ data }: { url: string; data: any; }) {
const { breadcrumbs, exception, extra, request, tags } = data;
const { message, stack } = convException(exception?.values?.[0] ?? {});

Expand Down
55 changes: 34 additions & 21 deletions packages/jaeger-ui/src/utils/tracking/ga.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import _get from 'lodash/get';
import Raven, { RavenOptions, RavenTransportOptions } from 'raven-js';
import * as Sentry from '@sentry/browser';

import convRavenToGa from './conv-raven-to-ga';
import { TNil } from '../../types';
Expand All @@ -30,6 +30,13 @@ interface WindowWithGATracking extends Window {
dataLayer: (string | object)[][] | undefined;
}

function convertEventToTransportOptions(event: Sentry.Event): { url: string; data: any; } {
return {
url: event.request?.url || '',
data: event,
};
}

declare let window: WindowWithGATracking;

const isTruish = (value?: string | string[]) => {
Expand All @@ -47,7 +54,7 @@ const GA: IWebAnalyticsFunc = (config: Config, versionShort: string, versionLong
const gaID = _get(config, 'tracking.gaID');
const isErrorsEnabled = isDebugMode || Boolean(_get(config, 'tracking.trackErrors'));
const cookiesToDimensions = _get(config, 'tracking.cookiesToDimensions');
const context = isErrorsEnabled ? Raven : null;
const context = isErrorsEnabled ? Sentry.BrowserClient : null;
const EVENT_LENGTHS = {
action: 499,
category: 149,
Expand Down Expand Up @@ -119,8 +126,8 @@ const GA: IWebAnalyticsFunc = (config: Config, versionShort: string, versionLong
});
};

const trackRavenError = (ravenData: RavenTransportOptions) => {
const { message, category, action, label, value } = convRavenToGa(ravenData);
const trackRavenError = (sentryData: { url: string; data: any; }) => {
const { message, category, action, label, value } = convRavenToGa(sentryData);
trackError(message);
trackEvent(category, action, label, value);
};
Expand Down Expand Up @@ -164,24 +171,30 @@ const GA: IWebAnalyticsFunc = (config: Config, versionShort: string, versionLong
);
}
if (isErrorsEnabled) {
const ravenConfig: RavenOptions = {
autoBreadcrumbs: {
xhr: true,
console: false,
dom: true,
location: true,
Sentry.init({
dsn: 'https://[email protected]/1',
environment: getAppEnvironment() || 'unknown',
integrations: [
Sentry.breadcrumbsIntegration({
xhr: true,
console: false,
dom: true,
}),
],
beforeSend(event) {
const transportOptions = convertEventToTransportOptions(event);
trackRavenError(transportOptions);
return event;
},
environment: getAppEnvironment() || 'unkonwn',
transport: trackRavenError,
};
if (versionShort && versionShort !== 'unknown') {
ravenConfig.tags = {
git: versionShort,
};
}
Raven.config('https://[email protected]/1', ravenConfig).install();
window.onunhandledrejection = function trackRejectedPromise(evt: PromiseRejectionEvent) {
Raven.captureException(evt.reason);
...(versionShort && versionShort !== 'unknown' && {
tags: {
git: versionShort,
},
}),
});

window.onunhandledrejection = function trackRejectedPromise(evt) {
Sentry.captureException(evt.reason);
};
}
};
Expand Down

0 comments on commit 9423f5e

Please sign in to comment.