Skip to content

Commit

Permalink
Trace (#403)
Browse files Browse the repository at this point in the history
* feat: add trace

* feat: remove sentry & useTrace

* feat: update trace url

---------

Co-authored-by: onePone <[email protected]>
  • Loading branch information
zhangtao25 and Xremn authored Aug 17, 2023
1 parent 7a0a4c0 commit 7a42ed8
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 108 deletions.
1 change: 0 additions & 1 deletion packages/arex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@arextest/monaco-react": "^4.5.1",
"@sentry/react": "^7.56.0",
"ahooks": "^3.7.5",
"allotment": "^1.18.1",
"antd": "^5.6.4",
Expand Down
17 changes: 3 additions & 14 deletions packages/arex/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {
ArexCoreProvider,
ArexMenuManager,
ArexPaneManager,
getLocalStorage,
} from '@arextest/arex-core';
import * as Sentry from '@sentry/react';
import { ArexCoreProvider, ArexMenuManager, ArexPaneManager } from '@arextest/arex-core';
import React from 'react';

import { EMAIL_KEY } from '@/constant';

import { useAuthentication } from './hooks';
import { useAuthentication, useTrace } from './hooks';
import resources from './i18n';
import Menus from './menus';
import Panes from './panes';
Expand All @@ -20,11 +12,8 @@ import GlobalStyle from './style/GlobalStyle';
// register menus and panes
ArexPaneManager.registerPanes(Panes);
ArexMenuManager.registerMenus(Menus);
const email = getLocalStorage<string>(EMAIL_KEY);
const App = () => {
if (email) {
Sentry.setTag('arex-user', email);
}
useTrace('http://trace.arextest.com:8080/graphql');
useAuthentication();
const { theme, compact, colorPrimary, language } = useUserProfile();

Expand Down
3 changes: 3 additions & 0 deletions packages/arex/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ export const DEFAULT_THEME =
export const DEFAULT_COLOR_PRIMARY = ColorPrimary.green;

export const MAX_PANES_COUNT = 8;

// custom event type
export const AREX_OPEN_NEW_PANEL = 'arexOpenNewPanel';
1 change: 1 addition & 0 deletions packages/arex/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { default as useCheckChrome } from './useCheckChrome';
export { default as useColorPrimary } from './useColorPrimary';
export { default as useInit } from './useInit';
export { default as useNavPane } from './useNavPane';
export { default as useTrace } from './useTrace';
30 changes: 30 additions & 0 deletions packages/arex/src/hooks/useTrace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { getLocalStorage, Pane } from '@arextest/arex-core';
import { useEffect } from 'react';

import { AREX_OPEN_NEW_PANEL, EMAIL_KEY } from '@/constant';
import { request } from '@/utils';

const useTrace = (url: string) => {
useEffect(() => {
window.addEventListener(AREX_OPEN_NEW_PANEL, (e: CustomEvent<Pane>) => {
request.post(url, {
query: `mutation ReportTraceData($data: String!) { reportTraceData(data: $data) {id}}`,
operationName: 'ReportTraceData',
variables: {
data: JSON.stringify([
{
key: 'url',
value: e.detail.type,
},
{
key: 'username',
value: getLocalStorage(EMAIL_KEY) || 'unknown',
},
]),
},
});
});
}, []);
};

export default useTrace;
19 changes: 0 additions & 19 deletions packages/arex/src/sentry.ts

This file was deleted.

9 changes: 8 additions & 1 deletion packages/arex/src/store/useMenusPanes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { create } from 'zustand';
import { persist, subscribeWithSelector } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';

import { DEFAULT_ACTIVE_MENU, MAX_PANES_COUNT } from '@/constant';
import { AREX_OPEN_NEW_PANEL, DEFAULT_ACTIVE_MENU, MAX_PANES_COUNT } from '@/constant';

export type MenusPanesState = {
collapsed: boolean;
Expand Down Expand Up @@ -111,6 +111,13 @@ export const useMenusPanes = create(
if (state.panes.length > MAX_PANES_COUNT) {
state.panes.shift();
}

// dispatch event to open new pane
const event = new CustomEvent(AREX_OPEN_NEW_PANEL, {
detail: newPane,
});
window.dispatchEvent(event);

// insert new pane with sortIndex
state.panes.push(newPane);
});
Expand Down
2 changes: 0 additions & 2 deletions packages/arex/src/store/useUserProfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getLocalStorage, i18n, I18nextLng, setLocalStorage, Theme } from '@arextest/arex-core';
import * as Sentry from '@sentry/react';
import { message } from 'antd';
import { create } from 'zustand';

Expand Down Expand Up @@ -30,7 +29,6 @@ const useUserProfile = create<UserProfile & UserProfileAction>((set) => {
let profile: UserProfile | undefined;
try {
profile = await UserService.getUserProfile(_email);
Sentry.setTag('arex-user', email);
} catch (e: any) {
// 由于后端没有过期的responseCode,所以单独在这里判断。
if (e?.responseCode === 4) {
Expand Down
10 changes: 9 additions & 1 deletion packages/arex/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// <reference types="vite/client" />
import { Pane } from '@arextest/arex-core';
import { MessageInstance } from 'antd/es/message/interface';
export {};

import { AREX_OPEN_NEW_PANEL } from '@/constant';

declare global {
interface Window {
monaco: any;
Expand All @@ -9,4 +12,9 @@ declare global {
__AREX_EXTENSION_VERSION__: string; // arex-chrome-extension 最新版本号
__AREX_DESKTOP_AGENT__: boolean; //是否安装了arex桌面代理
}

// custom event type
interface WindowEventMap {
[AREX_OPEN_NEW_PANEL]: CustomEvent<Pane>;
}
}
71 changes: 1 addition & 70 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a42ed8

Please sign in to comment.