Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦 feat: 新增性能跟踪功能 #3

Open
CharCaius opened this issue Nov 8, 2024 · 2 comments
Open

📦 feat: 新增性能跟踪功能 #3

CharCaius opened this issue Nov 8, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@CharCaius
Copy link
Collaborator

此代码应插入在<head>标签的首部以获取相对准确的数据

📦 feat: 新增性能跟踪功能

  • 集成 Aegis 性能监测 SDK
  • 启用了页面性能和资源加载速度报告
  • 增加了性能瓶颈检测

以下代码需插入主页面内

<script src="https://tam.cdn-go.cn/aegis-sdk/latest/aegis.f.min.js" crossorigin="anonymous"></script>
<script>let VisitorID = localStorage.getItem('VisitorID'); if (!VisitorID) { VisitorID = (function () { const array = new Uint32Array(3); window.crypto.getRandomValues(array); return array.join('').slice(0, 10) })(); localStorage.setItem('VisitorID', VisitorID); console.log("UIN:", VisitorID) } else { console.log("UIN:", VisitorID) } document.getElementById('VisitorID').innerText = VisitorID; const AegisENVs = Object.freeze({ prod: 'production', dev: 'development', gray: 'gray', pre: 'pre', daily: 'daily', local: 'local', test: 'test', others: 'others' }); let env = AegisENVs.prod; fetch('/config.json').then(res => res.json()).then(config => { env = AegisENVs[config.aegis_env] || AegisENVs.prod }).catch(error => { console.error('获取上报环境失败:', error); env = AegisENVs.dev });</script>
<!-- Aegis Init-->
<script>
    if (typeof Aegis === 'function') {
        var aegis = new Aegis({
            // Env
            id: 'mZxy9hL2PY1GozZLD9',
            uin: VisitorID,
            env: env,
            hostUrl: 'https://rumt-zh.com',

            // Speed Report
            reportApiSpeed: true,
            pagePerformance: true,
            reportAssetSpeed: true,
            speedSample: false,

            // Error Report
            onError: true,

            // SPA Set
            spa: true,

            // API
            api: {
                // Report
                apiDetail: true,
                reportRequest: true,
                websocketHack: true,
                usePerformanceTiming: true,

                // Trace Header
                // injectTraceHeader: 'traceparent',

                // Header Report
                // reqHeaders: ['traceparent'],
                resHeaders: ['content-type', 'server'],

                // Ignore URL
                // injectTraceIgnoreUrls: ['/gstatic.com/', '/bilibili.com/'],

                // RC Report
                // retCodeHandler(data, url, xhr) {

                // }
            }
        });
    }
</script>
@CharCaius
Copy link
Collaborator Author

对应的一个配置文件config.json内容如下:

{"aegis_env":"prod"}

没错,就这么短

@CharCaius CharCaius closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2024
@CharCaius CharCaius reopened this Nov 8, 2024
@CharCaius CharCaius assigned CharCaius and unassigned CharCaius Nov 8, 2024
@CharCaius CharCaius added the enhancement New feature or request label Nov 8, 2024
@CharCaius
Copy link
Collaborator Author

回顾发现写错咯。。。。。我服了

<script src="https://tam.cdn-go.cn/aegis-sdk/latest/aegis.f.min.js" crossorigin="anonymous"></script>
<script>let VisitorID=localStorage.getItem('VisitorID');if(!VisitorID){VisitorID=(function(){const array=new Uint32Array(3);window.crypto.getRandomValues(array);return array.join('').slice(0,10)})();localStorage.setItem('VisitorID',VisitorID);console.log("UIN:",VisitorID)}else{console.log("UIN:",VisitorID)}const AegisENVs=Object.freeze({prod:'production',dev:'development',gray:'gray',pre:'pre',daily:'daily',local:'local',test:'test',others:'others'});let env=AegisENVs.prod;fetch('/config.json').then(res=>res.json()).then(config=>{env=AegisENVs[config.aegis_env]||AegisENVs.prod}).catch(error=>{console.error('获取上报环境失败:',error);env=AegisENVs.dev});</script>
<!-- Aegis Init-->
<script>
    if (typeof Aegis === 'function') {
        var aegis = new Aegis({
            // Env
            id: 'mZxy9hL2PY1GozZLD9',
            uin: VisitorID,
            env: env,
            hostUrl: 'https://rumt-zh.com',

            // Speed Report
            reportApiSpeed: true,
            pagePerformance: true,
            reportAssetSpeed: true,
            speedSample: false,

            // Error Report
            onError: true,

            // SPA Set
            spa: true,

            // API
            api: {
                // Report
                apiDetail: true,
                reportRequest: true,
                websocketHack: true,
                usePerformanceTiming: true,

                // Trace Header
                // injectTraceHeader: 'traceparent',

                // Header Report
                // reqHeaders: ['traceparent'],
                resHeaders: ['content-type', 'server'],

                // Ignore URL
                // injectTraceIgnoreUrls: ['/gstatic.com/', '/bilibili.com/'],

                // RC Report
                // retCodeHandler(data, url, xhr) {

                // }
            }
        });
    }
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant