Skip to content

Commit

Permalink
feat: add telemetry to aware of the presence of other deployment inst…
Browse files Browse the repository at this point in the history
…ances

you can disable it by env DISABLE_TELEMETRY=1
  • Loading branch information
moonrailgun committed Oct 31, 2023
1 parent c7c05b5 commit c25d3a0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions client/shared/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export {
isBrowser,
isNavigator,
isDevelopment,
isProduction,
version,
} from './utils/environment';
export type { PermissionItemType } from './utils/role-helper';
Expand Down
5 changes: 5 additions & 0 deletions client/shared/model/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export interface GlobalConfig {
*/
disableAddFriend?: boolean;

/**
* 是否禁用遥测
*/
disableTelemetry?: boolean;

announcement?:
| false
| {
Expand Down
1 change: 1 addition & 0 deletions client/shared/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export const defaultGlobalConfig: GlobalConfig = {
disableCreateGroup: false,
disablePluginStore: false,
disableAddFriend: false,
disableTelemetry: false,
announcement: false,
};
2 changes: 2 additions & 0 deletions client/shared/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export const isNavigator = typeof navigator !== 'undefined';

export const isDevelopment = process.env.NODE_ENV === 'development';

export const isProduction = process.env.NODE_ENV === 'production';

export const version = process.env.VERSION || '0.0.0';
19 changes: 15 additions & 4 deletions client/web/src/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import {
t,
fetchGlobalClientConfig,
isDevelopment,
isProduction,
setErrorHook,
showToasts,
parseUrlStr,
onLanguageLoaded,
version,
} from 'tailchat-shared';
import { getPopupContainer } from './utils/dom-helper';
import { getUserJWT } from './utils/jwt-helper';
Expand Down Expand Up @@ -121,7 +123,16 @@ setErrorHook((err) => {
/**
* 获取前端配置
*/
fetchGlobalClientConfig().catch((e) => {
showErrorToasts(t('全局配置加载失败'));
console.error('全局配置加载失败', e);
});
fetchGlobalClientConfig()
.then((config) => {
if (isProduction && !config.disableTelemetry) {
// 发送遥测信息
fetch(
`https://tianji.moonrailgun.com/telemetry/clnzoxcy10001vy2ohi4obbi0/blank.gif?name=tailchat&url=${window.location.origin}&v=${version}`
).catch(() => {});
}
})
.catch((e) => {
showErrorToasts(t('全局配置加载失败'));
console.error('全局配置加载失败', e);
});
1 change: 1 addition & 0 deletions server/packages/sdk/src/services/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const config = {
disableCreateGroup: checkEnvTrusty(process.env.DISABLE_CREATE_GROUP), // 是否禁用用户创建群组功能
disablePluginStore: checkEnvTrusty(process.env.DISABLE_PLUGIN_STORE), // 是否禁用用户插件中心功能
disableAddFriend: checkEnvTrusty(process.env.DISABLE_ADD_FRIEND), // 是否禁用用户添加好友功能
disableTelemetry: checkEnvTrusty(process.env.DISABLE_TELEMETRY), // 是否禁用遥测
},
};

Expand Down
1 change: 1 addition & 0 deletions server/services/core/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class ConfigService extends TcService {
disableCreateGroup: config.feature.disableCreateGroup,
disablePluginStore: config.feature.disablePluginStore,
disableAddFriend: config.feature.disableAddFriend,
disableTelemetry: config.feature.disableTelemetry,
...persistConfig,
};
}
Expand Down

0 comments on commit c25d3a0

Please sign in to comment.