Skip to content

Commit 8a808bd

Browse files
committed
feat: 性能、异常信息上报
1 parent 755f57d commit 8a808bd

File tree

22 files changed

+448
-29
lines changed

22 files changed

+448
-29
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 用于错误日志、性能检测的 Azure Application Insights 连接字符串
2+
EXPO_PUBLIC_AZURE_APPLICATION_INSIGHTS_CONNECTION_STRING=

.github/copilot-instructions.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# MusicFree 项目说明
2+
3+
## 项目简介
4+
MusicFree 是一个基于 React Native 的音乐播放器应用。
5+
6+
## 常见任务
7+
### 如何新增多语言支持
8+
1.`src/core/i18n/languages/` 目录下新增对应语言的 JSON 文件,例如 `zh-cn.json` 用于简体中文支持。
9+
2.`src/types/core/i18n/index.d.ts` 文件中添加对应的语言类型定义。

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ keystore.properties
8080
.vscode/
8181
tmp/
8282
scripts/
83+
.env.production.local
84+
.env.local
8385

8486
*.log
8587
# Expo

babel.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1+
const path = require('path');
2+
try {
3+
require('dotenv').config({ path: path.resolve(__dirname, '.env.local') });
4+
require('dotenv').config({ path: path.resolve(__dirname, '.env') });
5+
} catch (e) {
6+
console.warn('dotenv not found, skipping env loading');
7+
}
8+
19
module.exports = {
210
presets: ['babel-preset-expo'],
311
plugins: [
12+
[
13+
'transform-inline-environment-variables',
14+
{
15+
include: [
16+
'EXPO_PUBLIC_AZURE_APPLICATION_INSIGHTS_CONNECTION_STRING'
17+
]
18+
}
19+
],
420
[
521
'module-resolver',
622
{

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"prepare": "husky"
2323
},
2424
"dependencies": {
25+
"@microsoft/applicationinsights-react-native": "^4.3.8",
26+
"@microsoft/applicationinsights-web": "^3.3.10",
2527
"@react-native-async-storage/async-storage": "1.23.1",
2628
"@react-native-clipboard/clipboard": "^1.15.0",
2729
"@react-native-community/netinfo": "11.4.1",
@@ -109,7 +111,9 @@
109111
"@types/react-test-renderer": "^18.0.0",
110112
"babel-jest": "^29.6.3",
111113
"babel-plugin-module-resolver": "^5.0.2",
114+
"babel-plugin-transform-inline-environment-variables": "^0.4.4",
112115
"babel-plugin-transform-remove-console": "^6.9.4",
116+
"dotenv": "^17.2.3",
113117
"eslint": "^8.19.0",
114118
"eslint-config-prettier": "^9.1.0",
115119
"husky": "^9.1.4",

release/telemetry.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

src/components/errorBoundary/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import rpx from "@/utils/rpx";
66
import LinkText from "@/components/base/linkText";
77
import { ImgAsset } from "@/constants/assetsConst";
88
import ThemeText from "@/components/base/themeText";
9+
import telemetry from "@/core/telemetry";
910

1011
interface DeviceInfoProps {
1112
colors: any;
@@ -52,7 +53,9 @@ function DeviceInfoSection({ colors }: DeviceInfoProps) {
5253
};
5354

5455
getDeviceInfo();
55-
}, []); const systemDisplayName = Platform.OS === "ios" ? "iOS" : "Android";
56+
}, []);
57+
58+
const systemDisplayName = Platform.OS === "ios" ? "iOS" : "Android";
5659

5760
return (
5861
<View style={[styles.deviceInfoBox, { backgroundColor: colors.card, borderColor: colors.divider }]}>
@@ -76,6 +79,10 @@ function DeviceInfoSection({ colors }: DeviceInfoProps) {
7679
<Text style={[styles.deviceInfoLabel, { color: colors.textSecondary }]}>设备型号:</Text>
7780
<Text style={[styles.deviceInfoValue, { color: colors.text }]}>{deviceInfo.deviceBrand} {deviceInfo.deviceModel}</Text>
7881
</View>
82+
<View style={styles.deviceInfoRow}>
83+
<Text style={[styles.deviceInfoLabel, { color: colors.textSecondary }]}>DebugID:</Text>
84+
<Text style={[styles.deviceInfoValue, { color: colors.text }]}>{telemetry.sessionId}</Text>
85+
</View>
7986
</View>
8087
</View>
8188
);
@@ -116,6 +123,9 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
116123

117124
// 这里可以添加错误日志上报
118125
console.error("ErrorBoundary caught an error:", error, errorInfo);
126+
telemetry.logException(error, {
127+
i: errorInfo,
128+
});
119129
}
120130

121131
render() {

src/core/i18n/languages/en-us.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@
300300
"basicSettings.developer.devLog": "Debug Panel",
301301
"basicSettings.developer.viewErrorLog": "View Error Logs",
302302
"basicSettings.developer.clearLog": "Clear Logs",
303+
"basicSettings.developer.disableTelemetry": "Disable automatic reporting of performance and exception information",
303304
"editMusicSheetInfo.title": "Edit Playlist Info",
304305
"editMusicSheetInfo.changeCoverImageButton": "Change Cover",
305306
"editMusicSheetInfo.resetCoverImageButton": "Reset to Default",
@@ -331,6 +332,7 @@
331332
"toast.logCleared": "Logs cleared",
332333
"toast.noFloatWindowPermission": "No float window permission",
333334
"toast.folderNotExistOrNoPermission": "Folder doesn't exist or no permission",
335+
"toast.telemetryNotAvailable": "Automatic reporting of performance and exception information is temporarily unavailable",
334336
"musicQuality.low": "Low Quality",
335337
"musicQuality.standard": "Standard Quality",
336338
"musicQuality.high": "High Quality",

src/core/i18n/languages/zh-cn.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@
300300
"basicSettings.developer.devLog": "调试面板",
301301
"basicSettings.developer.viewErrorLog": "查看错误日志",
302302
"basicSettings.developer.clearLog": "清空日志",
303+
"basicSettings.developer.disableTelemetry": "禁止自动上报性能和异常信息",
303304
"editMusicSheetInfo.title": "编辑歌单信息",
304305
"editMusicSheetInfo.changeCoverImageButton": "更换封面",
305306
"editMusicSheetInfo.resetCoverImageButton": "恢复默认",
@@ -331,6 +332,7 @@
331332
"toast.logCleared": "日志已清空",
332333
"toast.noFloatWindowPermission": "无悬浮窗权限",
333334
"toast.folderNotExistOrNoPermission": "文件夹不存在或无权限",
335+
"toast.telemetryNotAvailable": "自动上报性能、异常信息功能暂不可用",
334336
"musicQuality.low": "低音质",
335337
"musicQuality.standard": "标准音质",
336338
"musicQuality.high": "高音质",

src/core/i18n/languages/zh-tw.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@
300300
"basicSettings.developer.devLog": "調試面板",
301301
"basicSettings.developer.viewErrorLog": "查看錯誤日誌",
302302
"basicSettings.developer.clearLog": "清空日誌",
303+
"basicSettings.developer.disableTelemetry": "禁止自動上報性能和異常信息",
303304
"editMusicSheetInfo.title": "編輯歌單資訊",
304305
"editMusicSheetInfo.changeCoverImageButton": "更換封面",
305306
"editMusicSheetInfo.resetCoverImageButton": "恢復預設",
@@ -331,6 +332,7 @@
331332
"toast.logCleared": "日誌已清空",
332333
"toast.noFloatWindowPermission": "無懸浮窗權限",
333334
"toast.folderNotExistOrNoPermission": "文件夾不存在或無權限",
335+
"toast.telemetryNotAvailable": "自動上報性能、異常信息功能暫不可用",
334336
"musicQuality.low": "低音質",
335337
"musicQuality.standard": "標準音質",
336338
"musicQuality.high": "高音質",

0 commit comments

Comments
 (0)