@qwen-code/qwen-code 0.20.0 → 0.20.1-nightly.20260724.7d17c44a3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundled/qc-helper/docs/configuration/settings.md +1 -1
- package/bundled/qc-helper/docs/features/auto-mode.md +19 -16
- package/bundled/qc-helper/docs/features/commands.md +54 -0
- package/bundled/qc-helper/docs/features/sub-agents.md +16 -7
- package/bundled/qc-helper/docs/integration-github-action.md +1 -1
- package/bundled/qc-helper/docs/qwen-serve.md +2 -1
- package/bundled/review/DESIGN.md +2 -2
- package/bundled/review/SKILL.md +7 -5
- package/chunks/MaxSizedBox-LGRTXB47.js +84 -0
- package/chunks/{StandaloneSessionPicker-CEGO2AZX.js → StandaloneSessionPicker-H3TBU3C3.js} +68 -56
- package/chunks/{acp-startup-profiler-N3RHHXJ3.js → acp-startup-profiler-RV3IV562.js} +2 -2
- package/chunks/{acpAgent-YUR43TLG.js → acpAgent-5D7P4BB5.js} +2061 -556
- package/chunks/agent-W7UAHCCI.js +80 -0
- package/chunks/agent-headless-KTBMPRSC.js +74 -0
- package/chunks/{anthropicContentGenerator-HVKLXOOU.js → anthropicContentGenerator-ZLQ3X2HI.js} +112 -45
- package/chunks/{artifact-tool-WBCAMD3O.js → artifact-tool-OKMWONT6.js} +3 -3
- package/chunks/{askUserQuestion-6DZC4UV5.js → askUserQuestion-V6FUS23G.js} +3 -3
- package/chunks/bridge-FFC4C6VD.js +89 -0
- package/chunks/{build-SSCNEHZZ.js → build-RV63TIRH.js} +2 -3
- package/chunks/{ca-2SL2BXTK.js → ca-GKRQZ7AM.js} +612 -201
- package/chunks/{channel-worker-group-53CMOPFT.js → channel-worker-group-MA3WXWYX.js} +7 -6
- package/chunks/{channel-worker-manager-UTXILKC2.js → channel-worker-manager-TIYYYBCT.js} +189 -29
- package/chunks/{channel-worker-supervisor-ZGO2W2MD.js → channel-worker-supervisor-CXRCDA4Y.js} +6 -5
- package/chunks/{chunk-TYQMGACW.js → chunk-22C7BQ6D.js} +508 -10967
- package/chunks/{chunk-4EP2PYYL.js → chunk-2G6QIHYL.js} +5 -5
- package/chunks/{chunk-H2XVO6NE.js → chunk-2MIN6GRR.js} +1 -1
- package/chunks/chunk-2RFKHEXL.js +74 -0
- package/chunks/{chunk-7SXZC7ID.js → chunk-2WTVWAKT.js} +7 -6
- package/chunks/{chunk-TIH2ZTOC.js → chunk-32A4PI3E.js} +2 -2
- package/chunks/chunk-36HSVBBU.js +469 -0
- package/chunks/{chunk-IR46U7RB.js → chunk-3FB2Y2OE.js} +3 -3
- package/chunks/{chunk-QR6U5QPP.js → chunk-3SJ43L4W.js} +4 -0
- package/chunks/chunk-3Z43GZUQ.js +32 -0
- package/chunks/chunk-43T5WDQ7.js +127 -0
- package/chunks/chunk-46UV252V.js +128 -0
- package/chunks/{chunk-JD3MKVKL.js → chunk-4K56OJFJ.js} +1 -1
- package/chunks/{chunk-KTUQMDEP.js → chunk-4K7VDKAD.js} +1 -1
- package/chunks/{chunk-QKYTTBYW.js → chunk-4LVZNIDO.js} +1 -1
- package/chunks/{chunk-OWCALFEG.js → chunk-54R2CV2G.js} +1 -1
- package/chunks/{chunk-ZEOZL37W.js → chunk-57FIIFJN.js} +1 -1
- package/chunks/chunk-5BS3KLRP.js +6194 -0
- package/chunks/{chunk-NEEB7UEN.js → chunk-6GMVPFB2.js} +153 -72
- package/chunks/{chunk-GMGDLUC7.js → chunk-6IL7KRLE.js} +1 -1
- package/chunks/chunk-6PVPNMXU.js +29 -0
- package/chunks/chunk-6QHAUJUE.js +293 -0
- package/chunks/chunk-6VK3IRTX.js +10017 -0
- package/chunks/{chunk-BDBMYST4.js → chunk-6X4GWOPW.js} +1 -1
- package/chunks/{chunk-AYCDXHZB.js → chunk-7Z6JQEL6.js} +1 -1
- package/chunks/{chunk-FSL5W5TI.js → chunk-AFFGGOF6.js} +4 -4
- package/chunks/chunk-AMDSOFFV.js +10860 -0
- package/chunks/chunk-AXUW635Q.js +934 -0
- package/chunks/{chunk-A5LYNIW7.js → chunk-BJBUDCM3.js} +8 -8
- package/chunks/chunk-BK2UNYWD.js +29 -0
- package/chunks/{chunk-6RLROE6G.js → chunk-BLFVGB7D.js} +30 -4
- package/chunks/chunk-BPJSQIJX.js +100 -0
- package/chunks/{chunk-FLSVD6BS.js → chunk-BRTR7S7O.js} +3 -3
- package/chunks/{chunk-KG3XV6FH.js → chunk-BSNWBC33.js} +32 -2
- package/chunks/chunk-BULDBTYC.js +153 -0
- package/chunks/{chunk-PBWEWI4N.js → chunk-BW5Z5NOG.js} +83 -74
- package/chunks/{chunk-EIAK6Q2B.js → chunk-C3VHAXP2.js} +20 -3
- package/chunks/{chunk-6AFUCL3D.js → chunk-CEZB3XFD.js} +1 -1
- package/chunks/chunk-CHMENNJV.js +1832 -0
- package/chunks/{chunk-TMQ6XQCX.js → chunk-CK3IEEHR.js} +416 -291
- package/chunks/{chunk-OYZWQNWG.js → chunk-CK6UABV2.js} +2 -2
- package/chunks/{chunk-VZQUV7VK.js → chunk-CKTMY3EP.js} +1 -1
- package/chunks/{chunk-VDWBQ5AW.js → chunk-CUPAVLRY.js} +5 -2
- package/chunks/{chunk-I2PYAYFM.js → chunk-CXUFILV3.js} +3 -3
- package/chunks/chunk-DP3IHZGG.js +1498 -0
- package/chunks/{chunk-BMWMT5Y2.js → chunk-DP5GT2MW.js} +7 -375
- package/chunks/{chunk-D22SX43D.js → chunk-DWNZ6PVQ.js} +1 -1
- package/chunks/{chunk-5SCI6E3E.js → chunk-E4IMU4Y5.js} +1 -1
- package/chunks/{chunk-DP5GXXNZ.js → chunk-EL2IQ2S5.js} +5 -1
- package/chunks/{chunk-EZVDJFZ7.js → chunk-ERLGR7GI.js} +1 -1
- package/chunks/{chunk-IVPSS6EL.js → chunk-F5MBYZSU.js} +4 -4
- package/chunks/{chunk-AQIEINAY.js → chunk-F6IYL66A.js} +28 -1766
- package/chunks/{chunk-FEOZBUMT.js → chunk-FODK6UMO.js} +0 -27
- package/chunks/{chunk-PGEPSDJI.js → chunk-FWNZ7CVN.js} +24 -20
- package/chunks/{chunk-5JBR5XIK.js → chunk-G7EFBBVF.js} +220 -141
- package/chunks/chunk-GLNBDYUX.js +38 -0
- package/chunks/{chunk-ANPINBOF.js → chunk-H4YKEV2X.js} +5 -5
- package/chunks/{chunk-TDKQP3M6.js → chunk-HIJQF5B5.js} +1 -1
- package/chunks/{chunk-FQD7GFSV.js → chunk-HJJDKFL5.js} +3 -3
- package/chunks/{chunk-4N3KMAIL.js → chunk-HPWHDJID.js} +152 -35
- package/chunks/{chunk-KQNM4EO7.js → chunk-HQCSRJ3P.js} +138 -6
- package/chunks/chunk-HTR4WV6U.js +327 -0
- package/chunks/{chunk-YWEW33JY.js → chunk-HVO55LUD.js} +7 -7
- package/chunks/{chunk-MJ6S23WZ.js → chunk-HZEWYOVI.js} +5 -5
- package/chunks/chunk-IFG6TYJ2.js +16577 -0
- package/chunks/{chunk-B3KGZCQN.js → chunk-IJTOWOD7.js} +322 -202
- package/chunks/{chunk-RS7MT2QG.js → chunk-IPUUTYMV.js} +2 -4
- package/chunks/{chunk-4ILMYHEI.js → chunk-IRDZJSCL.js} +3 -3
- package/chunks/{chunk-XU457J4V.js → chunk-IRH27ZC2.js} +2 -2
- package/chunks/{chunk-33XUAINQ.js → chunk-J5UKQEFG.js} +69 -9
- package/chunks/{chunk-G45X5TRN.js → chunk-JCW2R7WC.js} +1 -72
- package/chunks/{chunk-S2XVRHDN.js → chunk-JDFBBGRD.js} +1 -1
- package/chunks/{chunk-4XNLIGVA.js → chunk-JKCALGYN.js} +1023 -383
- package/chunks/{chunk-TJTKSVIV.js → chunk-JLU636DO.js} +5 -1
- package/chunks/{chunk-VEXFOTEO.js → chunk-JYUSL2V4.js} +3 -3
- package/chunks/{chunk-S2PD3EZD.js → chunk-KJEMJWNH.js} +1 -1
- package/chunks/{chunk-E2UVIFI2.js → chunk-KRXPRVGL.js} +0 -1
- package/chunks/{chunk-CZF3E5GF.js → chunk-LA5H3LM5.js} +1 -1
- package/chunks/{chunk-NDMQLV4Y.js → chunk-LBAO2XRA.js} +4 -4
- package/chunks/{chunk-7RMOXZTC.js → chunk-LDPP5VTZ.js} +4 -4
- package/chunks/{chunk-KDC6GNQR.js → chunk-LEEWLFHW.js} +4 -4
- package/chunks/{chunk-KX6UK4VJ.js → chunk-LI4I37W4.js} +22152 -18007
- package/chunks/{chunk-OOCI5VVU.js → chunk-LIZRAKPB.js} +1 -1
- package/chunks/{chunk-AJSJ5TTU.js → chunk-LP2E4MQG.js} +1 -1
- package/chunks/chunk-LS77BEZP.js +405 -0
- package/chunks/{chunk-BRRF37CO.js → chunk-LYTBLSSW.js} +5 -5
- package/chunks/{chunk-DBE4QFZS.js → chunk-MB7ENXPR.js} +39 -37
- package/chunks/{chunk-GKY2OJ7R.js → chunk-MOHAWVLH.js} +4 -4
- package/chunks/chunk-NABLFI57.js +82 -0
- package/chunks/chunk-NBQDBANR.js +411 -0
- package/chunks/{chunk-EAUYY7SS.js → chunk-NOAAFNTJ.js} +43 -10
- package/chunks/chunk-NXS53EA7.js +1462 -0
- package/chunks/{chunk-C27BYUX6.js → chunk-OQB4EXO4.js} +14 -11
- package/chunks/{chunk-NHDKSOEY.js → chunk-P3QQPMQA.js} +5 -5
- package/chunks/{chunk-OP4MOGXF.js → chunk-P5RRUHL7.js} +23 -1
- package/chunks/{chunk-KOR3XKCA.js → chunk-PBII2NFX.js} +12 -6
- package/chunks/{chunk-O3OCNYY5.js → chunk-PDYB7HG2.js} +2 -2
- package/chunks/{chunk-2HOVDT7W.js → chunk-PFSUKTZH.js} +1 -1
- package/chunks/chunk-PKL3HGNZ.js +2299 -0
- package/chunks/{chunk-5DTTYNB7.js → chunk-PQNHRFJC.js} +16 -3
- package/chunks/{chunk-OLMETXLX.js → chunk-PXHK5ONM.js} +41 -9
- package/chunks/{chunk-PF4CHQOJ.js → chunk-Q6GU6TKM.js} +11 -10
- package/chunks/{chunk-4ODB7WIB.js → chunk-QAFKR7WR.js} +1 -1
- package/chunks/{chunk-PBATSWUQ.js → chunk-QBUDF33N.js} +1 -1
- package/chunks/{chunk-BVLROR2T.js → chunk-QLJUC7TG.js} +1 -1
- package/chunks/{chunk-UEY4AYUL.js → chunk-QNLNLENL.js} +2 -2
- package/chunks/{chunk-333CXMNJ.js → chunk-QXZTZJLX.js} +5 -5
- package/chunks/chunk-R6D2CTQR.js +289 -0
- package/chunks/{chunk-7PZ2ATFZ.js → chunk-R6SKHK3T.js} +54 -29
- package/chunks/{chunk-OONJNQ42.js → chunk-RGG6M2WF.js} +4 -4
- package/chunks/{chunk-RFIAR4YL.js → chunk-RV4C2ZFG.js} +1 -1
- package/chunks/{chunk-O3Z73NBP.js → chunk-RW2NEXYJ.js} +15 -11
- package/chunks/{chunk-HZPN55E5.js → chunk-SJEDL7DI.js} +1 -1
- package/chunks/{chunk-AKX4WPPP.js → chunk-SWBJRDYC.js} +866 -183
- package/chunks/{chunk-NBMIC7DR.js → chunk-SX4PK3FC.js} +145 -5
- package/chunks/chunk-T3452DP5.js +246 -0
- package/chunks/{chunk-TB6UDU4T.js → chunk-THJNPLI4.js} +16 -16
- package/chunks/{chunk-T4TZQJ7W.js → chunk-TWPJO254.js} +5 -16
- package/chunks/chunk-U7ZFW55U.js +2098 -0
- package/chunks/{chunk-JNWZQ27S.js → chunk-UCOJC6EB.js} +72 -23
- package/chunks/{chunk-W7H223ZZ.js → chunk-UGYMA4EI.js} +1 -1
- package/chunks/{chunk-X6YQWCIJ.js → chunk-UH3WSE5L.js} +13 -1
- package/chunks/{chunk-2LL7TXB4.js → chunk-UH7242DI.js} +3 -3
- package/chunks/{chunk-CB2HFGRV.js → chunk-UJV643E2.js} +31 -6
- package/chunks/chunk-UO7DCGEV.js +121 -0
- package/chunks/{chunk-Y2ENGUD6.js → chunk-UPF7PTBI.js} +79 -2
- package/chunks/chunk-UW5EOVUN.js +249 -0
- package/chunks/{chunk-SJMV7ZBK.js → chunk-VLVO52KC.js} +8 -8
- package/chunks/{chunk-R3VWUU2E.js → chunk-VYPFXUCB.js} +1 -1
- package/chunks/{chunk-S2W2LVDU.js → chunk-WHFK6G6U.js} +8 -9
- package/chunks/chunk-WI3KCKZ5.js +391 -0
- package/chunks/{chunk-NGFEPAE6.js → chunk-WLEFWSSC.js} +8 -6
- package/chunks/{chunk-XVVH63JG.js → chunk-WUJXJ34P.js} +3 -3
- package/chunks/{chunk-MAQQGNQ5.js → chunk-WYLPWQHJ.js} +56 -717
- package/chunks/{chunk-D2VIDMVM.js → chunk-X6N25LXS.js} +2 -2
- package/chunks/chunk-XAWJ2526.js +1049 -0
- package/chunks/{chunk-CV63PP6U.js → chunk-YCIM6O3I.js} +1 -1
- package/chunks/{chunk-OEO2ERWK.js → chunk-Z44CVEUF.js} +54 -33
- package/chunks/{chunk-TKLLK6XQ.js → chunk-ZT4POVWC.js} +11 -11
- package/chunks/{chunk-NIJEXGV6.js → chunk-ZXYUQXY5.js} +148 -10
- package/chunks/{computer-use-NIWQNUZF.js → computer-use-UJ5T34TE.js} +50 -37
- package/chunks/{config-utils-AHQ6YZ66.js → config-utils-XQRXHAN3.js} +3 -3
- package/chunks/contextCommand-CSCB4E5M.js +79 -0
- package/chunks/{create-sub-session-MGNX52P3.js → create-sub-session-55F3GOLK.js} +46 -33
- package/chunks/{create-sub-session-P26FE5GG.js → create-sub-session-JPCSYZAJ.js} +3 -3
- package/chunks/{cron-create-JWFHBDRQ.js → cron-create-CUMELMPL.js} +6 -6
- package/chunks/{cron-delete-GDX4E26G.js → cron-delete-QZFV6U3P.js} +5 -5
- package/chunks/{cron-list-USMAIWPT.js → cron-list-IDKO7ZO2.js} +5 -5
- package/chunks/{daemon-RG2MAI6T.js → daemon-7LP7R6IU.js} +500 -133
- package/chunks/daemon-status-provider-6YNZ3UAE.js +88 -0
- package/chunks/{de-I7ZIYXZC.js → de-4IBXM7CN.js} +5 -1
- package/chunks/{dist-WGTQO7F2.js → dist-376652EZ.js} +114 -28
- package/chunks/{dist-53PZYC5B.js → dist-3YCTE6HD.js} +2 -2
- package/chunks/{dist-2BHAYBKP.js → dist-D7Z3HOO7.js} +14 -2
- package/chunks/{dist-FUTEXY6A.js → dist-MEGJFGAI.js} +40 -9
- package/chunks/{dist-2MIU4UUH.js → dist-NQ436QEX.js} +1 -1
- package/chunks/{dist-AU7NQQRP.js → dist-NQNTOIEN.js} +26 -2
- package/chunks/earlyInputCapture-HPUVJ2KH.js +81 -0
- package/chunks/{edit-3QV3JZJL.js → edit-7CMAN3F4.js} +50 -39
- package/chunks/{en-XE34GKAA.js → en-SALLIJS7.js} +6 -1
- package/chunks/{enter-worktree-4GMMF7EG.js → enter-worktree-3PH4YTY2.js} +49 -36
- package/chunks/{enterPlanMode-L5UWBAUC.js → enterPlanMode-MSXLSWLI.js} +55 -37
- package/chunks/{environment-3OV7UQOT.js → environment-KS36ZHBE.js} +48 -35
- package/chunks/errors-LCPFS62A.js +87 -0
- package/chunks/{exit-worktree-DDP57JLV.js → exit-worktree-ARA4C3CK.js} +49 -36
- package/chunks/{exitPlanMode-CJBLGPIP.js → exitPlanMode-GCDIQPB7.js} +49 -36
- package/chunks/{fast-path-M6RP2ING.js → fast-path-IDHBVIT6.js} +3 -2
- package/chunks/{fr-X7KDVZIY.js → fr-WVHEBDDB.js} +5 -1
- package/chunks/{gemini-H4PHBJTL.js → gemini-2AFQJMX5.js} +141 -105
- package/chunks/{geminiContentGenerator-VURJYPWP.js → geminiContentGenerator-UDIH3YI6.js} +9 -8
- package/chunks/{getMachineId-bsd-EXV7SWPA.js → getMachineId-bsd-QFVLPUPT.js} +1 -1
- package/chunks/{getMachineId-darwin-IUOMFXU3.js → getMachineId-darwin-DGMQQE2E.js} +1 -1
- package/chunks/{getMachineId-linux-K7XJYFHL.js → getMachineId-linux-R4Z6CSWC.js} +1 -1
- package/chunks/{getMachineId-unsupported-EA5FDRJ6.js → getMachineId-unsupported-Z3SBVBUV.js} +1 -1
- package/chunks/{getMachineId-win-KBA6RAI5.js → getMachineId-win-SCK5UFDT.js} +1 -1
- package/chunks/{glob-2KUSRAVQ.js → glob-HCL7HZ67.js} +49 -36
- package/chunks/{grep-B5RXVESV.js → grep-CJLBSCTV.js} +49 -36
- package/chunks/handleAutoUpdate-Q572P3FL.js +80 -0
- package/chunks/i18n-OBB4R7SR.js +96 -0
- package/chunks/initializer-LXEY6V3C.js +85 -0
- package/chunks/installationInfo-XUAOVMEE.js +79 -0
- package/chunks/{ja-2ICT3KXF.js → ja-KY4ROZTE.js} +5 -1
- package/chunks/{keychain-token-storage-DWRJMNH3.js → keychain-token-storage-6ACJDYIB.js} +3 -3
- package/chunks/{kittyProtocolDetector-HCNNKJTI.js → kittyProtocolDetector-MBRTDRBK.js} +5 -3
- package/chunks/list-WAXY7QOU.js +88 -0
- package/chunks/list-agents-AH3P5NB7.js +80 -0
- package/chunks/loadedSettingsAdapter-OZFNBRHE.js +82 -0
- package/chunks/loggingContentGenerator-7WDTTE6G.js +1068 -0
- package/chunks/{loop-wakeup-5GLTUBHA.js → loop-wakeup-IHRW6TNB.js} +7 -7
- package/chunks/{ls-FHBY3Y7I.js → ls-ZAXZ2G2W.js} +5 -5
- package/chunks/{lsp-B6VMEW6Y.js → lsp-R4ZG3UGQ.js} +3 -3
- package/chunks/managed-npm-update-N42DO5QW.js +339 -0
- package/chunks/mcp-6SOORKTY.js +82 -0
- package/chunks/{monitor-GLJZDNPS.js → monitor-4PSVNVU4.js} +51 -37
- package/chunks/node-UUDY34IG.js +305 -0
- package/chunks/nonInteractiveCli-FBR5S7IZ.js +140 -0
- package/chunks/{notebook-edit-AVCIWS4F.js → notebook-edit-QK26632S.js} +50 -39
- package/chunks/{openaiContentGenerator-B7W24G3D.js → openaiContentGenerator-IXJS6C2U.js} +33 -20
- package/chunks/pidfile-UCFCJOAP.js +85 -0
- package/chunks/{processUtils-XZPY2PBB.js → processUtils-YL2LXON2.js} +2 -2
- package/chunks/{pt-JJ4XPIBP.js → pt-OK455PLH.js} +5 -1
- package/chunks/{qwenContentGenerator-6GUTWJIC.js → qwenContentGenerator-H6WZPJKC.js} +56 -36
- package/chunks/{qwenOAuth2-GASEEWGU.js → qwenOAuth2-HTROHKXO.js} +10 -23
- package/chunks/read-file-FOYTMUNL.js +31 -0
- package/chunks/{read-mcp-resource-AKCL7I43.js → read-mcp-resource-65BWNF3F.js} +3 -3
- package/chunks/{record-artifact-PEUB7727.js → record-artifact-2RLSOP6U.js} +3 -3
- package/chunks/resumeHistoryUtils-ZNHTWBXS.js +90 -0
- package/chunks/ripGrep-K4K4QLNJ.js +72 -0
- package/chunks/{ru-STR4KTW7.js → ru-7SPDGMGD.js} +5 -1
- package/chunks/{run-qwen-serve-OZGR3FQA.js → run-qwen-serve-XI4MCAFV.js} +343 -88
- package/chunks/runtime-4CTBU5WX.js +115 -0
- package/chunks/{scheduler-Z7QLMUWA.js → scheduler-TTEITHBF.js} +46 -33
- package/chunks/sdk-exporters-grpc-N3OLDF63.js +23214 -0
- package/chunks/sdk-exporters-http-AOHAEOMC.js +563 -0
- package/chunks/sdk-impl-TLQOC7P4.js +9193 -0
- package/chunks/{send-message-3RHE7HSM.js → send-message-GEY4CNPS.js} +47 -8
- package/chunks/serve-W7UKJTQT.js +88 -0
- package/chunks/{server-SO64U3X5.js → server-JD5PIE7A.js} +3069 -517
- package/chunks/{session-2KL2WQAH.js → session-R4BDHLYR.js} +112 -177
- package/chunks/{settings-KITVOUSV.js → settings-BXZHA6TZ.js} +50 -37
- package/chunks/shell-XYMFCGN5.js +82 -0
- package/chunks/{skill-SOQHY455.js → skill-YKXYEPOF.js} +25 -20
- package/chunks/spawnChannel-IO4HQLFS.js +81 -0
- package/chunks/{src-43LM7JLB.js → src-LKKTJ4NG.js} +382 -235
- package/chunks/standalone-update-76JG7DVN.js +91 -0
- package/chunks/{startInteractiveUI-3RGTGEX5.js → startInteractiveUI-BXWQUXAS.js} +1314 -958
- package/chunks/{syntheticOutput-FG5PQKIR.js → syntheticOutput-2WNMXEU5.js} +4 -4
- package/chunks/task-create-R5H74Y76.js +25 -0
- package/chunks/{task-list-QWSY4ZIU.js → task-list-WXAFDSRY.js} +7 -7
- package/chunks/{task-stop-GWC6UWAL.js → task-stop-CHFZP23W.js} +4 -4
- package/chunks/{task-update-NCTAB73Q.js → task-update-Z44A4GAR.js} +11 -9
- package/chunks/{team-create-FXN3PEBP.js → team-create-5Y3MCAIM.js} +49 -36
- package/chunks/{team-delete-KK37HTOG.js → team-delete-YDCMRSI4.js} +7 -7
- package/chunks/{team-plan-approval-GEIZ356Q.js → team-plan-approval-HYJJZ76T.js} +49 -36
- package/chunks/theme-manager-3YF2SUZL.js +76 -0
- package/chunks/{todoWrite-ERCAMLFS.js → todoWrite-ED2IVZJL.js} +5 -5
- package/chunks/{tool-search-XKK7DNOK.js → tool-search-3ZO2XMEP.js} +21 -17
- package/chunks/total-session-admission-NDF7EVG7.js +83 -0
- package/chunks/trustedFolders-Q7RALK4T.js +92 -0
- package/chunks/{chunk-6EFTQYW7.js → undici-3FJYTMOF.js} +24 -399
- package/chunks/{chunk-L573Z2QZ.js → undici-PYHBDDPN.js} +1 -5
- package/chunks/{update-relaunch-FMVZK6XF.js → update-relaunch-BTW5XGVT.js} +17 -17
- package/chunks/updateCheck-MXIU6DWQ.js +91 -0
- package/chunks/useAutoAcceptIndicator-BJXHJW77.js +92 -0
- package/chunks/{validateNonInterActiveAuth-PRVEB6GG.js → validateNonInterActiveAuth-FLEPF3QQ.js} +90 -76
- package/chunks/{version-AZMG6KWL.js → version-75VRONIL.js} +1 -1
- package/chunks/{web-fetch-EPGJ5OQQ.js → web-fetch-5X27LYHB.js} +101 -41
- package/chunks/web-search-IDMTBJUP.js +718 -0
- package/chunks/{workflow-UTNVPW22.js → workflow-JOD2OPFQ.js} +54 -40
- package/chunks/workspace-providers-status-WDLBDLPG.js +85 -0
- package/chunks/{workspace-registration-store-F3ZX3YHT.js → workspace-registration-store-26Z6J6P5.js} +9 -3
- package/chunks/workspace-registry-IABDATX3.js +87 -0
- package/chunks/workspace-service-BI4KDYPD.js +97 -0
- package/chunks/workspace-skills-status-OVB4LPHA.js +84 -0
- package/chunks/write-file-276AJ7KE.js +72 -0
- package/chunks/{zh-6ANG2HTL.js → zh-Q54GA5SV.js} +6 -1
- package/chunks/{zh-TW-4RR3YHNN.js → zh-TW-VOBNFOPU.js} +6 -1
- package/cli-entry.js +164 -12
- package/cli.js +19 -12
- package/locales/ca.js +773 -203
- package/locales/de.js +8 -2
- package/locales/en.js +9 -2
- package/locales/fr.js +8 -2
- package/locales/ja.js +8 -2
- package/locales/pt.js +8 -2
- package/locales/ru.js +8 -2
- package/locales/zh-TW.js +9 -2
- package/locales/zh.js +9 -2
- package/package.json +3 -3
- package/web-shell/assets/{arc-Buk1besA.js → arc-CMb7lr2P.js} +1 -1
- package/web-shell/assets/{architectureDiagram-3BPJPVTR-B1aUKYDC.js → architectureDiagram-3BPJPVTR-D6KQ5Kwm.js} +1 -1
- package/web-shell/assets/{blockDiagram-GPEHLZMM-CRTdg3Zx.js → blockDiagram-GPEHLZMM-Ce7YYSf8.js} +1 -1
- package/web-shell/assets/{c4Diagram-AAUBKEIU-DFdRMp5g.js → c4Diagram-AAUBKEIU-DaStHfor.js} +1 -1
- package/web-shell/assets/channel-Dg4f-Kry.js +1 -0
- package/web-shell/assets/{chunk-2J33WTMH-4rYQdkEI.js → chunk-2J33WTMH-CPaqadg9.js} +1 -1
- package/web-shell/assets/{chunk-4BX2VUAB-Coi-pQJy.js → chunk-4BX2VUAB-Veh9ZGKg.js} +1 -1
- package/web-shell/assets/{chunk-55IACEB6-BtBjz02t.js → chunk-55IACEB6-BPTX5n4q.js} +1 -1
- package/web-shell/assets/{chunk-727SXJPM-CGYOWorl.js → chunk-727SXJPM-CtXsE_ca.js} +1 -1
- package/web-shell/assets/{chunk-AQP2D5EJ-CH5AKhqx.js → chunk-AQP2D5EJ-D8DDCJ8h.js} +1 -1
- package/web-shell/assets/{chunk-FMBD7UC4-Cd50-w85.js → chunk-FMBD7UC4-cjMDGzHz.js} +1 -1
- package/web-shell/assets/{chunk-ND2GUHAM-C2wF3KCK.js → chunk-ND2GUHAM-BaZ1hNhV.js} +1 -1
- package/web-shell/assets/{chunk-QZHKN3VN-pCeRTaWi.js → chunk-QZHKN3VN-C7w-9w5-.js} +1 -1
- package/web-shell/assets/classDiagram-4FO5ZUOK-CT7Fo2aW.js +1 -0
- package/web-shell/assets/classDiagram-v2-Q7XG4LA2-CT7Fo2aW.js +1 -0
- package/web-shell/assets/{cose-bilkent-S5V4N54A-B-_fAB6D.js → cose-bilkent-S5V4N54A-DqvBEEIe.js} +1 -1
- package/web-shell/assets/{dagre-BM42HDAG-ChSPNHpL.js → dagre-BM42HDAG-RkPyoMAk.js} +1 -1
- package/web-shell/assets/{diagram-2AECGRRQ-BX7cFOF3.js → diagram-2AECGRRQ-D9b6nNyg.js} +1 -1
- package/web-shell/assets/{diagram-5GNKFQAL-BQUTW92n.js → diagram-5GNKFQAL-CiiNKUIy.js} +1 -1
- package/web-shell/assets/{diagram-KO2AKTUF-BkYPh3e4.js → diagram-KO2AKTUF-CP1qizXd.js} +1 -1
- package/web-shell/assets/{diagram-LMA3HP47-Cl6jsNyx.js → diagram-LMA3HP47-BGe30TWx.js} +1 -1
- package/web-shell/assets/{diagram-OG6HWLK6-DRWoHz8n.js → diagram-OG6HWLK6-CvoEPARH.js} +1 -1
- package/web-shell/assets/{erDiagram-TEJ5UH35-CGvFcZco.js → erDiagram-TEJ5UH35-DWfLzVkV.js} +1 -1
- package/web-shell/assets/{flowDiagram-I6XJVG4X-vms6oVdv.js → flowDiagram-I6XJVG4X-D-dTQmo6.js} +1 -1
- package/web-shell/assets/{ganttDiagram-6RSMTGT7-ukT_sfmi.js → ganttDiagram-6RSMTGT7-CYPHKaGY.js} +1 -1
- package/web-shell/assets/{gitGraphDiagram-PVQCEYII-Bn2ZE2Ut.js → gitGraphDiagram-PVQCEYII-DA7_aQYD.js} +1 -1
- package/web-shell/assets/index-B0i-TOYM.css +5 -0
- package/web-shell/assets/index-CgCHD46L.js +1225 -0
- package/web-shell/assets/{index-wFXp7W68.js → index-DqHNAB8C.js} +1 -1
- package/web-shell/assets/{infoDiagram-5YYISTIA-DHJdSi7x.js → infoDiagram-5YYISTIA-B87ljDPa.js} +1 -1
- package/web-shell/assets/{ishikawaDiagram-YF4QCWOH-DOvd2Wph.js → ishikawaDiagram-YF4QCWOH-CYSpyjaN.js} +1 -1
- package/web-shell/assets/{journeyDiagram-JHISSGLW-CH_urMCT.js → journeyDiagram-JHISSGLW-DAL6Js6f.js} +1 -1
- package/web-shell/assets/{kanban-definition-UN3LZRKU-FKiBdgbH.js → kanban-definition-UN3LZRKU-_zufKGJv.js} +1 -1
- package/web-shell/assets/{linear-0ZVQFVKf.js → linear-DidhMgku.js} +1 -1
- package/web-shell/assets/{mermaid.core-DJ05ZZIK.js → mermaid.core-DAkX3h3a.js} +5 -5
- package/web-shell/assets/{mindmap-definition-RKZ34NQL-BPuUhkUm.js → mindmap-definition-RKZ34NQL-DbZxUBEH.js} +1 -1
- package/web-shell/assets/{pieDiagram-4H26LBE5-yLFKcXyG.js → pieDiagram-4H26LBE5-Du9uoqrf.js} +1 -1
- package/web-shell/assets/{quadrantDiagram-W4KKPZXB-irWqc1pE.js → quadrantDiagram-W4KKPZXB-DwjELuKm.js} +1 -1
- package/web-shell/assets/{requirementDiagram-4Y6WPE33-B_4uMoIV.js → requirementDiagram-4Y6WPE33-BAqfVtBL.js} +1 -1
- package/web-shell/assets/{sankeyDiagram-5OEKKPKP-ciA4GPwk.js → sankeyDiagram-5OEKKPKP--hm2VpmK.js} +1 -1
- package/web-shell/assets/{sequenceDiagram-3UESZ5HK-CRdZvy0U.js → sequenceDiagram-3UESZ5HK-R5MUQaIt.js} +1 -1
- package/web-shell/assets/{stateDiagram-AJRCARHV-DaYIkCCn.js → stateDiagram-AJRCARHV-VsX032xQ.js} +1 -1
- package/web-shell/assets/stateDiagram-v2-BHNVJYJU-uPWLcSfy.js +1 -0
- package/web-shell/assets/{timeline-definition-PNZ67QCA-oBUKv6iH.js → timeline-definition-PNZ67QCA-BqjVRXzg.js} +1 -1
- package/web-shell/assets/{vennDiagram-CIIHVFJN-CGW9Sdmb.js → vennDiagram-CIIHVFJN-i2tkvlkg.js} +1 -1
- package/web-shell/assets/{wardley-L42UT6IY-CvwKJOCm.js → wardley-L42UT6IY-Ch8G49EM.js} +1 -1
- package/web-shell/assets/{wardleyDiagram-YWT4CUSO-Ipc260sN.js → wardleyDiagram-YWT4CUSO-bYpWeQNy.js} +1 -1
- package/web-shell/assets/{xychartDiagram-2RQKCTM6-D6-CM7pK.js → xychartDiagram-2RQKCTM6-C9NhuBqB.js} +1 -1
- package/web-shell/index.html +17 -13
- package/chunks/MaxSizedBox-B5YGZSYE.js +0 -72
- package/chunks/agent-H4JIDL7S.js +0 -67
- package/chunks/agent-headless-TTBEREQV.js +0 -61
- package/chunks/bridge-VL7ITBU5.js +0 -75
- package/chunks/chunk-542SK7KV.js +0 -8293
- package/chunks/chunk-CPCVCKKF.js +0 -358
- package/chunks/chunk-SEKHYHMS.js +0 -45
- package/chunks/chunk-W7FJ3N32.js +0 -49
- package/chunks/chunk-ZFKNWQGQ.js +0 -74639
- package/chunks/contextCommand-L2COEUHS.js +0 -66
- package/chunks/daemon-status-provider-NL4IAG7B.js +0 -74
- package/chunks/earlyInputCapture-L6I2A22T.js +0 -68
- package/chunks/errors-LEOF5QG4.js +0 -74
- package/chunks/handleAutoUpdate-QQVIWXKT.js +0 -67
- package/chunks/i18n-N6OBDORT.js +0 -83
- package/chunks/initializer-6WCFNDLL.js +0 -72
- package/chunks/installationInfo-6J3WPXNS.js +0 -64
- package/chunks/list-HOWQSWP6.js +0 -75
- package/chunks/loadedSettingsAdapter-AO4YBRXZ.js +0 -69
- package/chunks/mcp-QH7QNXOH.js +0 -69
- package/chunks/nonInteractiveCli-TI7EMPXD.js +0 -126
- package/chunks/pidfile-UEHAT6DH.js +0 -72
- package/chunks/read-file-SQJONF6A.js +0 -29
- package/chunks/resumeHistoryUtils-PFQ2A23X.js +0 -78
- package/chunks/ripGrep-QCK22GDU.js +0 -59
- package/chunks/runtime-SNVAP6EH.js +0 -100
- package/chunks/serve-BT7KS6SC.js +0 -75
- package/chunks/shell-BITUVH2R.js +0 -69
- package/chunks/spawnChannel-2BU3AULL.js +0 -68
- package/chunks/standalone-update-YG5JUYCM.js +0 -78
- package/chunks/task-create-HX32YXO7.js +0 -23
- package/chunks/theme-manager-IAETOI25.js +0 -63
- package/chunks/total-session-admission-BJLDHKJN.js +0 -69
- package/chunks/trustedFolders-5XCVNEUU.js +0 -79
- package/chunks/updateCheck-YZZB7YBU.js +0 -70
- package/chunks/useAutoAcceptIndicator-ZSQX4I2H.js +0 -80
- package/chunks/workspace-providers-status-EADV364W.js +0 -72
- package/chunks/workspace-registry-W6VMFYZU.js +0 -73
- package/chunks/workspace-service-F3KIN2UN.js +0 -84
- package/chunks/workspace-skills-status-YVICUR5Y.js +0 -71
- package/chunks/write-file-CVGF2OKV.js +0 -596
- package/web-shell/assets/channel-04R0vLbG.js +0 -1
- package/web-shell/assets/classDiagram-4FO5ZUOK-Bw9SOwAV.js +0 -1
- package/web-shell/assets/classDiagram-v2-Q7XG4LA2-Bw9SOwAV.js +0 -1
- package/web-shell/assets/index-DgkKrjw3.js +0 -1187
- package/web-shell/assets/index-Rv6mOAN9.css +0 -5
- package/web-shell/assets/stateDiagram-v2-BHNVJYJU-DWBoO4UY.js +0 -1
|
@@ -0,0 +1,2299 @@
|
|
|
1
|
+
// Force strict mode and setup for ESM
|
|
2
|
+
"use strict";
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_SENSITIVE_SPAN_ATTRIBUTE_MAX_LENGTH,
|
|
5
|
+
EVENT_CHAT_COMPRESSION,
|
|
6
|
+
SERVICE_NAME,
|
|
7
|
+
SPAN_HOOK,
|
|
8
|
+
SPAN_INTERACTION,
|
|
9
|
+
SPAN_LLM_REQUEST,
|
|
10
|
+
SPAN_SUBAGENT,
|
|
11
|
+
SPAN_TOOL,
|
|
12
|
+
SPAN_TOOL_BLOCKED_ON_USER,
|
|
13
|
+
SPAN_TOOL_EXECUTION,
|
|
14
|
+
safeJsonStringify
|
|
15
|
+
} from "./chunk-BULDBTYC.js";
|
|
16
|
+
import {
|
|
17
|
+
createDebugLogger,
|
|
18
|
+
getCurrentSessionId,
|
|
19
|
+
setSessionContext,
|
|
20
|
+
setShellTracePropagation
|
|
21
|
+
} from "./chunk-OQB4EXO4.js";
|
|
22
|
+
import {
|
|
23
|
+
DiagLogLevel,
|
|
24
|
+
ROOT_CONTEXT,
|
|
25
|
+
SpanKind,
|
|
26
|
+
SpanStatusCode,
|
|
27
|
+
TraceFlags,
|
|
28
|
+
ValueType,
|
|
29
|
+
context,
|
|
30
|
+
diag,
|
|
31
|
+
init_esm,
|
|
32
|
+
metrics,
|
|
33
|
+
trace
|
|
34
|
+
} from "./chunk-THJNPLI4.js";
|
|
35
|
+
import {
|
|
36
|
+
init_esbuild_shims
|
|
37
|
+
} from "./chunk-5O2XNYP6.js";
|
|
38
|
+
import {
|
|
39
|
+
__name
|
|
40
|
+
} from "./chunk-J2S4EL5Y.js";
|
|
41
|
+
|
|
42
|
+
// packages/core/src/telemetry/metrics.ts
|
|
43
|
+
init_esbuild_shims();
|
|
44
|
+
init_esm();
|
|
45
|
+
var TOOL_CALL_COUNT = `${SERVICE_NAME}.tool.call.count`;
|
|
46
|
+
var TOOL_CALL_LATENCY = `${SERVICE_NAME}.tool.call.latency`;
|
|
47
|
+
var API_REQUEST_COUNT = `${SERVICE_NAME}.api.request.count`;
|
|
48
|
+
var API_REQUEST_LATENCY = `${SERVICE_NAME}.api.request.latency`;
|
|
49
|
+
var TOKEN_USAGE = `${SERVICE_NAME}.token.usage`;
|
|
50
|
+
var SESSION_COUNT = `${SERVICE_NAME}.session.count`;
|
|
51
|
+
var FILE_OPERATION_COUNT = `${SERVICE_NAME}.file.operation.count`;
|
|
52
|
+
var INVALID_CHUNK_COUNT = `${SERVICE_NAME}.chat.invalid_chunk.count`;
|
|
53
|
+
var CONTENT_RETRY_COUNT = `${SERVICE_NAME}.chat.content_retry.count`;
|
|
54
|
+
var CONTENT_RETRY_FAILURE_COUNT = `${SERVICE_NAME}.chat.content_retry_failure.count`;
|
|
55
|
+
var API_RETRY_COUNT = `${SERVICE_NAME}.api.retry.count`;
|
|
56
|
+
var MODEL_SLASH_COMMAND_CALL_COUNT = `${SERVICE_NAME}.slash_command.model.call_count`;
|
|
57
|
+
var SUBAGENT_EXECUTION_COUNT = `${SERVICE_NAME}.subagent.execution.count`;
|
|
58
|
+
var ARENA_SESSION_COUNT = `${SERVICE_NAME}.arena.session.count`;
|
|
59
|
+
var ARENA_SESSION_DURATION = `${SERVICE_NAME}.arena.session.duration`;
|
|
60
|
+
var ARENA_AGENT_COUNT = `${SERVICE_NAME}.arena.agent.count`;
|
|
61
|
+
var ARENA_AGENT_DURATION = `${SERVICE_NAME}.arena.agent.duration`;
|
|
62
|
+
var ARENA_AGENT_TOKENS = `${SERVICE_NAME}.arena.agent.tokens`;
|
|
63
|
+
var ARENA_RESULT_SELECTED = `${SERVICE_NAME}.arena.result.selected`;
|
|
64
|
+
var STARTUP_TIME = `${SERVICE_NAME}.startup.duration`;
|
|
65
|
+
var MEMORY_USAGE = `${SERVICE_NAME}.memory.usage`;
|
|
66
|
+
var CPU_USAGE = `${SERVICE_NAME}.cpu.usage`;
|
|
67
|
+
var TOOL_QUEUE_DEPTH = `${SERVICE_NAME}.tool.queue.depth`;
|
|
68
|
+
var TOOL_EXECUTION_BREAKDOWN = `${SERVICE_NAME}.tool.execution.breakdown`;
|
|
69
|
+
var TOKEN_EFFICIENCY = `${SERVICE_NAME}.token.efficiency`;
|
|
70
|
+
var API_REQUEST_BREAKDOWN = `${SERVICE_NAME}.api.request.breakdown`;
|
|
71
|
+
var PERFORMANCE_SCORE = `${SERVICE_NAME}.performance.score`;
|
|
72
|
+
var REGRESSION_DETECTION = `${SERVICE_NAME}.performance.regression`;
|
|
73
|
+
var REGRESSION_PERCENTAGE_CHANGE = `${SERVICE_NAME}.performance.regression.percentage_change`;
|
|
74
|
+
var BASELINE_COMPARISON = `${SERVICE_NAME}.performance.baseline.comparison`;
|
|
75
|
+
var MEMORY_EXTRACT_COUNT = `${SERVICE_NAME}.memory.extract.count`;
|
|
76
|
+
var MEMORY_EXTRACT_DURATION = `${SERVICE_NAME}.memory.extract.duration`;
|
|
77
|
+
var MEMORY_DREAM_COUNT = `${SERVICE_NAME}.memory.dream.count`;
|
|
78
|
+
var MEMORY_DREAM_DURATION = `${SERVICE_NAME}.memory.dream.duration`;
|
|
79
|
+
var MEMORY_RECALL_COUNT = `${SERVICE_NAME}.memory.recall.count`;
|
|
80
|
+
var MEMORY_RECALL_DURATION = `${SERVICE_NAME}.memory.recall.duration`;
|
|
81
|
+
var CHANNEL_MEMORY_RECALL_COUNT = `${SERVICE_NAME}.channel.memory.recall.count`;
|
|
82
|
+
var CHANNEL_MEMORY_RECALL_DURATION = `${SERVICE_NAME}.channel.memory.recall.duration`;
|
|
83
|
+
var CHANNEL_MEMORY_RECALL_SELECTED_COUNT = `${SERVICE_NAME}.channel.memory.recall.selected_count`;
|
|
84
|
+
var MEMORY_RECALL_DELIVERY_COUNT = `${SERVICE_NAME}.memory.recall.delivery.count`;
|
|
85
|
+
var MEMORY_RECALL_DELIVERY_LATENCY = `${SERVICE_NAME}.memory.recall.delivery.latency`;
|
|
86
|
+
var baseMetricDefinition = {
|
|
87
|
+
// session.id on metrics is opt-in: each session is a new value, so
|
|
88
|
+
// attaching it by default would create unbounded time-series fan-out on
|
|
89
|
+
// every metric backend. Operators who need session-level metric slicing
|
|
90
|
+
// can enable QWEN_TELEMETRY_METRICS_INCLUDE_SESSION_ID or
|
|
91
|
+
// telemetry.metrics.includeSessionId. Spans and logs always carry
|
|
92
|
+
// session.id for trace/log correlation.
|
|
93
|
+
getCommonAttributes: /* @__PURE__ */ __name((config) => {
|
|
94
|
+
const out = {};
|
|
95
|
+
if (config.getTelemetryMetricsIncludeSessionId()) {
|
|
96
|
+
out["session.id"] = config.getSessionId();
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}, "getCommonAttributes")
|
|
100
|
+
};
|
|
101
|
+
var COUNTER_DEFINITIONS = {
|
|
102
|
+
[TOOL_CALL_COUNT]: {
|
|
103
|
+
description: "Counts tool calls, tagged by function name and success.",
|
|
104
|
+
valueType: ValueType.INT,
|
|
105
|
+
assign: /* @__PURE__ */ __name((c) => toolCallCounter = c, "assign"),
|
|
106
|
+
attributes: {}
|
|
107
|
+
},
|
|
108
|
+
[API_REQUEST_COUNT]: {
|
|
109
|
+
description: "Counts API requests, tagged by model and status.",
|
|
110
|
+
valueType: ValueType.INT,
|
|
111
|
+
assign: /* @__PURE__ */ __name((c) => apiRequestCounter = c, "assign"),
|
|
112
|
+
attributes: {}
|
|
113
|
+
},
|
|
114
|
+
[TOKEN_USAGE]: {
|
|
115
|
+
description: "Counts the total number of tokens used.",
|
|
116
|
+
valueType: ValueType.INT,
|
|
117
|
+
assign: /* @__PURE__ */ __name((c) => tokenUsageCounter = c, "assign"),
|
|
118
|
+
attributes: {}
|
|
119
|
+
},
|
|
120
|
+
[SESSION_COUNT]: {
|
|
121
|
+
description: "Count of CLI sessions started.",
|
|
122
|
+
valueType: ValueType.INT,
|
|
123
|
+
assign: /* @__PURE__ */ __name((c) => sessionCounter = c, "assign"),
|
|
124
|
+
attributes: {}
|
|
125
|
+
},
|
|
126
|
+
[FILE_OPERATION_COUNT]: {
|
|
127
|
+
description: "Counts file operations (create, read, update).",
|
|
128
|
+
valueType: ValueType.INT,
|
|
129
|
+
assign: /* @__PURE__ */ __name((c) => fileOperationCounter = c, "assign"),
|
|
130
|
+
attributes: {}
|
|
131
|
+
},
|
|
132
|
+
[INVALID_CHUNK_COUNT]: {
|
|
133
|
+
description: "Counts invalid chunks received from a stream.",
|
|
134
|
+
valueType: ValueType.INT,
|
|
135
|
+
assign: /* @__PURE__ */ __name((c) => invalidChunkCounter = c, "assign"),
|
|
136
|
+
attributes: {}
|
|
137
|
+
},
|
|
138
|
+
[CONTENT_RETRY_COUNT]: {
|
|
139
|
+
description: "Counts retries due to content errors (e.g., empty stream).",
|
|
140
|
+
valueType: ValueType.INT,
|
|
141
|
+
assign: /* @__PURE__ */ __name((c) => contentRetryCounter = c, "assign"),
|
|
142
|
+
attributes: {}
|
|
143
|
+
},
|
|
144
|
+
[CONTENT_RETRY_FAILURE_COUNT]: {
|
|
145
|
+
description: "Counts occurrences of all content retries failing.",
|
|
146
|
+
valueType: ValueType.INT,
|
|
147
|
+
assign: /* @__PURE__ */ __name((c) => contentRetryFailureCounter = c, "assign"),
|
|
148
|
+
attributes: {}
|
|
149
|
+
},
|
|
150
|
+
[API_RETRY_COUNT]: {
|
|
151
|
+
description: "Counts HTTP-status retries (429/5xx) at LLM call sites, emitted by retryWithBackoff onRetry callback.",
|
|
152
|
+
valueType: ValueType.INT,
|
|
153
|
+
assign: /* @__PURE__ */ __name((c) => apiRetryCounter = c, "assign"),
|
|
154
|
+
attributes: {}
|
|
155
|
+
},
|
|
156
|
+
[MODEL_SLASH_COMMAND_CALL_COUNT]: {
|
|
157
|
+
description: "Counts model slash command calls.",
|
|
158
|
+
valueType: ValueType.INT,
|
|
159
|
+
assign: /* @__PURE__ */ __name((c) => modelSlashCommandCallCounter = c, "assign"),
|
|
160
|
+
attributes: {}
|
|
161
|
+
},
|
|
162
|
+
[EVENT_CHAT_COMPRESSION]: {
|
|
163
|
+
description: "Counts chat compression events.",
|
|
164
|
+
valueType: ValueType.INT,
|
|
165
|
+
assign: /* @__PURE__ */ __name((c) => chatCompressionCounter = c, "assign"),
|
|
166
|
+
attributes: {}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var HISTOGRAM_DEFINITIONS = {
|
|
170
|
+
[TOOL_CALL_LATENCY]: {
|
|
171
|
+
description: "Latency of tool calls in milliseconds.",
|
|
172
|
+
unit: "ms",
|
|
173
|
+
valueType: ValueType.INT,
|
|
174
|
+
assign: /* @__PURE__ */ __name((h) => toolCallLatencyHistogram = h, "assign"),
|
|
175
|
+
attributes: {}
|
|
176
|
+
},
|
|
177
|
+
[API_REQUEST_LATENCY]: {
|
|
178
|
+
description: "Latency of API requests in milliseconds.",
|
|
179
|
+
unit: "ms",
|
|
180
|
+
valueType: ValueType.INT,
|
|
181
|
+
assign: /* @__PURE__ */ __name((h) => apiRequestLatencyHistogram = h, "assign"),
|
|
182
|
+
attributes: {}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var PERFORMANCE_COUNTER_DEFINITIONS = {
|
|
186
|
+
[REGRESSION_DETECTION]: {
|
|
187
|
+
description: "Performance regression detection events.",
|
|
188
|
+
valueType: ValueType.INT,
|
|
189
|
+
assign: /* @__PURE__ */ __name((c) => regressionDetectionCounter = c, "assign"),
|
|
190
|
+
attributes: {}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
var PERFORMANCE_HISTOGRAM_DEFINITIONS = {
|
|
194
|
+
[STARTUP_TIME]: {
|
|
195
|
+
description: "CLI startup time in milliseconds, broken down by initialization phase.",
|
|
196
|
+
unit: "ms",
|
|
197
|
+
valueType: ValueType.DOUBLE,
|
|
198
|
+
assign: /* @__PURE__ */ __name((h) => startupTimeHistogram = h, "assign"),
|
|
199
|
+
attributes: {}
|
|
200
|
+
},
|
|
201
|
+
[MEMORY_USAGE]: {
|
|
202
|
+
description: "Memory usage in bytes.",
|
|
203
|
+
unit: "bytes",
|
|
204
|
+
valueType: ValueType.INT,
|
|
205
|
+
assign: /* @__PURE__ */ __name((h) => memoryUsageGauge = h, "assign"),
|
|
206
|
+
attributes: {}
|
|
207
|
+
},
|
|
208
|
+
[CPU_USAGE]: {
|
|
209
|
+
description: "CPU usage percentage.",
|
|
210
|
+
unit: "percent",
|
|
211
|
+
valueType: ValueType.DOUBLE,
|
|
212
|
+
assign: /* @__PURE__ */ __name((h) => cpuUsageGauge = h, "assign"),
|
|
213
|
+
attributes: {}
|
|
214
|
+
},
|
|
215
|
+
[TOOL_QUEUE_DEPTH]: {
|
|
216
|
+
description: "Number of tools in execution queue.",
|
|
217
|
+
unit: "count",
|
|
218
|
+
valueType: ValueType.INT,
|
|
219
|
+
assign: /* @__PURE__ */ __name((h) => toolQueueDepthGauge = h, "assign"),
|
|
220
|
+
attributes: {}
|
|
221
|
+
},
|
|
222
|
+
[TOOL_EXECUTION_BREAKDOWN]: {
|
|
223
|
+
description: "Tool execution time breakdown by phase in milliseconds.",
|
|
224
|
+
unit: "ms",
|
|
225
|
+
valueType: ValueType.INT,
|
|
226
|
+
assign: /* @__PURE__ */ __name((h) => toolExecutionBreakdownHistogram = h, "assign"),
|
|
227
|
+
attributes: {}
|
|
228
|
+
},
|
|
229
|
+
[TOKEN_EFFICIENCY]: {
|
|
230
|
+
description: "Token efficiency metrics (tokens per operation, cache hit rate, etc.).",
|
|
231
|
+
unit: "ratio",
|
|
232
|
+
valueType: ValueType.DOUBLE,
|
|
233
|
+
assign: /* @__PURE__ */ __name((h) => tokenEfficiencyHistogram = h, "assign"),
|
|
234
|
+
attributes: {}
|
|
235
|
+
},
|
|
236
|
+
[API_REQUEST_BREAKDOWN]: {
|
|
237
|
+
description: "API request time breakdown by phase in milliseconds.",
|
|
238
|
+
unit: "ms",
|
|
239
|
+
valueType: ValueType.INT,
|
|
240
|
+
assign: /* @__PURE__ */ __name((h) => apiRequestBreakdownHistogram = h, "assign"),
|
|
241
|
+
attributes: {}
|
|
242
|
+
},
|
|
243
|
+
[PERFORMANCE_SCORE]: {
|
|
244
|
+
description: "Composite performance score (0-100).",
|
|
245
|
+
unit: "score",
|
|
246
|
+
valueType: ValueType.DOUBLE,
|
|
247
|
+
assign: /* @__PURE__ */ __name((h) => performanceScoreGauge = h, "assign"),
|
|
248
|
+
attributes: {}
|
|
249
|
+
},
|
|
250
|
+
[REGRESSION_PERCENTAGE_CHANGE]: {
|
|
251
|
+
description: "Percentage change compared to baseline for detected regressions.",
|
|
252
|
+
unit: "percent",
|
|
253
|
+
valueType: ValueType.DOUBLE,
|
|
254
|
+
assign: /* @__PURE__ */ __name((h) => regressionPercentageChangeHistogram = h, "assign"),
|
|
255
|
+
attributes: {}
|
|
256
|
+
},
|
|
257
|
+
[BASELINE_COMPARISON]: {
|
|
258
|
+
description: "Performance comparison to established baseline (percentage change).",
|
|
259
|
+
unit: "percent",
|
|
260
|
+
valueType: ValueType.DOUBLE,
|
|
261
|
+
assign: /* @__PURE__ */ __name((h) => baselineComparisonHistogram = h, "assign"),
|
|
262
|
+
attributes: {}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var FileOperation = /* @__PURE__ */ ((FileOperation2) => {
|
|
266
|
+
FileOperation2["CREATE"] = "create";
|
|
267
|
+
FileOperation2["READ"] = "read";
|
|
268
|
+
FileOperation2["UPDATE"] = "update";
|
|
269
|
+
return FileOperation2;
|
|
270
|
+
})(FileOperation || {});
|
|
271
|
+
var PerformanceMetricType = /* @__PURE__ */ ((PerformanceMetricType2) => {
|
|
272
|
+
PerformanceMetricType2["STARTUP"] = "startup";
|
|
273
|
+
PerformanceMetricType2["MEMORY"] = "memory";
|
|
274
|
+
PerformanceMetricType2["CPU"] = "cpu";
|
|
275
|
+
PerformanceMetricType2["TOOL_EXECUTION"] = "tool_execution";
|
|
276
|
+
PerformanceMetricType2["API_REQUEST"] = "api_request";
|
|
277
|
+
PerformanceMetricType2["TOKEN_EFFICIENCY"] = "token_efficiency";
|
|
278
|
+
return PerformanceMetricType2;
|
|
279
|
+
})(PerformanceMetricType || {});
|
|
280
|
+
var MemoryMetricType = /* @__PURE__ */ ((MemoryMetricType2) => {
|
|
281
|
+
MemoryMetricType2["HEAP_USED"] = "heap_used";
|
|
282
|
+
MemoryMetricType2["HEAP_TOTAL"] = "heap_total";
|
|
283
|
+
MemoryMetricType2["EXTERNAL"] = "external";
|
|
284
|
+
MemoryMetricType2["RSS"] = "rss";
|
|
285
|
+
return MemoryMetricType2;
|
|
286
|
+
})(MemoryMetricType || {});
|
|
287
|
+
var ToolExecutionPhase = /* @__PURE__ */ ((ToolExecutionPhase2) => {
|
|
288
|
+
ToolExecutionPhase2["VALIDATION"] = "validation";
|
|
289
|
+
ToolExecutionPhase2["PREPARATION"] = "preparation";
|
|
290
|
+
ToolExecutionPhase2["EXECUTION"] = "execution";
|
|
291
|
+
ToolExecutionPhase2["RESULT_PROCESSING"] = "result_processing";
|
|
292
|
+
return ToolExecutionPhase2;
|
|
293
|
+
})(ToolExecutionPhase || {});
|
|
294
|
+
var ApiRequestPhase = /* @__PURE__ */ ((ApiRequestPhase2) => {
|
|
295
|
+
ApiRequestPhase2["REQUEST_PREPARATION"] = "request_preparation";
|
|
296
|
+
ApiRequestPhase2["NETWORK_LATENCY"] = "network_latency";
|
|
297
|
+
ApiRequestPhase2["RESPONSE_PROCESSING"] = "response_processing";
|
|
298
|
+
ApiRequestPhase2["TOKEN_PROCESSING"] = "token_processing";
|
|
299
|
+
return ApiRequestPhase2;
|
|
300
|
+
})(ApiRequestPhase || {});
|
|
301
|
+
var cliMeter;
|
|
302
|
+
var toolCallCounter;
|
|
303
|
+
var toolCallLatencyHistogram;
|
|
304
|
+
var apiRequestCounter;
|
|
305
|
+
var apiRequestLatencyHistogram;
|
|
306
|
+
var tokenUsageCounter;
|
|
307
|
+
var sessionCounter;
|
|
308
|
+
var fileOperationCounter;
|
|
309
|
+
var chatCompressionCounter;
|
|
310
|
+
var invalidChunkCounter;
|
|
311
|
+
var contentRetryCounter;
|
|
312
|
+
var contentRetryFailureCounter;
|
|
313
|
+
var apiRetryCounter;
|
|
314
|
+
var subagentExecutionCounter;
|
|
315
|
+
var modelSlashCommandCallCounter;
|
|
316
|
+
var startupTimeHistogram;
|
|
317
|
+
var memoryUsageGauge;
|
|
318
|
+
var cpuUsageGauge;
|
|
319
|
+
var toolQueueDepthGauge;
|
|
320
|
+
var toolExecutionBreakdownHistogram;
|
|
321
|
+
var tokenEfficiencyHistogram;
|
|
322
|
+
var apiRequestBreakdownHistogram;
|
|
323
|
+
var performanceScoreGauge;
|
|
324
|
+
var regressionDetectionCounter;
|
|
325
|
+
var regressionPercentageChangeHistogram;
|
|
326
|
+
var baselineComparisonHistogram;
|
|
327
|
+
var arenaSessionCounter;
|
|
328
|
+
var arenaSessionDurationHistogram;
|
|
329
|
+
var arenaAgentCounter;
|
|
330
|
+
var arenaAgentDurationHistogram;
|
|
331
|
+
var arenaAgentTokensCounter;
|
|
332
|
+
var arenaResultSelectedCounter;
|
|
333
|
+
var memoryExtractCounter;
|
|
334
|
+
var memoryExtractDurationHistogram;
|
|
335
|
+
var memoryDreamCounter;
|
|
336
|
+
var memoryDreamDurationHistogram;
|
|
337
|
+
var memoryRecallCounter;
|
|
338
|
+
var memoryRecallDurationHistogram;
|
|
339
|
+
var channelMemoryRecallCounter;
|
|
340
|
+
var channelMemoryRecallDurationHistogram;
|
|
341
|
+
var channelMemoryRecallSelectedCountHistogram;
|
|
342
|
+
var memoryRecallDeliveryCounter;
|
|
343
|
+
var memoryRecallDeliveryLatencyHistogram;
|
|
344
|
+
var isMetricsInitialized = false;
|
|
345
|
+
var isPerformanceMonitoringEnabled = false;
|
|
346
|
+
function getMeter() {
|
|
347
|
+
if (!cliMeter) {
|
|
348
|
+
cliMeter = metrics.getMeter(SERVICE_NAME);
|
|
349
|
+
}
|
|
350
|
+
return cliMeter;
|
|
351
|
+
}
|
|
352
|
+
__name(getMeter, "getMeter");
|
|
353
|
+
function initializeMetrics(config) {
|
|
354
|
+
if (isMetricsInitialized) return;
|
|
355
|
+
const meter = getMeter();
|
|
356
|
+
if (!meter) return;
|
|
357
|
+
Object.entries(COUNTER_DEFINITIONS).forEach(
|
|
358
|
+
([name, { description, valueType, assign }]) => {
|
|
359
|
+
assign(meter.createCounter(name, { description, valueType }));
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
subagentExecutionCounter = meter.createCounter(SUBAGENT_EXECUTION_COUNT, {
|
|
363
|
+
description: "Counts subagent execution events, tagged by status and subagent name.",
|
|
364
|
+
valueType: ValueType.INT
|
|
365
|
+
});
|
|
366
|
+
arenaSessionCounter = meter.createCounter(ARENA_SESSION_COUNT, {
|
|
367
|
+
description: "Counts arena sessions by status and display backend.",
|
|
368
|
+
valueType: ValueType.INT
|
|
369
|
+
});
|
|
370
|
+
arenaSessionDurationHistogram = meter.createHistogram(
|
|
371
|
+
ARENA_SESSION_DURATION,
|
|
372
|
+
{
|
|
373
|
+
description: "Duration of arena sessions in milliseconds.",
|
|
374
|
+
unit: "ms",
|
|
375
|
+
valueType: ValueType.INT
|
|
376
|
+
}
|
|
377
|
+
);
|
|
378
|
+
arenaAgentCounter = meter.createCounter(ARENA_AGENT_COUNT, {
|
|
379
|
+
description: "Counts arena agent completions by status and model.",
|
|
380
|
+
valueType: ValueType.INT
|
|
381
|
+
});
|
|
382
|
+
arenaAgentDurationHistogram = meter.createHistogram(ARENA_AGENT_DURATION, {
|
|
383
|
+
description: "Duration of arena agent execution in milliseconds.",
|
|
384
|
+
unit: "ms",
|
|
385
|
+
valueType: ValueType.INT
|
|
386
|
+
});
|
|
387
|
+
arenaAgentTokensCounter = meter.createCounter(ARENA_AGENT_TOKENS, {
|
|
388
|
+
description: "Token usage by arena agents.",
|
|
389
|
+
valueType: ValueType.INT
|
|
390
|
+
});
|
|
391
|
+
arenaResultSelectedCounter = meter.createCounter(ARENA_RESULT_SELECTED, {
|
|
392
|
+
description: "Counts arena result selections by model.",
|
|
393
|
+
valueType: ValueType.INT
|
|
394
|
+
});
|
|
395
|
+
Object.entries(HISTOGRAM_DEFINITIONS).forEach(
|
|
396
|
+
([name, { description, unit, valueType, assign }]) => {
|
|
397
|
+
assign(meter.createHistogram(name, { description, unit, valueType }));
|
|
398
|
+
}
|
|
399
|
+
);
|
|
400
|
+
sessionCounter?.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
401
|
+
memoryExtractCounter = meter.createCounter(MEMORY_EXTRACT_COUNT, {
|
|
402
|
+
description: "Counts auto-memory extraction runs, tagged by trigger and status.",
|
|
403
|
+
valueType: ValueType.INT
|
|
404
|
+
});
|
|
405
|
+
memoryExtractDurationHistogram = meter.createHistogram(
|
|
406
|
+
MEMORY_EXTRACT_DURATION,
|
|
407
|
+
{
|
|
408
|
+
description: "Duration of auto-memory extraction in milliseconds.",
|
|
409
|
+
unit: "ms",
|
|
410
|
+
valueType: ValueType.INT
|
|
411
|
+
}
|
|
412
|
+
);
|
|
413
|
+
memoryDreamCounter = meter.createCounter(MEMORY_DREAM_COUNT, {
|
|
414
|
+
description: "Counts auto-memory dream (consolidation) runs, tagged by trigger and status.",
|
|
415
|
+
valueType: ValueType.INT
|
|
416
|
+
});
|
|
417
|
+
memoryDreamDurationHistogram = meter.createHistogram(MEMORY_DREAM_DURATION, {
|
|
418
|
+
description: "Duration of auto-memory dream runs in milliseconds.",
|
|
419
|
+
unit: "ms",
|
|
420
|
+
valueType: ValueType.INT
|
|
421
|
+
});
|
|
422
|
+
memoryRecallCounter = meter.createCounter(MEMORY_RECALL_COUNT, {
|
|
423
|
+
description: "Counts auto-memory recall operations, tagged by strategy.",
|
|
424
|
+
valueType: ValueType.INT
|
|
425
|
+
});
|
|
426
|
+
memoryRecallDurationHistogram = meter.createHistogram(
|
|
427
|
+
MEMORY_RECALL_DURATION,
|
|
428
|
+
{
|
|
429
|
+
description: "Duration of auto-memory recall operations in milliseconds.",
|
|
430
|
+
unit: "ms",
|
|
431
|
+
valueType: ValueType.INT
|
|
432
|
+
}
|
|
433
|
+
);
|
|
434
|
+
channelMemoryRecallCounter = meter.createCounter(
|
|
435
|
+
CHANNEL_MEMORY_RECALL_COUNT,
|
|
436
|
+
{
|
|
437
|
+
description: "Counts channel memory recall attempts by cache path and bounded result.",
|
|
438
|
+
valueType: ValueType.INT
|
|
439
|
+
}
|
|
440
|
+
);
|
|
441
|
+
channelMemoryRecallDurationHistogram = meter.createHistogram(
|
|
442
|
+
CHANNEL_MEMORY_RECALL_DURATION,
|
|
443
|
+
{
|
|
444
|
+
description: "Duration of channel memory recall attempts.",
|
|
445
|
+
unit: "ms",
|
|
446
|
+
valueType: ValueType.DOUBLE,
|
|
447
|
+
advice: {
|
|
448
|
+
explicitBucketBoundaries: [0.1, 0.5, 1, 2, 5, 10, 25, 50, 100, 250]
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
);
|
|
452
|
+
channelMemoryRecallSelectedCountHistogram = meter.createHistogram(
|
|
453
|
+
CHANNEL_MEMORY_RECALL_SELECTED_COUNT,
|
|
454
|
+
{
|
|
455
|
+
description: "Number of channel memory entries selected per attempt.",
|
|
456
|
+
valueType: ValueType.INT
|
|
457
|
+
}
|
|
458
|
+
);
|
|
459
|
+
memoryRecallDeliveryCounter = meter.createCounter(
|
|
460
|
+
MEMORY_RECALL_DELIVERY_COUNT,
|
|
461
|
+
{
|
|
462
|
+
description: "Counts auto-memory recall delivery outcomes, tagged by phase and delivery point.",
|
|
463
|
+
valueType: ValueType.INT
|
|
464
|
+
}
|
|
465
|
+
);
|
|
466
|
+
memoryRecallDeliveryLatencyHistogram = meter.createHistogram(
|
|
467
|
+
MEMORY_RECALL_DELIVERY_LATENCY,
|
|
468
|
+
{
|
|
469
|
+
description: "Latency from auto-memory recall prefetch start to delivery or discard.",
|
|
470
|
+
unit: "ms",
|
|
471
|
+
valueType: ValueType.INT
|
|
472
|
+
}
|
|
473
|
+
);
|
|
474
|
+
initializePerformanceMonitoring(config);
|
|
475
|
+
isMetricsInitialized = true;
|
|
476
|
+
}
|
|
477
|
+
__name(initializeMetrics, "initializeMetrics");
|
|
478
|
+
function recordChatCompressionMetrics(config, attributes) {
|
|
479
|
+
if (!chatCompressionCounter || !isMetricsInitialized) return;
|
|
480
|
+
chatCompressionCounter.add(1, {
|
|
481
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
482
|
+
...attributes
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
__name(recordChatCompressionMetrics, "recordChatCompressionMetrics");
|
|
486
|
+
function recordToolCallMetrics(config, durationMs, attributes) {
|
|
487
|
+
if (!toolCallCounter || !toolCallLatencyHistogram || !isMetricsInitialized)
|
|
488
|
+
return;
|
|
489
|
+
const metricAttributes = {
|
|
490
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
491
|
+
...attributes
|
|
492
|
+
};
|
|
493
|
+
toolCallCounter.add(1, metricAttributes);
|
|
494
|
+
toolCallLatencyHistogram.record(durationMs, {
|
|
495
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
496
|
+
function_name: attributes.function_name
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
__name(recordToolCallMetrics, "recordToolCallMetrics");
|
|
500
|
+
function recordTokenUsageMetrics(config, tokenCount, attributes) {
|
|
501
|
+
if (!tokenUsageCounter || !isMetricsInitialized) return;
|
|
502
|
+
tokenUsageCounter.add(tokenCount, {
|
|
503
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
504
|
+
...attributes
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
__name(recordTokenUsageMetrics, "recordTokenUsageMetrics");
|
|
508
|
+
function recordApiResponseMetrics(config, durationMs, attributes) {
|
|
509
|
+
if (!apiRequestCounter || !apiRequestLatencyHistogram || !isMetricsInitialized)
|
|
510
|
+
return;
|
|
511
|
+
const metricAttributes = {
|
|
512
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
513
|
+
model: attributes.model,
|
|
514
|
+
status_code: attributes.status_code ?? "ok"
|
|
515
|
+
};
|
|
516
|
+
apiRequestCounter.add(1, metricAttributes);
|
|
517
|
+
apiRequestLatencyHistogram.record(durationMs, {
|
|
518
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
519
|
+
model: attributes.model
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
__name(recordApiResponseMetrics, "recordApiResponseMetrics");
|
|
523
|
+
function recordApiErrorMetrics(config, durationMs, attributes) {
|
|
524
|
+
if (!apiRequestCounter || !apiRequestLatencyHistogram || !isMetricsInitialized)
|
|
525
|
+
return;
|
|
526
|
+
const metricAttributes = {
|
|
527
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
528
|
+
model: attributes.model,
|
|
529
|
+
status_code: attributes.status_code ?? "error",
|
|
530
|
+
error_type: attributes.error_type ?? "unknown"
|
|
531
|
+
};
|
|
532
|
+
apiRequestCounter.add(1, metricAttributes);
|
|
533
|
+
apiRequestLatencyHistogram.record(durationMs, {
|
|
534
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
535
|
+
model: attributes.model
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
__name(recordApiErrorMetrics, "recordApiErrorMetrics");
|
|
539
|
+
function recordFileOperationMetric(config, attributes) {
|
|
540
|
+
if (!fileOperationCounter || !isMetricsInitialized) return;
|
|
541
|
+
fileOperationCounter.add(1, {
|
|
542
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
543
|
+
...attributes
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
__name(recordFileOperationMetric, "recordFileOperationMetric");
|
|
547
|
+
function recordInvalidChunk(config) {
|
|
548
|
+
if (!invalidChunkCounter || !isMetricsInitialized) return;
|
|
549
|
+
invalidChunkCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
550
|
+
}
|
|
551
|
+
__name(recordInvalidChunk, "recordInvalidChunk");
|
|
552
|
+
function recordContentRetry(config) {
|
|
553
|
+
if (!contentRetryCounter || !isMetricsInitialized) return;
|
|
554
|
+
contentRetryCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
|
|
555
|
+
}
|
|
556
|
+
__name(recordContentRetry, "recordContentRetry");
|
|
557
|
+
function recordContentRetryFailure(config) {
|
|
558
|
+
if (!contentRetryFailureCounter || !isMetricsInitialized) return;
|
|
559
|
+
contentRetryFailureCounter.add(
|
|
560
|
+
1,
|
|
561
|
+
baseMetricDefinition.getCommonAttributes(config)
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
__name(recordContentRetryFailure, "recordContentRetryFailure");
|
|
565
|
+
function recordApiRetry(config, attributes) {
|
|
566
|
+
if (!apiRetryCounter || !isMetricsInitialized) return;
|
|
567
|
+
apiRetryCounter.add(1, {
|
|
568
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
569
|
+
...attributes
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
__name(recordApiRetry, "recordApiRetry");
|
|
573
|
+
function recordModelSlashCommand(config, event) {
|
|
574
|
+
if (!modelSlashCommandCallCounter || !isMetricsInitialized) return;
|
|
575
|
+
modelSlashCommandCallCounter.add(1, {
|
|
576
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
577
|
+
"slash_command.model.model_name": event.model_name
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
__name(recordModelSlashCommand, "recordModelSlashCommand");
|
|
581
|
+
function initializePerformanceMonitoring(config) {
|
|
582
|
+
const meter = getMeter();
|
|
583
|
+
if (!meter) return;
|
|
584
|
+
isPerformanceMonitoringEnabled = config.getTelemetryEnabled();
|
|
585
|
+
if (!isPerformanceMonitoringEnabled) return;
|
|
586
|
+
Object.entries(PERFORMANCE_COUNTER_DEFINITIONS).forEach(
|
|
587
|
+
([name, { description, valueType, assign }]) => {
|
|
588
|
+
assign(meter.createCounter(name, { description, valueType }));
|
|
589
|
+
}
|
|
590
|
+
);
|
|
591
|
+
Object.entries(PERFORMANCE_HISTOGRAM_DEFINITIONS).forEach(
|
|
592
|
+
([name, { description, unit, valueType, assign }]) => {
|
|
593
|
+
assign(meter.createHistogram(name, { description, unit, valueType }));
|
|
594
|
+
}
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
__name(initializePerformanceMonitoring, "initializePerformanceMonitoring");
|
|
598
|
+
function recordStartupPerformance(config, durationMs, attributes) {
|
|
599
|
+
if (!startupTimeHistogram || !isPerformanceMonitoringEnabled) return;
|
|
600
|
+
const metricAttributes = {
|
|
601
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
602
|
+
phase: attributes.phase,
|
|
603
|
+
...attributes.details
|
|
604
|
+
};
|
|
605
|
+
startupTimeHistogram.record(durationMs, metricAttributes);
|
|
606
|
+
}
|
|
607
|
+
__name(recordStartupPerformance, "recordStartupPerformance");
|
|
608
|
+
function recordMemoryUsage(config, bytes, attributes) {
|
|
609
|
+
if (!memoryUsageGauge || !isPerformanceMonitoringEnabled) return;
|
|
610
|
+
const metricAttributes = {
|
|
611
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
612
|
+
...attributes
|
|
613
|
+
};
|
|
614
|
+
memoryUsageGauge.record(bytes, metricAttributes);
|
|
615
|
+
}
|
|
616
|
+
__name(recordMemoryUsage, "recordMemoryUsage");
|
|
617
|
+
function recordCpuUsage(config, percentage, attributes) {
|
|
618
|
+
if (!cpuUsageGauge || !isPerformanceMonitoringEnabled) return;
|
|
619
|
+
const metricAttributes = {
|
|
620
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
621
|
+
...attributes
|
|
622
|
+
};
|
|
623
|
+
cpuUsageGauge.record(percentage, metricAttributes);
|
|
624
|
+
}
|
|
625
|
+
__name(recordCpuUsage, "recordCpuUsage");
|
|
626
|
+
function recordToolQueueDepth(config, queueDepth) {
|
|
627
|
+
if (!toolQueueDepthGauge || !isPerformanceMonitoringEnabled) return;
|
|
628
|
+
const attributes = {
|
|
629
|
+
...baseMetricDefinition.getCommonAttributes(config)
|
|
630
|
+
};
|
|
631
|
+
toolQueueDepthGauge.record(queueDepth, attributes);
|
|
632
|
+
}
|
|
633
|
+
__name(recordToolQueueDepth, "recordToolQueueDepth");
|
|
634
|
+
function recordToolExecutionBreakdown(config, durationMs, attributes) {
|
|
635
|
+
if (!toolExecutionBreakdownHistogram || !isPerformanceMonitoringEnabled)
|
|
636
|
+
return;
|
|
637
|
+
const metricAttributes = {
|
|
638
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
639
|
+
...attributes
|
|
640
|
+
};
|
|
641
|
+
toolExecutionBreakdownHistogram.record(durationMs, metricAttributes);
|
|
642
|
+
}
|
|
643
|
+
__name(recordToolExecutionBreakdown, "recordToolExecutionBreakdown");
|
|
644
|
+
function recordTokenEfficiency(config, value, attributes) {
|
|
645
|
+
if (!tokenEfficiencyHistogram || !isPerformanceMonitoringEnabled) return;
|
|
646
|
+
const metricAttributes = {
|
|
647
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
648
|
+
...attributes
|
|
649
|
+
};
|
|
650
|
+
tokenEfficiencyHistogram.record(value, metricAttributes);
|
|
651
|
+
}
|
|
652
|
+
__name(recordTokenEfficiency, "recordTokenEfficiency");
|
|
653
|
+
function recordApiRequestBreakdown(config, durationMs, attributes) {
|
|
654
|
+
if (!apiRequestBreakdownHistogram || !isPerformanceMonitoringEnabled) return;
|
|
655
|
+
const metricAttributes = {
|
|
656
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
657
|
+
...attributes
|
|
658
|
+
};
|
|
659
|
+
apiRequestBreakdownHistogram.record(durationMs, metricAttributes);
|
|
660
|
+
}
|
|
661
|
+
__name(recordApiRequestBreakdown, "recordApiRequestBreakdown");
|
|
662
|
+
function recordPerformanceScore(config, score, attributes) {
|
|
663
|
+
if (!performanceScoreGauge || !isPerformanceMonitoringEnabled) return;
|
|
664
|
+
const metricAttributes = {
|
|
665
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
666
|
+
...attributes
|
|
667
|
+
};
|
|
668
|
+
performanceScoreGauge.record(score, metricAttributes);
|
|
669
|
+
}
|
|
670
|
+
__name(recordPerformanceScore, "recordPerformanceScore");
|
|
671
|
+
function recordPerformanceRegression(config, attributes) {
|
|
672
|
+
if (!regressionDetectionCounter || !isPerformanceMonitoringEnabled) return;
|
|
673
|
+
const metricAttributes = {
|
|
674
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
675
|
+
...attributes
|
|
676
|
+
};
|
|
677
|
+
regressionDetectionCounter.add(1, metricAttributes);
|
|
678
|
+
if (attributes.baseline_value !== 0 && regressionPercentageChangeHistogram) {
|
|
679
|
+
const percentageChange = (attributes.current_value - attributes.baseline_value) / attributes.baseline_value * 100;
|
|
680
|
+
regressionPercentageChangeHistogram.record(
|
|
681
|
+
percentageChange,
|
|
682
|
+
metricAttributes
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
__name(recordPerformanceRegression, "recordPerformanceRegression");
|
|
687
|
+
function recordBaselineComparison(config, attributes) {
|
|
688
|
+
if (!baselineComparisonHistogram || !isPerformanceMonitoringEnabled) return;
|
|
689
|
+
if (attributes.baseline_value === 0) {
|
|
690
|
+
diag.warn("Baseline value is zero, skipping comparison.");
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const percentageChange = (attributes.current_value - attributes.baseline_value) / attributes.baseline_value * 100;
|
|
694
|
+
const metricAttributes = {
|
|
695
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
696
|
+
...attributes
|
|
697
|
+
};
|
|
698
|
+
baselineComparisonHistogram.record(percentageChange, metricAttributes);
|
|
699
|
+
}
|
|
700
|
+
__name(recordBaselineComparison, "recordBaselineComparison");
|
|
701
|
+
function isPerformanceMonitoringActive() {
|
|
702
|
+
return isPerformanceMonitoringEnabled && isMetricsInitialized;
|
|
703
|
+
}
|
|
704
|
+
__name(isPerformanceMonitoringActive, "isPerformanceMonitoringActive");
|
|
705
|
+
function recordSubagentExecutionMetrics(config, subagentName, status, terminateReason) {
|
|
706
|
+
if (!subagentExecutionCounter || !isMetricsInitialized) return;
|
|
707
|
+
const attributes = {
|
|
708
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
709
|
+
subagent_name: subagentName,
|
|
710
|
+
status
|
|
711
|
+
};
|
|
712
|
+
if (terminateReason) {
|
|
713
|
+
attributes["terminate_reason"] = terminateReason;
|
|
714
|
+
}
|
|
715
|
+
subagentExecutionCounter.add(1, attributes);
|
|
716
|
+
}
|
|
717
|
+
__name(recordSubagentExecutionMetrics, "recordSubagentExecutionMetrics");
|
|
718
|
+
function recordArenaSessionStartedMetrics(config) {
|
|
719
|
+
if (!isMetricsInitialized) return;
|
|
720
|
+
arenaSessionCounter?.add(1, {
|
|
721
|
+
...baseMetricDefinition.getCommonAttributes(config),
|
|
722
|
+
status: "started"
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
__name(recordArenaSessionStartedMetrics, "recordArenaSessionStartedMetrics");
|
|
726
|
+
function recordArenaAgentCompletedMetrics(config, modelId, status, durationMs, inputTokens, outputTokens) {
|
|
727
|
+
if (!isMetricsInitialized) return;
|
|
728
|
+
const common = baseMetricDefinition.getCommonAttributes(config);
|
|
729
|
+
arenaAgentCounter?.add(1, {
|
|
730
|
+
...common,
|
|
731
|
+
status,
|
|
732
|
+
model_id: modelId
|
|
733
|
+
});
|
|
734
|
+
arenaAgentDurationHistogram?.record(durationMs, {
|
|
735
|
+
...common,
|
|
736
|
+
model_id: modelId
|
|
737
|
+
});
|
|
738
|
+
if (inputTokens > 0) {
|
|
739
|
+
arenaAgentTokensCounter?.add(inputTokens, {
|
|
740
|
+
...common,
|
|
741
|
+
model_id: modelId,
|
|
742
|
+
type: "input"
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
if (outputTokens > 0) {
|
|
746
|
+
arenaAgentTokensCounter?.add(outputTokens, {
|
|
747
|
+
...common,
|
|
748
|
+
model_id: modelId,
|
|
749
|
+
type: "output"
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
__name(recordArenaAgentCompletedMetrics, "recordArenaAgentCompletedMetrics");
|
|
754
|
+
function recordArenaSessionEndedMetrics(config, status, displayBackend, durationMs, winnerModelId) {
|
|
755
|
+
if (!isMetricsInitialized) return;
|
|
756
|
+
const common = baseMetricDefinition.getCommonAttributes(config);
|
|
757
|
+
arenaSessionCounter?.add(1, {
|
|
758
|
+
...common,
|
|
759
|
+
status,
|
|
760
|
+
...displayBackend ? { display_backend: displayBackend } : {}
|
|
761
|
+
});
|
|
762
|
+
if (durationMs !== void 0 && arenaSessionDurationHistogram) {
|
|
763
|
+
arenaSessionDurationHistogram.record(durationMs, {
|
|
764
|
+
...common,
|
|
765
|
+
status
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
if (winnerModelId) {
|
|
769
|
+
arenaResultSelectedCounter?.add(1, {
|
|
770
|
+
...common,
|
|
771
|
+
model_id: winnerModelId
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
__name(recordArenaSessionEndedMetrics, "recordArenaSessionEndedMetrics");
|
|
776
|
+
function recordMemoryExtractMetrics(config, durationMs, attrs) {
|
|
777
|
+
if (!isMetricsInitialized) return;
|
|
778
|
+
const common = baseMetricDefinition.getCommonAttributes(config);
|
|
779
|
+
memoryExtractCounter?.add(1, {
|
|
780
|
+
...common,
|
|
781
|
+
trigger: attrs.trigger,
|
|
782
|
+
status: attrs.status
|
|
783
|
+
});
|
|
784
|
+
memoryExtractDurationHistogram?.record(durationMs, {
|
|
785
|
+
...common,
|
|
786
|
+
trigger: attrs.trigger,
|
|
787
|
+
status: attrs.status
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
__name(recordMemoryExtractMetrics, "recordMemoryExtractMetrics");
|
|
791
|
+
function recordMemoryDreamMetrics(config, durationMs, attrs) {
|
|
792
|
+
if (!isMetricsInitialized) return;
|
|
793
|
+
const common = baseMetricDefinition.getCommonAttributes(config);
|
|
794
|
+
memoryDreamCounter?.add(1, {
|
|
795
|
+
...common,
|
|
796
|
+
trigger: attrs.trigger,
|
|
797
|
+
status: attrs.status
|
|
798
|
+
});
|
|
799
|
+
memoryDreamDurationHistogram?.record(durationMs, {
|
|
800
|
+
...common,
|
|
801
|
+
trigger: attrs.trigger,
|
|
802
|
+
status: attrs.status
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
__name(recordMemoryDreamMetrics, "recordMemoryDreamMetrics");
|
|
806
|
+
function recordMemoryRecallMetrics(config, durationMs, attrs) {
|
|
807
|
+
if (!isMetricsInitialized) return;
|
|
808
|
+
const common = baseMetricDefinition.getCommonAttributes(config);
|
|
809
|
+
memoryRecallCounter?.add(1, { ...common, strategy: attrs.strategy });
|
|
810
|
+
memoryRecallDurationHistogram?.record(durationMs, {
|
|
811
|
+
...common,
|
|
812
|
+
strategy: attrs.strategy
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
__name(recordMemoryRecallMetrics, "recordMemoryRecallMetrics");
|
|
816
|
+
function recordChannelMemoryRecallMetrics(observation) {
|
|
817
|
+
if (!isMetricsInitialized) return;
|
|
818
|
+
const attributes = {
|
|
819
|
+
cache: observation.cache,
|
|
820
|
+
result: observation.result
|
|
821
|
+
};
|
|
822
|
+
channelMemoryRecallCounter?.add(1, attributes);
|
|
823
|
+
channelMemoryRecallDurationHistogram?.record(
|
|
824
|
+
observation.durationMs,
|
|
825
|
+
attributes
|
|
826
|
+
);
|
|
827
|
+
channelMemoryRecallSelectedCountHistogram?.record(
|
|
828
|
+
observation.selectedCount,
|
|
829
|
+
attributes
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
__name(recordChannelMemoryRecallMetrics, "recordChannelMemoryRecallMetrics");
|
|
833
|
+
function recordMemoryRecallDeliveryMetrics(config, latencyMs, attrs) {
|
|
834
|
+
if (!isMetricsInitialized) return;
|
|
835
|
+
const common = baseMetricDefinition.getCommonAttributes(config);
|
|
836
|
+
const metricAttributes = {
|
|
837
|
+
...common,
|
|
838
|
+
phase: attrs.phase,
|
|
839
|
+
delivery_point: attrs.delivery_point,
|
|
840
|
+
strategy: attrs.strategy,
|
|
841
|
+
...attrs.discard_reason ? { discard_reason: attrs.discard_reason } : {}
|
|
842
|
+
};
|
|
843
|
+
memoryRecallDeliveryCounter?.add(1, metricAttributes);
|
|
844
|
+
memoryRecallDeliveryLatencyHistogram?.record(latencyMs, metricAttributes);
|
|
845
|
+
}
|
|
846
|
+
__name(recordMemoryRecallDeliveryMetrics, "recordMemoryRecallDeliveryMetrics");
|
|
847
|
+
|
|
848
|
+
// packages/core/src/telemetry/detailed-span-attributes.ts
|
|
849
|
+
init_esbuild_shims();
|
|
850
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
851
|
+
|
|
852
|
+
// packages/core/src/telemetry/sdk.ts
|
|
853
|
+
init_esbuild_shims();
|
|
854
|
+
init_esm();
|
|
855
|
+
|
|
856
|
+
// packages/core/src/telemetry/tracer.ts
|
|
857
|
+
init_esbuild_shims();
|
|
858
|
+
init_esm();
|
|
859
|
+
|
|
860
|
+
// packages/core/src/telemetry/trace-id-utils.ts
|
|
861
|
+
init_esbuild_shims();
|
|
862
|
+
import { createHash } from "node:crypto";
|
|
863
|
+
function deriveTraceId(sessionId) {
|
|
864
|
+
return createHash("sha256").update(sessionId).digest("hex").slice(0, 32);
|
|
865
|
+
}
|
|
866
|
+
__name(deriveTraceId, "deriveTraceId");
|
|
867
|
+
function randomSpanId() {
|
|
868
|
+
const bytes = new Uint8Array(8);
|
|
869
|
+
crypto.getRandomValues(bytes);
|
|
870
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
871
|
+
}
|
|
872
|
+
__name(randomSpanId, "randomSpanId");
|
|
873
|
+
function randomHexString(length) {
|
|
874
|
+
const bytes = new Uint8Array(Math.ceil(length / 2));
|
|
875
|
+
crypto.getRandomValues(bytes);
|
|
876
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("").slice(0, length);
|
|
877
|
+
}
|
|
878
|
+
__name(randomHexString, "randomHexString");
|
|
879
|
+
|
|
880
|
+
// packages/core/src/telemetry/tracer.ts
|
|
881
|
+
var tracer = trace.getTracer(SERVICE_NAME);
|
|
882
|
+
var debugLogger = createDebugLogger("OTEL_TRACER");
|
|
883
|
+
var TELEMETRY_WARNING_INTERVAL_MS = 3e4;
|
|
884
|
+
var API_CALL_FAILED_SPAN_STATUS_MESSAGE = "API call failed";
|
|
885
|
+
var API_CALL_ABORTED_SPAN_STATUS_MESSAGE = "API call aborted";
|
|
886
|
+
var lastTelemetryWarningMs;
|
|
887
|
+
var suppressedTelemetryWarnings = 0;
|
|
888
|
+
function warnTelemetryOperationFailed(operation, error) {
|
|
889
|
+
const now = Date.now();
|
|
890
|
+
if (lastTelemetryWarningMs !== void 0 && now - lastTelemetryWarningMs < TELEMETRY_WARNING_INTERVAL_MS) {
|
|
891
|
+
suppressedTelemetryWarnings += 1;
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
const suppressedSuffix = suppressedTelemetryWarnings > 0 ? `; suppressed ${suppressedTelemetryWarnings} similar warning(s)` : "";
|
|
895
|
+
suppressedTelemetryWarnings = 0;
|
|
896
|
+
lastTelemetryWarningMs = now;
|
|
897
|
+
try {
|
|
898
|
+
debugLogger.warn(
|
|
899
|
+
`OTel span ${operation} failed: ${error instanceof Error ? error.message : String(error)}${suppressedSuffix}`
|
|
900
|
+
);
|
|
901
|
+
} catch {
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
__name(warnTelemetryOperationFailed, "warnTelemetryOperationFailed");
|
|
905
|
+
function safeSetStatus(span, status) {
|
|
906
|
+
try {
|
|
907
|
+
span.setStatus(status);
|
|
908
|
+
} catch (error) {
|
|
909
|
+
warnTelemetryOperationFailed("setStatus", error);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
__name(safeSetStatus, "safeSetStatus");
|
|
913
|
+
function shouldForceSampled() {
|
|
914
|
+
const sampler = process.env["OTEL_TRACES_SAMPLER"]?.trim().toLowerCase() ?? "";
|
|
915
|
+
if (!sampler || sampler.startsWith("parentbased_")) {
|
|
916
|
+
if (sampler.includes("always_off")) return false;
|
|
917
|
+
return true;
|
|
918
|
+
}
|
|
919
|
+
return sampler === "always_on";
|
|
920
|
+
}
|
|
921
|
+
__name(shouldForceSampled, "shouldForceSampled");
|
|
922
|
+
function createSessionRootContext(sessionId) {
|
|
923
|
+
const traceId = deriveTraceId(sessionId);
|
|
924
|
+
const spanId = randomSpanId();
|
|
925
|
+
const rootSpan = trace.wrapSpanContext({
|
|
926
|
+
traceId,
|
|
927
|
+
spanId,
|
|
928
|
+
traceFlags: shouldForceSampled() ? TraceFlags.SAMPLED : TraceFlags.NONE,
|
|
929
|
+
isRemote: false
|
|
930
|
+
});
|
|
931
|
+
return trace.setSpan(ROOT_CONTEXT, rootSpan);
|
|
932
|
+
}
|
|
933
|
+
__name(createSessionRootContext, "createSessionRootContext");
|
|
934
|
+
|
|
935
|
+
// packages/core/src/telemetry/session-tracing.ts
|
|
936
|
+
init_esbuild_shims();
|
|
937
|
+
init_esm();
|
|
938
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
939
|
+
var debugLogger2 = createDebugLogger("SESSION_TRACING");
|
|
940
|
+
function resolveParentContext(parent) {
|
|
941
|
+
if (parent) {
|
|
942
|
+
return trace.setSpan(context.active(), parent.span);
|
|
943
|
+
}
|
|
944
|
+
return context.active();
|
|
945
|
+
}
|
|
946
|
+
__name(resolveParentContext, "resolveParentContext");
|
|
947
|
+
var NOOP_SPAN = trace.wrapSpanContext({
|
|
948
|
+
traceId: "0".repeat(32),
|
|
949
|
+
spanId: "0".repeat(16),
|
|
950
|
+
traceFlags: 0
|
|
951
|
+
});
|
|
952
|
+
var interactionContext = new AsyncLocalStorage();
|
|
953
|
+
var toolContext = new AsyncLocalStorage();
|
|
954
|
+
var subagentContext = new AsyncLocalStorage();
|
|
955
|
+
function isInNativeSubagentSpan() {
|
|
956
|
+
const ctx = subagentContext.getStore();
|
|
957
|
+
return ctx !== void 0 && !ctx.ended;
|
|
958
|
+
}
|
|
959
|
+
__name(isInNativeSubagentSpan, "isInNativeSubagentSpan");
|
|
960
|
+
function resolveSessionId(parentCtx) {
|
|
961
|
+
const fromParent = parentCtx?.attributes?.["session.id"];
|
|
962
|
+
return typeof fromParent === "string" && fromParent ? fromParent : getCurrentSessionId();
|
|
963
|
+
}
|
|
964
|
+
__name(resolveSessionId, "resolveSessionId");
|
|
965
|
+
var activeSpans = /* @__PURE__ */ new Map();
|
|
966
|
+
var strongSpans = /* @__PURE__ */ new Map();
|
|
967
|
+
var interactionSequence = 0;
|
|
968
|
+
var lastInteractionCtx;
|
|
969
|
+
var cleanupIntervalStarted = false;
|
|
970
|
+
var SPAN_TTL_MS_DEFAULT = 30 * 60 * 1e3;
|
|
971
|
+
var SPAN_TTL_MS_LONG = 4 * 60 * 60 * 1e3;
|
|
972
|
+
var LONG_TTL_SUBAGENT_KINDS = /* @__PURE__ */ new Set([
|
|
973
|
+
"fork",
|
|
974
|
+
"background"
|
|
975
|
+
]);
|
|
976
|
+
function ttlFor(ctx) {
|
|
977
|
+
if (ctx.type === "subagent") {
|
|
978
|
+
const kind = ctx.attributes["qwen-code.subagent.invocation_kind"];
|
|
979
|
+
if (typeof kind === "string" && LONG_TTL_SUBAGENT_KINDS.has(kind)) {
|
|
980
|
+
return SPAN_TTL_MS_LONG;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
return SPAN_TTL_MS_DEFAULT;
|
|
984
|
+
}
|
|
985
|
+
__name(ttlFor, "ttlFor");
|
|
986
|
+
function sweepStaleSpans(now) {
|
|
987
|
+
for (const [spanId, weakRef] of activeSpans) {
|
|
988
|
+
const ctx = weakRef.deref();
|
|
989
|
+
if (ctx === void 0) {
|
|
990
|
+
activeSpans.delete(spanId);
|
|
991
|
+
strongSpans.delete(spanId);
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
if (now - ctx.startTime < ttlFor(ctx)) continue;
|
|
995
|
+
if (!ctx.ended) {
|
|
996
|
+
ctx.ended = true;
|
|
997
|
+
const ageMs = now - ctx.startTime;
|
|
998
|
+
const toolName = ctx.attributes["gen_ai.tool.name"] ?? ctx.attributes["tool.name"];
|
|
999
|
+
const callId = ctx.attributes["tool.call_id"];
|
|
1000
|
+
try {
|
|
1001
|
+
ctx.span.setAttributes({
|
|
1002
|
+
"qwen-code.span.ttl_expired": true,
|
|
1003
|
+
"qwen-code.span.duration_ms": ageMs,
|
|
1004
|
+
...ctx.type === "tool.blocked_on_user" ? {
|
|
1005
|
+
decision: "aborted",
|
|
1006
|
+
source: "system"
|
|
1007
|
+
} : {},
|
|
1008
|
+
...ctx.type === "subagent" ? {
|
|
1009
|
+
"qwen-code.subagent.status": "aborted",
|
|
1010
|
+
"qwen-code.subagent.terminate_reason": "ttl_swept",
|
|
1011
|
+
// Mirror the subagent-specific duration_ms key that
|
|
1012
|
+
// endSubagentSpan stamps so dashboards querying that
|
|
1013
|
+
// namespace see TTL-swept spans too (they currently
|
|
1014
|
+
// only get the generic qwen-code.span.duration_ms
|
|
1015
|
+
// above). wenshao @ #4410.
|
|
1016
|
+
"qwen-code.subagent.duration_ms": ageMs
|
|
1017
|
+
} : {}
|
|
1018
|
+
});
|
|
1019
|
+
} catch (error) {
|
|
1020
|
+
debugLogger2.warn(
|
|
1021
|
+
`Failed to stamp TTL attrs on stale span ${spanId}: ${error instanceof Error ? error.message : String(error)}`
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
const ctxLabel = toolName && callId ? `${ctx.type} (tool.name=${toolName}, tool.call_id=${callId})` : ctx.type;
|
|
1025
|
+
debugLogger2.warn(
|
|
1026
|
+
`Stale ${ctxLabel} span ended by TTL safety net (age=${ageMs}ms, spanId=${spanId})`
|
|
1027
|
+
);
|
|
1028
|
+
try {
|
|
1029
|
+
ctx.span.end();
|
|
1030
|
+
} catch (error) {
|
|
1031
|
+
debugLogger2.warn(
|
|
1032
|
+
`Failed to end stale span ${spanId}: ${error instanceof Error ? error.message : String(error)}`
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
activeSpans.delete(spanId);
|
|
1037
|
+
strongSpans.delete(spanId);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
__name(sweepStaleSpans, "sweepStaleSpans");
|
|
1041
|
+
function ensureCleanupInterval() {
|
|
1042
|
+
if (cleanupIntervalStarted) return;
|
|
1043
|
+
cleanupIntervalStarted = true;
|
|
1044
|
+
const interval = setInterval(() => sweepStaleSpans(Date.now()), 6e4);
|
|
1045
|
+
if (typeof interval.unref === "function") {
|
|
1046
|
+
interval.unref();
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
__name(ensureCleanupInterval, "ensureCleanupInterval");
|
|
1050
|
+
function getSpanId(span) {
|
|
1051
|
+
return span.spanContext().spanId || "";
|
|
1052
|
+
}
|
|
1053
|
+
__name(getSpanId, "getSpanId");
|
|
1054
|
+
var SPAN_TEXT_MAX_CHARS = 1024;
|
|
1055
|
+
function truncateSpanText(s) {
|
|
1056
|
+
if (s.length <= SPAN_TEXT_MAX_CHARS) return s;
|
|
1057
|
+
let end = SPAN_TEXT_MAX_CHARS;
|
|
1058
|
+
const code = s.charCodeAt(end - 1);
|
|
1059
|
+
if (code >= 55296 && code <= 56319) end--;
|
|
1060
|
+
return s.slice(0, end) + "\u2026[truncated]";
|
|
1061
|
+
}
|
|
1062
|
+
__name(truncateSpanText, "truncateSpanText");
|
|
1063
|
+
function truncateSpanError(s) {
|
|
1064
|
+
return truncateSpanText(s);
|
|
1065
|
+
}
|
|
1066
|
+
__name(truncateSpanError, "truncateSpanError");
|
|
1067
|
+
function getTracer() {
|
|
1068
|
+
return trace.getTracer(SERVICE_NAME, "1.0.0");
|
|
1069
|
+
}
|
|
1070
|
+
__name(getTracer, "getTracer");
|
|
1071
|
+
function startInteractionSpan(config, options) {
|
|
1072
|
+
if (!isTelemetrySdkInitialized()) return;
|
|
1073
|
+
ensureCleanupInterval();
|
|
1074
|
+
interactionSequence++;
|
|
1075
|
+
const attributes = {
|
|
1076
|
+
"session.id": config.getSessionId(),
|
|
1077
|
+
"qwen-code.prompt_id": options.promptId,
|
|
1078
|
+
"qwen-code.message_type": options.messageType,
|
|
1079
|
+
"qwen-code.model": options.model,
|
|
1080
|
+
"qwen-code.approval_mode": config.getApprovalMode(),
|
|
1081
|
+
"interaction.sequence": interactionSequence
|
|
1082
|
+
};
|
|
1083
|
+
const span = getTracer().startSpan(
|
|
1084
|
+
SPAN_INTERACTION,
|
|
1085
|
+
{ kind: SpanKind.INTERNAL, attributes },
|
|
1086
|
+
ROOT_CONTEXT
|
|
1087
|
+
);
|
|
1088
|
+
const spanId = getSpanId(span);
|
|
1089
|
+
const spanContextObj = {
|
|
1090
|
+
span,
|
|
1091
|
+
startTime: Date.now(),
|
|
1092
|
+
attributes,
|
|
1093
|
+
type: "interaction"
|
|
1094
|
+
};
|
|
1095
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
1096
|
+
strongSpans.set(spanId, spanContextObj);
|
|
1097
|
+
lastInteractionCtx = spanContextObj;
|
|
1098
|
+
interactionContext.enterWith(spanContextObj);
|
|
1099
|
+
}
|
|
1100
|
+
__name(startInteractionSpan, "startInteractionSpan");
|
|
1101
|
+
function endInteractionSpan(status, metadata) {
|
|
1102
|
+
const spanCtx = interactionContext.getStore() ?? lastInteractionCtx;
|
|
1103
|
+
if (!spanCtx) return;
|
|
1104
|
+
if (spanCtx.ended) {
|
|
1105
|
+
debugLogger2.debug(
|
|
1106
|
+
`endInteractionSpan: span ${getSpanId(spanCtx.span)} already ended (possible TTL sweep race)`
|
|
1107
|
+
);
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
spanCtx.ended = true;
|
|
1111
|
+
lastInteractionCtx = void 0;
|
|
1112
|
+
const duration = Date.now() - spanCtx.startTime;
|
|
1113
|
+
spanCtx.span.setAttributes({
|
|
1114
|
+
"interaction.duration_ms": duration,
|
|
1115
|
+
"qwen-code.turn_status": status
|
|
1116
|
+
});
|
|
1117
|
+
if (status === "error") {
|
|
1118
|
+
spanCtx.span.setStatus({
|
|
1119
|
+
code: SpanStatusCode.ERROR,
|
|
1120
|
+
message: metadata?.errorMessage ?? "unknown error"
|
|
1121
|
+
});
|
|
1122
|
+
} else {
|
|
1123
|
+
spanCtx.span.setStatus({ code: SpanStatusCode.OK });
|
|
1124
|
+
}
|
|
1125
|
+
spanCtx.span.end();
|
|
1126
|
+
const spanId = getSpanId(spanCtx.span);
|
|
1127
|
+
activeSpans.delete(spanId);
|
|
1128
|
+
strongSpans.delete(spanId);
|
|
1129
|
+
interactionContext.enterWith(void 0);
|
|
1130
|
+
}
|
|
1131
|
+
__name(endInteractionSpan, "endInteractionSpan");
|
|
1132
|
+
async function withInteractionSpan(config, options, fn, getResultStatus) {
|
|
1133
|
+
if (!isTelemetrySdkInitialized()) return await fn();
|
|
1134
|
+
ensureCleanupInterval();
|
|
1135
|
+
interactionSequence++;
|
|
1136
|
+
const attributes = {
|
|
1137
|
+
"session.id": config.getSessionId(),
|
|
1138
|
+
"qwen-code.prompt_id": options.promptId,
|
|
1139
|
+
"qwen-code.message_type": options.messageType,
|
|
1140
|
+
"qwen-code.model": options.model,
|
|
1141
|
+
"qwen-code.approval_mode": config.getApprovalMode(),
|
|
1142
|
+
"interaction.sequence": interactionSequence
|
|
1143
|
+
};
|
|
1144
|
+
const parentContext = options.parentContext ?? ROOT_CONTEXT;
|
|
1145
|
+
const span = getTracer().startSpan(
|
|
1146
|
+
SPAN_INTERACTION,
|
|
1147
|
+
{
|
|
1148
|
+
kind: SpanKind.INTERNAL,
|
|
1149
|
+
attributes
|
|
1150
|
+
},
|
|
1151
|
+
parentContext
|
|
1152
|
+
);
|
|
1153
|
+
const spanId = getSpanId(span);
|
|
1154
|
+
const spanContextObj = {
|
|
1155
|
+
span,
|
|
1156
|
+
startTime: Date.now(),
|
|
1157
|
+
attributes,
|
|
1158
|
+
type: "interaction"
|
|
1159
|
+
};
|
|
1160
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
1161
|
+
strongSpans.set(spanId, spanContextObj);
|
|
1162
|
+
const activeContext = trace.setSpan(parentContext, span);
|
|
1163
|
+
return await context.with(
|
|
1164
|
+
activeContext,
|
|
1165
|
+
async () => interactionContext.run(spanContextObj, async () => {
|
|
1166
|
+
let terminalStatus = "ok";
|
|
1167
|
+
let errorStatusSet = false;
|
|
1168
|
+
try {
|
|
1169
|
+
const result = await fn();
|
|
1170
|
+
terminalStatus = getResultStatus?.(result) ?? "ok";
|
|
1171
|
+
return result;
|
|
1172
|
+
} catch (error) {
|
|
1173
|
+
terminalStatus = "error";
|
|
1174
|
+
span.setStatus({
|
|
1175
|
+
code: SpanStatusCode.ERROR,
|
|
1176
|
+
message: truncateSpanError(
|
|
1177
|
+
error instanceof Error ? error.message : String(error)
|
|
1178
|
+
)
|
|
1179
|
+
});
|
|
1180
|
+
errorStatusSet = true;
|
|
1181
|
+
throw error;
|
|
1182
|
+
} finally {
|
|
1183
|
+
if (!spanContextObj.ended) {
|
|
1184
|
+
spanContextObj.ended = true;
|
|
1185
|
+
const duration = Date.now() - spanContextObj.startTime;
|
|
1186
|
+
span.setAttributes({
|
|
1187
|
+
"interaction.duration_ms": duration,
|
|
1188
|
+
"qwen-code.turn_status": terminalStatus
|
|
1189
|
+
});
|
|
1190
|
+
if (terminalStatus === "ok") {
|
|
1191
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
1192
|
+
} else if (terminalStatus === "error" && !errorStatusSet) {
|
|
1193
|
+
span.setStatus({
|
|
1194
|
+
code: SpanStatusCode.ERROR,
|
|
1195
|
+
message: "interaction error"
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
span.end();
|
|
1199
|
+
activeSpans.delete(spanId);
|
|
1200
|
+
strongSpans.delete(spanId);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
})
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
__name(withInteractionSpan, "withInteractionSpan");
|
|
1207
|
+
function startLLMRequestSpan(model, promptId, options) {
|
|
1208
|
+
if (!isTelemetrySdkInitialized()) {
|
|
1209
|
+
return NOOP_SPAN;
|
|
1210
|
+
}
|
|
1211
|
+
const parentCtx = subagentContext.getStore() ?? interactionContext.getStore();
|
|
1212
|
+
const ctx = resolveParentContext(parentCtx);
|
|
1213
|
+
const sessionId = resolveSessionId(parentCtx);
|
|
1214
|
+
const attributes = {
|
|
1215
|
+
...sessionId ? { "session.id": sessionId } : {},
|
|
1216
|
+
...sessionId ? { "gen_ai.conversation.id": sessionId } : {},
|
|
1217
|
+
"qwen-code.prompt_id": promptId,
|
|
1218
|
+
"llm_request.context": subagentContext.getStore() ? "subagent" : interactionContext.getStore() ? "interaction" : "standalone",
|
|
1219
|
+
// Emit the version-pinned OTel GenAI semantic convention.
|
|
1220
|
+
"gen_ai.request.model": model,
|
|
1221
|
+
...options?.operationName ? { "gen_ai.operation.name": options.operationName } : {},
|
|
1222
|
+
...options?.providerName ? { "gen_ai.provider.name": options.providerName } : {},
|
|
1223
|
+
...options?.outputType ? { "gen_ai.output.type": options.outputType } : {}
|
|
1224
|
+
};
|
|
1225
|
+
const span = getTracer().startSpan(
|
|
1226
|
+
SPAN_LLM_REQUEST,
|
|
1227
|
+
{ kind: SpanKind.INTERNAL, attributes },
|
|
1228
|
+
ctx
|
|
1229
|
+
);
|
|
1230
|
+
const spanId = getSpanId(span);
|
|
1231
|
+
const spanContextObj = {
|
|
1232
|
+
span,
|
|
1233
|
+
startTime: Date.now(),
|
|
1234
|
+
attributes,
|
|
1235
|
+
type: "llm_request"
|
|
1236
|
+
};
|
|
1237
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
1238
|
+
strongSpans.set(spanId, spanContextObj);
|
|
1239
|
+
return span;
|
|
1240
|
+
}
|
|
1241
|
+
__name(startLLMRequestSpan, "startLLMRequestSpan");
|
|
1242
|
+
function endLLMRequestSpan(span, metadata) {
|
|
1243
|
+
const spanId = getSpanId(span);
|
|
1244
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
1245
|
+
if (!spanCtx) return;
|
|
1246
|
+
if (spanCtx.ended) {
|
|
1247
|
+
debugLogger2.debug(
|
|
1248
|
+
`endLLMRequestSpan: span ${spanId} already ended (possible TTL sweep race)`
|
|
1249
|
+
);
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
spanCtx.ended = true;
|
|
1253
|
+
try {
|
|
1254
|
+
const duration = metadata?.durationMs ?? Date.now() - spanCtx.startTime;
|
|
1255
|
+
const endAttributes = { duration_ms: duration };
|
|
1256
|
+
if (metadata) {
|
|
1257
|
+
if (metadata.inputTokens !== void 0 && Number.isSafeInteger(metadata.inputTokens) && metadata.inputTokens >= 0) {
|
|
1258
|
+
endAttributes["gen_ai.usage.input_tokens"] = metadata.inputTokens;
|
|
1259
|
+
}
|
|
1260
|
+
if (metadata.outputTokens !== void 0 && Number.isSafeInteger(metadata.outputTokens) && metadata.outputTokens >= 0) {
|
|
1261
|
+
endAttributes["gen_ai.usage.output_tokens"] = metadata.outputTokens;
|
|
1262
|
+
}
|
|
1263
|
+
if (metadata.cachedInputTokensReported && metadata.cachedInputTokens !== void 0 && Number.isSafeInteger(metadata.cachedInputTokens) && metadata.cachedInputTokens >= 0) {
|
|
1264
|
+
endAttributes["gen_ai.usage.cache_read.input_tokens"] = metadata.cachedInputTokens;
|
|
1265
|
+
}
|
|
1266
|
+
if (metadata.cacheCreationInputTokens !== void 0 && Number.isSafeInteger(metadata.cacheCreationInputTokens) && metadata.cacheCreationInputTokens >= 0) {
|
|
1267
|
+
endAttributes["gen_ai.usage.cache_creation.input_tokens"] = metadata.cacheCreationInputTokens;
|
|
1268
|
+
}
|
|
1269
|
+
if (metadata.ttftMs !== void 0) {
|
|
1270
|
+
endAttributes["ttft_ms"] = metadata.ttftMs;
|
|
1271
|
+
}
|
|
1272
|
+
if (metadata.requestSetupMs !== void 0) {
|
|
1273
|
+
endAttributes["request_setup_ms"] = metadata.requestSetupMs;
|
|
1274
|
+
}
|
|
1275
|
+
if (metadata.attempt !== void 0) {
|
|
1276
|
+
endAttributes["attempt"] = metadata.attempt;
|
|
1277
|
+
}
|
|
1278
|
+
if (metadata.retryTotalDelayMs !== void 0) {
|
|
1279
|
+
endAttributes["retry_total_delay_ms"] = metadata.retryTotalDelayMs;
|
|
1280
|
+
}
|
|
1281
|
+
if (metadata.ttftMs !== void 0) {
|
|
1282
|
+
const samplingMs = Math.max(0, duration - metadata.ttftMs);
|
|
1283
|
+
endAttributes["sampling_ms"] = samplingMs;
|
|
1284
|
+
if (samplingMs > 0 && metadata.outputTokens !== void 0) {
|
|
1285
|
+
endAttributes["output_tokens_per_second"] = Math.round(metadata.outputTokens / (samplingMs / 1e3) * 100) / 100;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
endAttributes["success"] = metadata.success;
|
|
1289
|
+
if (metadata.error !== void 0)
|
|
1290
|
+
endAttributes["error"] = truncateSpanError(metadata.error);
|
|
1291
|
+
if (metadata.responseId !== void 0) {
|
|
1292
|
+
endAttributes["gen_ai.response.id"] = metadata.responseId;
|
|
1293
|
+
}
|
|
1294
|
+
if (metadata.responseModel !== void 0) {
|
|
1295
|
+
endAttributes["gen_ai.response.model"] = metadata.responseModel;
|
|
1296
|
+
}
|
|
1297
|
+
const finishReasons = metadata.finishReasons?.length ? metadata.finishReasons : metadata.finishReason !== void 0 ? [metadata.finishReason] : void 0;
|
|
1298
|
+
if (finishReasons) {
|
|
1299
|
+
endAttributes["finish_reason"] = finishReasons[0];
|
|
1300
|
+
endAttributes["gen_ai.response.finish_reasons"] = finishReasons;
|
|
1301
|
+
}
|
|
1302
|
+
if (metadata.thoughtsTokenCount !== void 0) {
|
|
1303
|
+
endAttributes["thoughts_token_count"] = metadata.thoughtsTokenCount;
|
|
1304
|
+
}
|
|
1305
|
+
if (metadata.subagentName !== void 0) {
|
|
1306
|
+
endAttributes["subagent_name"] = metadata.subagentName;
|
|
1307
|
+
}
|
|
1308
|
+
if (metadata.errorType !== void 0) {
|
|
1309
|
+
endAttributes["error_type"] = metadata.errorType;
|
|
1310
|
+
endAttributes["error.type"] = metadata.errorType;
|
|
1311
|
+
}
|
|
1312
|
+
if (metadata.errorStatusCode !== void 0) {
|
|
1313
|
+
endAttributes["error_status_code"] = metadata.errorStatusCode;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
spanCtx.span.setAttributes(endAttributes);
|
|
1317
|
+
try {
|
|
1318
|
+
if (metadata?.config && metadata.success) {
|
|
1319
|
+
const model = String(spanCtx.attributes["gen_ai.request.model"] ?? "");
|
|
1320
|
+
if (metadata.requestSetupMs !== void 0) {
|
|
1321
|
+
recordApiRequestBreakdown(metadata.config, metadata.requestSetupMs, {
|
|
1322
|
+
model,
|
|
1323
|
+
phase: "request_preparation" /* REQUEST_PREPARATION */
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
if (metadata.ttftMs !== void 0) {
|
|
1327
|
+
recordApiRequestBreakdown(metadata.config, metadata.ttftMs, {
|
|
1328
|
+
model,
|
|
1329
|
+
phase: "network_latency" /* NETWORK_LATENCY */
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
const breakdownSamplingMs = metadata.ttftMs !== void 0 ? Math.max(0, duration - metadata.ttftMs) : void 0;
|
|
1333
|
+
if (breakdownSamplingMs !== void 0 && breakdownSamplingMs > 0) {
|
|
1334
|
+
recordApiRequestBreakdown(metadata.config, breakdownSamplingMs, {
|
|
1335
|
+
model,
|
|
1336
|
+
phase: "response_processing" /* RESPONSE_PROCESSING */
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
} catch (error) {
|
|
1341
|
+
debugLogger2.warn(
|
|
1342
|
+
`Failed to record API request breakdown histogram: ${error instanceof Error ? error.message : String(error)}`
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
if (metadata === void 0 || metadata.success) {
|
|
1346
|
+
spanCtx.span.setStatus({ code: SpanStatusCode.OK });
|
|
1347
|
+
} else {
|
|
1348
|
+
spanCtx.span.setStatus({
|
|
1349
|
+
code: SpanStatusCode.ERROR,
|
|
1350
|
+
message: metadata.error ? truncateSpanError(metadata.error) : "unknown error"
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
} catch (error) {
|
|
1354
|
+
debugLogger2.warn(
|
|
1355
|
+
`Failed to update LLM request span attributes/status: ${error instanceof Error ? error.message : String(error)}`
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
try {
|
|
1359
|
+
spanCtx.span.end();
|
|
1360
|
+
} catch (error) {
|
|
1361
|
+
debugLogger2.warn(
|
|
1362
|
+
`Failed to end LLM request span: ${error instanceof Error ? error.message : String(error)}`
|
|
1363
|
+
);
|
|
1364
|
+
}
|
|
1365
|
+
activeSpans.delete(spanId);
|
|
1366
|
+
strongSpans.delete(spanId);
|
|
1367
|
+
}
|
|
1368
|
+
__name(endLLMRequestSpan, "endLLMRequestSpan");
|
|
1369
|
+
function startToolSpan(toolName, attrs) {
|
|
1370
|
+
if (!isTelemetrySdkInitialized()) {
|
|
1371
|
+
return NOOP_SPAN;
|
|
1372
|
+
}
|
|
1373
|
+
const parentCtx = subagentContext.getStore() ?? interactionContext.getStore();
|
|
1374
|
+
const ctx = resolveParentContext(parentCtx);
|
|
1375
|
+
const sessionId = resolveSessionId(parentCtx);
|
|
1376
|
+
const attributes = {
|
|
1377
|
+
...sessionId ? { "session.id": sessionId } : {},
|
|
1378
|
+
...attrs,
|
|
1379
|
+
"gen_ai.operation.name": "execute_tool",
|
|
1380
|
+
"gen_ai.tool.name": toolName,
|
|
1381
|
+
"gen_ai.tool.type": "function"
|
|
1382
|
+
};
|
|
1383
|
+
const span = getTracer().startSpan(
|
|
1384
|
+
SPAN_TOOL,
|
|
1385
|
+
{ kind: SpanKind.INTERNAL, attributes },
|
|
1386
|
+
ctx
|
|
1387
|
+
);
|
|
1388
|
+
const spanId = getSpanId(span);
|
|
1389
|
+
const spanContextObj = {
|
|
1390
|
+
span,
|
|
1391
|
+
startTime: Date.now(),
|
|
1392
|
+
attributes,
|
|
1393
|
+
type: "tool"
|
|
1394
|
+
};
|
|
1395
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
1396
|
+
strongSpans.set(spanId, spanContextObj);
|
|
1397
|
+
return span;
|
|
1398
|
+
}
|
|
1399
|
+
__name(startToolSpan, "startToolSpan");
|
|
1400
|
+
function runInToolSpanContext(span, fn) {
|
|
1401
|
+
const spanId = getSpanId(span);
|
|
1402
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
1403
|
+
if (!spanCtx) return fn();
|
|
1404
|
+
const otelCtxWithSpan = trace.setSpan(context.active(), span);
|
|
1405
|
+
return toolContext.run(spanCtx, () => context.with(otelCtxWithSpan, fn));
|
|
1406
|
+
}
|
|
1407
|
+
__name(runInToolSpanContext, "runInToolSpanContext");
|
|
1408
|
+
function endToolSpan(span, metadata) {
|
|
1409
|
+
const spanId = getSpanId(span);
|
|
1410
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
1411
|
+
if (!spanCtx) return;
|
|
1412
|
+
if (spanCtx.ended) {
|
|
1413
|
+
debugLogger2.debug(
|
|
1414
|
+
`endToolSpan: span ${spanId} already ended (possible TTL sweep race)`
|
|
1415
|
+
);
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
spanCtx.ended = true;
|
|
1419
|
+
try {
|
|
1420
|
+
const duration = Date.now() - spanCtx.startTime;
|
|
1421
|
+
const endAttributes = { duration_ms: duration };
|
|
1422
|
+
if (metadata) {
|
|
1423
|
+
if (metadata.success !== void 0)
|
|
1424
|
+
endAttributes["success"] = metadata.success;
|
|
1425
|
+
if (metadata.error !== void 0)
|
|
1426
|
+
endAttributes["error"] = truncateSpanError(metadata.error);
|
|
1427
|
+
}
|
|
1428
|
+
spanCtx.span.setAttributes(endAttributes);
|
|
1429
|
+
if (metadata) {
|
|
1430
|
+
if (metadata.success !== false) {
|
|
1431
|
+
spanCtx.span.setStatus({ code: SpanStatusCode.OK });
|
|
1432
|
+
} else {
|
|
1433
|
+
spanCtx.span.setStatus({
|
|
1434
|
+
code: SpanStatusCode.ERROR,
|
|
1435
|
+
message: metadata.error ? truncateSpanError(metadata.error) : "tool error"
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
} catch (error) {
|
|
1440
|
+
debugLogger2.warn(
|
|
1441
|
+
`Failed to update tool span attributes/status: ${error instanceof Error ? error.message : String(error)}`
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
try {
|
|
1445
|
+
spanCtx.span.end();
|
|
1446
|
+
} catch (error) {
|
|
1447
|
+
debugLogger2.warn(
|
|
1448
|
+
`Failed to end tool span: ${error instanceof Error ? error.message : String(error)}`
|
|
1449
|
+
);
|
|
1450
|
+
}
|
|
1451
|
+
activeSpans.delete(spanId);
|
|
1452
|
+
strongSpans.delete(spanId);
|
|
1453
|
+
}
|
|
1454
|
+
__name(endToolSpan, "endToolSpan");
|
|
1455
|
+
function startToolExecutionSpan() {
|
|
1456
|
+
if (!isTelemetrySdkInitialized()) {
|
|
1457
|
+
return NOOP_SPAN;
|
|
1458
|
+
}
|
|
1459
|
+
const parentCtx = toolContext.getStore();
|
|
1460
|
+
if (!parentCtx) {
|
|
1461
|
+
debugLogger2.warn(
|
|
1462
|
+
"startToolExecutionSpan called outside runInToolSpanContext \u2014 span will not be parented to tool span"
|
|
1463
|
+
);
|
|
1464
|
+
}
|
|
1465
|
+
const ctx = resolveParentContext(parentCtx);
|
|
1466
|
+
const sessionId = resolveSessionId(
|
|
1467
|
+
parentCtx ?? interactionContext.getStore()
|
|
1468
|
+
);
|
|
1469
|
+
const span = getTracer().startSpan(
|
|
1470
|
+
SPAN_TOOL_EXECUTION,
|
|
1471
|
+
{
|
|
1472
|
+
kind: SpanKind.INTERNAL,
|
|
1473
|
+
attributes: sessionId ? { "session.id": sessionId } : {}
|
|
1474
|
+
},
|
|
1475
|
+
ctx
|
|
1476
|
+
);
|
|
1477
|
+
const spanId = getSpanId(span);
|
|
1478
|
+
const spanContextObj = {
|
|
1479
|
+
span,
|
|
1480
|
+
startTime: Date.now(),
|
|
1481
|
+
attributes: sessionId ? { "session.id": sessionId } : {},
|
|
1482
|
+
type: "tool.execution"
|
|
1483
|
+
};
|
|
1484
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
1485
|
+
strongSpans.set(spanId, spanContextObj);
|
|
1486
|
+
return span;
|
|
1487
|
+
}
|
|
1488
|
+
__name(startToolExecutionSpan, "startToolExecutionSpan");
|
|
1489
|
+
function endToolExecutionSpan(span, metadata) {
|
|
1490
|
+
const spanId = getSpanId(span);
|
|
1491
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
1492
|
+
if (!spanCtx) return;
|
|
1493
|
+
if (spanCtx.ended) {
|
|
1494
|
+
debugLogger2.debug(
|
|
1495
|
+
`endToolExecutionSpan: span ${spanId} already ended (possible TTL sweep race)`
|
|
1496
|
+
);
|
|
1497
|
+
return;
|
|
1498
|
+
}
|
|
1499
|
+
spanCtx.ended = true;
|
|
1500
|
+
try {
|
|
1501
|
+
const duration = Date.now() - spanCtx.startTime;
|
|
1502
|
+
const endAttributes = {};
|
|
1503
|
+
if (metadata?.attributes) {
|
|
1504
|
+
Object.assign(endAttributes, metadata.attributes);
|
|
1505
|
+
}
|
|
1506
|
+
endAttributes["duration_ms"] = duration;
|
|
1507
|
+
if (metadata) {
|
|
1508
|
+
if (metadata.success !== void 0)
|
|
1509
|
+
endAttributes["success"] = metadata.success;
|
|
1510
|
+
if (metadata.error !== void 0)
|
|
1511
|
+
endAttributes["error"] = truncateSpanError(metadata.error);
|
|
1512
|
+
}
|
|
1513
|
+
spanCtx.span.setAttributes(endAttributes);
|
|
1514
|
+
if (metadata && !metadata.cancelled) {
|
|
1515
|
+
if (metadata.success !== false) {
|
|
1516
|
+
spanCtx.span.setStatus({ code: SpanStatusCode.OK });
|
|
1517
|
+
} else {
|
|
1518
|
+
spanCtx.span.setStatus({
|
|
1519
|
+
code: SpanStatusCode.ERROR,
|
|
1520
|
+
message: metadata.error ? truncateSpanError(metadata.error) : "tool execution error"
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
} catch (error) {
|
|
1525
|
+
debugLogger2.warn(
|
|
1526
|
+
`Failed to update tool execution span attributes/status: ${error instanceof Error ? error.message : String(error)}`
|
|
1527
|
+
);
|
|
1528
|
+
}
|
|
1529
|
+
try {
|
|
1530
|
+
spanCtx.span.end();
|
|
1531
|
+
} catch (error) {
|
|
1532
|
+
debugLogger2.warn(
|
|
1533
|
+
`Failed to end tool execution span: ${error instanceof Error ? error.message : String(error)}`
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1536
|
+
activeSpans.delete(spanId);
|
|
1537
|
+
strongSpans.delete(spanId);
|
|
1538
|
+
}
|
|
1539
|
+
__name(endToolExecutionSpan, "endToolExecutionSpan");
|
|
1540
|
+
function startToolBlockedOnUserSpan(toolSpan, attrs) {
|
|
1541
|
+
if (!isTelemetrySdkInitialized()) {
|
|
1542
|
+
return NOOP_SPAN;
|
|
1543
|
+
}
|
|
1544
|
+
ensureCleanupInterval();
|
|
1545
|
+
const parentSpanId = getSpanId(toolSpan);
|
|
1546
|
+
const parentSpanCtx = activeSpans.get(parentSpanId)?.deref();
|
|
1547
|
+
if (!parentSpanCtx) {
|
|
1548
|
+
debugLogger2.debug(
|
|
1549
|
+
"startToolBlockedOnUserSpan: tool span not in activeSpans (already ended?) \u2014 using resolveParentContext fallback"
|
|
1550
|
+
);
|
|
1551
|
+
}
|
|
1552
|
+
const ctx = parentSpanCtx ? trace.setSpan(context.active(), parentSpanCtx.span) : resolveParentContext(void 0);
|
|
1553
|
+
const sessionParentCtx = parentSpanCtx ?? subagentContext.getStore() ?? interactionContext.getStore() ?? void 0;
|
|
1554
|
+
const sessionId = resolveSessionId(sessionParentCtx);
|
|
1555
|
+
const attributes = {
|
|
1556
|
+
...sessionId ? { "session.id": sessionId } : {}
|
|
1557
|
+
};
|
|
1558
|
+
if (attrs?.tool_name !== void 0) attributes["tool.name"] = attrs.tool_name;
|
|
1559
|
+
if (attrs?.call_id !== void 0) attributes["tool.call_id"] = attrs.call_id;
|
|
1560
|
+
const span = getTracer().startSpan(
|
|
1561
|
+
SPAN_TOOL_BLOCKED_ON_USER,
|
|
1562
|
+
{ kind: SpanKind.INTERNAL, attributes },
|
|
1563
|
+
ctx
|
|
1564
|
+
);
|
|
1565
|
+
const spanId = getSpanId(span);
|
|
1566
|
+
const spanContextObj = {
|
|
1567
|
+
span,
|
|
1568
|
+
startTime: Date.now(),
|
|
1569
|
+
attributes,
|
|
1570
|
+
type: "tool.blocked_on_user"
|
|
1571
|
+
};
|
|
1572
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
1573
|
+
strongSpans.set(spanId, spanContextObj);
|
|
1574
|
+
return span;
|
|
1575
|
+
}
|
|
1576
|
+
__name(startToolBlockedOnUserSpan, "startToolBlockedOnUserSpan");
|
|
1577
|
+
function endToolBlockedOnUserSpan(span, metadata) {
|
|
1578
|
+
const spanId = getSpanId(span);
|
|
1579
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
1580
|
+
if (!spanCtx) return;
|
|
1581
|
+
if (spanCtx.ended) {
|
|
1582
|
+
debugLogger2.debug(
|
|
1583
|
+
`endToolBlockedOnUserSpan: span ${spanId} already ended (possible TTL sweep race)`
|
|
1584
|
+
);
|
|
1585
|
+
return;
|
|
1586
|
+
}
|
|
1587
|
+
spanCtx.ended = true;
|
|
1588
|
+
try {
|
|
1589
|
+
const duration = Date.now() - spanCtx.startTime;
|
|
1590
|
+
const endAttributes = { duration_ms: duration };
|
|
1591
|
+
if (metadata?.decision !== void 0)
|
|
1592
|
+
endAttributes["decision"] = metadata.decision;
|
|
1593
|
+
if (metadata?.source !== void 0)
|
|
1594
|
+
endAttributes["source"] = metadata.source;
|
|
1595
|
+
spanCtx.span.setAttributes(endAttributes);
|
|
1596
|
+
} catch (error) {
|
|
1597
|
+
debugLogger2.warn(
|
|
1598
|
+
`Failed to update blocked_on_user span attributes: ${error instanceof Error ? error.message : String(error)}`
|
|
1599
|
+
);
|
|
1600
|
+
}
|
|
1601
|
+
try {
|
|
1602
|
+
spanCtx.span.end();
|
|
1603
|
+
} catch (error) {
|
|
1604
|
+
debugLogger2.warn(
|
|
1605
|
+
`Failed to end blocked_on_user span: ${error instanceof Error ? error.message : String(error)}`
|
|
1606
|
+
);
|
|
1607
|
+
}
|
|
1608
|
+
activeSpans.delete(spanId);
|
|
1609
|
+
strongSpans.delete(spanId);
|
|
1610
|
+
}
|
|
1611
|
+
__name(endToolBlockedOnUserSpan, "endToolBlockedOnUserSpan");
|
|
1612
|
+
function startHookSpan(opts) {
|
|
1613
|
+
if (!isTelemetrySdkInitialized()) {
|
|
1614
|
+
return NOOP_SPAN;
|
|
1615
|
+
}
|
|
1616
|
+
ensureCleanupInterval();
|
|
1617
|
+
const parentCtx = toolContext.getStore() ?? subagentContext.getStore() ?? interactionContext.getStore() ?? void 0;
|
|
1618
|
+
const ctx = resolveParentContext(parentCtx);
|
|
1619
|
+
const sessionId = resolveSessionId(parentCtx);
|
|
1620
|
+
const attributes = {
|
|
1621
|
+
...sessionId ? { "session.id": sessionId } : {},
|
|
1622
|
+
hook_event: opts.hookEvent,
|
|
1623
|
+
"tool.name": opts.toolName
|
|
1624
|
+
};
|
|
1625
|
+
if (opts.toolUseId !== void 0) attributes["tool.use_id"] = opts.toolUseId;
|
|
1626
|
+
if (opts.isInterrupt !== void 0)
|
|
1627
|
+
attributes["is_interrupt"] = opts.isInterrupt;
|
|
1628
|
+
const span = getTracer().startSpan(
|
|
1629
|
+
SPAN_HOOK,
|
|
1630
|
+
{ kind: SpanKind.INTERNAL, attributes },
|
|
1631
|
+
ctx
|
|
1632
|
+
);
|
|
1633
|
+
const spanId = getSpanId(span);
|
|
1634
|
+
const spanContextObj = {
|
|
1635
|
+
span,
|
|
1636
|
+
startTime: Date.now(),
|
|
1637
|
+
attributes,
|
|
1638
|
+
type: "hook"
|
|
1639
|
+
};
|
|
1640
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
1641
|
+
strongSpans.set(spanId, spanContextObj);
|
|
1642
|
+
return span;
|
|
1643
|
+
}
|
|
1644
|
+
__name(startHookSpan, "startHookSpan");
|
|
1645
|
+
function endHookSpan(span, metadata) {
|
|
1646
|
+
const spanId = getSpanId(span);
|
|
1647
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
1648
|
+
if (!spanCtx) return;
|
|
1649
|
+
if (spanCtx.ended) {
|
|
1650
|
+
debugLogger2.debug(
|
|
1651
|
+
`endHookSpan: span ${spanId} already ended (possible TTL sweep race)`
|
|
1652
|
+
);
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1655
|
+
spanCtx.ended = true;
|
|
1656
|
+
try {
|
|
1657
|
+
const duration = Date.now() - spanCtx.startTime;
|
|
1658
|
+
const endAttributes = { duration_ms: duration };
|
|
1659
|
+
if (metadata) {
|
|
1660
|
+
if (metadata.success !== void 0)
|
|
1661
|
+
endAttributes["success"] = metadata.success;
|
|
1662
|
+
if (metadata.shouldProceed !== void 0)
|
|
1663
|
+
endAttributes["should_proceed"] = metadata.shouldProceed;
|
|
1664
|
+
if (metadata.shouldStop !== void 0)
|
|
1665
|
+
endAttributes["should_stop"] = metadata.shouldStop;
|
|
1666
|
+
if (metadata.blockType !== void 0)
|
|
1667
|
+
endAttributes["block_type"] = metadata.blockType;
|
|
1668
|
+
if (metadata.hasAdditionalContext !== void 0)
|
|
1669
|
+
endAttributes["has_additional_context"] = metadata.hasAdditionalContext;
|
|
1670
|
+
if (metadata.postBatchStop !== void 0)
|
|
1671
|
+
endAttributes["post_batch_stop"] = metadata.postBatchStop;
|
|
1672
|
+
if (metadata.postBatchStopReason !== void 0)
|
|
1673
|
+
endAttributes["post_batch_stop_reason"] = truncateSpanError(
|
|
1674
|
+
metadata.postBatchStopReason
|
|
1675
|
+
);
|
|
1676
|
+
if (metadata.error !== void 0)
|
|
1677
|
+
endAttributes["error"] = truncateSpanError(metadata.error);
|
|
1678
|
+
}
|
|
1679
|
+
spanCtx.span.setAttributes(endAttributes);
|
|
1680
|
+
if (metadata?.error !== void 0) {
|
|
1681
|
+
spanCtx.span.setStatus({
|
|
1682
|
+
code: SpanStatusCode.ERROR,
|
|
1683
|
+
message: truncateSpanError(metadata.error)
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
} catch (error) {
|
|
1687
|
+
debugLogger2.warn(
|
|
1688
|
+
`Failed to update hook span attributes/status: ${error instanceof Error ? error.message : String(error)}`
|
|
1689
|
+
);
|
|
1690
|
+
}
|
|
1691
|
+
try {
|
|
1692
|
+
spanCtx.span.end();
|
|
1693
|
+
} catch (error) {
|
|
1694
|
+
debugLogger2.warn(
|
|
1695
|
+
`Failed to end hook span: ${error instanceof Error ? error.message : String(error)}`
|
|
1696
|
+
);
|
|
1697
|
+
}
|
|
1698
|
+
activeSpans.delete(spanId);
|
|
1699
|
+
strongSpans.delete(spanId);
|
|
1700
|
+
}
|
|
1701
|
+
__name(endHookSpan, "endHookSpan");
|
|
1702
|
+
function startSubagentSpan(opts) {
|
|
1703
|
+
if (!isTelemetrySdkInitialized()) return NOOP_SPAN;
|
|
1704
|
+
ensureCleanupInterval();
|
|
1705
|
+
const attributes = {
|
|
1706
|
+
// Spec-aligned (OTel GenAI Agent Spans, Development status).
|
|
1707
|
+
"gen_ai.operation.name": "invoke_agent",
|
|
1708
|
+
"gen_ai.agent.name": opts.subagentName,
|
|
1709
|
+
"gen_ai.conversation.id": opts.sessionId,
|
|
1710
|
+
// Vendor identity and lifecycle. The per-invocation ID stays private;
|
|
1711
|
+
// gen_ai.agent.id is reserved for a stable agent definition identity.
|
|
1712
|
+
"qwen-code.subagent.id": opts.agentId,
|
|
1713
|
+
"qwen-code.subagent.name": opts.subagentName,
|
|
1714
|
+
"qwen-code.subagent.invocation_kind": opts.invocationKind,
|
|
1715
|
+
"qwen-code.subagent.is_built_in": opts.isBuiltIn,
|
|
1716
|
+
"qwen-code.subagent.depth": opts.depth
|
|
1717
|
+
};
|
|
1718
|
+
if (opts.agentDescription !== void 0) {
|
|
1719
|
+
attributes["gen_ai.agent.description"] = truncateSpanText(
|
|
1720
|
+
opts.agentDescription
|
|
1721
|
+
);
|
|
1722
|
+
}
|
|
1723
|
+
if (opts.modelOverride !== void 0) {
|
|
1724
|
+
attributes["gen_ai.request.model"] = opts.modelOverride;
|
|
1725
|
+
}
|
|
1726
|
+
if (opts.parentAgentId !== void 0) {
|
|
1727
|
+
attributes["qwen-code.subagent.parent_agent_id"] = opts.parentAgentId;
|
|
1728
|
+
}
|
|
1729
|
+
if (opts.invokingRequestId !== void 0) {
|
|
1730
|
+
attributes["qwen-code.subagent.invoking_request_id"] = opts.invokingRequestId;
|
|
1731
|
+
}
|
|
1732
|
+
const tracer2 = getTracer();
|
|
1733
|
+
let span;
|
|
1734
|
+
if (opts.invocationKind === "foreground") {
|
|
1735
|
+
span = tracer2.startSpan(SPAN_SUBAGENT, {
|
|
1736
|
+
kind: SpanKind.INTERNAL,
|
|
1737
|
+
attributes
|
|
1738
|
+
});
|
|
1739
|
+
} else {
|
|
1740
|
+
span = tracer2.startSpan(SPAN_SUBAGENT, {
|
|
1741
|
+
kind: SpanKind.INTERNAL,
|
|
1742
|
+
attributes,
|
|
1743
|
+
root: true,
|
|
1744
|
+
links: opts.invokerSpanContext ? [
|
|
1745
|
+
{
|
|
1746
|
+
context: opts.invokerSpanContext,
|
|
1747
|
+
attributes: { "qwen-code.link.kind": "invoker" }
|
|
1748
|
+
}
|
|
1749
|
+
] : void 0
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
const spanId = getSpanId(span);
|
|
1753
|
+
const spanContextObj = {
|
|
1754
|
+
span,
|
|
1755
|
+
startTime: Date.now(),
|
|
1756
|
+
attributes,
|
|
1757
|
+
type: "subagent"
|
|
1758
|
+
};
|
|
1759
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
1760
|
+
strongSpans.set(spanId, spanContextObj);
|
|
1761
|
+
return span;
|
|
1762
|
+
}
|
|
1763
|
+
__name(startSubagentSpan, "startSubagentSpan");
|
|
1764
|
+
function runInSubagentSpanContext(span, fn) {
|
|
1765
|
+
const spanId = getSpanId(span);
|
|
1766
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
1767
|
+
if (!spanCtx) return fn();
|
|
1768
|
+
const otelCtxWithSpan = trace.setSpan(context.active(), span);
|
|
1769
|
+
return subagentContext.run(
|
|
1770
|
+
spanCtx,
|
|
1771
|
+
() => toolContext.run(void 0, () => context.with(otelCtxWithSpan, fn))
|
|
1772
|
+
);
|
|
1773
|
+
}
|
|
1774
|
+
__name(runInSubagentSpanContext, "runInSubagentSpanContext");
|
|
1775
|
+
function endSubagentSpan(span, metadata) {
|
|
1776
|
+
const spanId = getSpanId(span);
|
|
1777
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
1778
|
+
if (!spanCtx) {
|
|
1779
|
+
if (isTelemetrySdkInitialized()) {
|
|
1780
|
+
debugLogger2.warn(
|
|
1781
|
+
`endSubagentSpan: span ${spanId} not found in activeSpans (already swept?) \u2014 intended status=${metadata.status}, reason=${metadata.terminateReason ?? "none"}`
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1784
|
+
return;
|
|
1785
|
+
}
|
|
1786
|
+
if (spanCtx.ended) {
|
|
1787
|
+
debugLogger2.warn(
|
|
1788
|
+
`endSubagentSpan: span ${spanId} already ended \u2014 intended status=${metadata.status}, reason=${metadata.terminateReason ?? "none"} (possible TTL sweep race)`
|
|
1789
|
+
);
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
spanCtx.ended = true;
|
|
1793
|
+
try {
|
|
1794
|
+
const duration = Date.now() - spanCtx.startTime;
|
|
1795
|
+
const endAttributes = {
|
|
1796
|
+
duration_ms: duration,
|
|
1797
|
+
"qwen-code.subagent.duration_ms": duration,
|
|
1798
|
+
"qwen-code.subagent.status": metadata.status
|
|
1799
|
+
};
|
|
1800
|
+
if (metadata.terminateReason !== void 0) {
|
|
1801
|
+
endAttributes["qwen-code.subagent.terminate_reason"] = metadata.terminateReason;
|
|
1802
|
+
}
|
|
1803
|
+
if (metadata.resultSummaryPresent !== void 0) {
|
|
1804
|
+
endAttributes["qwen-code.subagent.result_summary_present"] = metadata.resultSummaryPresent;
|
|
1805
|
+
}
|
|
1806
|
+
if (metadata.error !== void 0) {
|
|
1807
|
+
const truncated = truncateSpanError(metadata.error);
|
|
1808
|
+
endAttributes["exception.message"] = truncated;
|
|
1809
|
+
}
|
|
1810
|
+
if (metadata.errorType !== void 0) {
|
|
1811
|
+
endAttributes["error.type"] = metadata.errorType;
|
|
1812
|
+
}
|
|
1813
|
+
spanCtx.span.setAttributes(endAttributes);
|
|
1814
|
+
if (metadata.status === "completed") {
|
|
1815
|
+
spanCtx.span.setStatus({ code: SpanStatusCode.OK });
|
|
1816
|
+
} else if (metadata.status === "failed") {
|
|
1817
|
+
spanCtx.span.setStatus({
|
|
1818
|
+
code: SpanStatusCode.ERROR,
|
|
1819
|
+
message: metadata.error ? truncateSpanError(metadata.error) : "subagent failed"
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
} catch (error) {
|
|
1823
|
+
debugLogger2.warn(
|
|
1824
|
+
`Failed to update subagent span attributes/status: ${error instanceof Error ? error.message : String(error)}`
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
try {
|
|
1828
|
+
spanCtx.span.end();
|
|
1829
|
+
} catch (error) {
|
|
1830
|
+
debugLogger2.warn(
|
|
1831
|
+
`Failed to end subagent span: ${error instanceof Error ? error.message : String(error)}`
|
|
1832
|
+
);
|
|
1833
|
+
}
|
|
1834
|
+
activeSpans.delete(spanId);
|
|
1835
|
+
strongSpans.delete(spanId);
|
|
1836
|
+
}
|
|
1837
|
+
__name(endSubagentSpan, "endSubagentSpan");
|
|
1838
|
+
function getActiveInteractionSpan() {
|
|
1839
|
+
const ctx = interactionContext.getStore() ?? lastInteractionCtx;
|
|
1840
|
+
if (!ctx || ctx.ended) return void 0;
|
|
1841
|
+
return ctx.span;
|
|
1842
|
+
}
|
|
1843
|
+
__name(getActiveInteractionSpan, "getActiveInteractionSpan");
|
|
1844
|
+
|
|
1845
|
+
// packages/core/src/telemetry/sdk.ts
|
|
1846
|
+
function createTelemetryDiagLogger() {
|
|
1847
|
+
const debugLogger3 = createDebugLogger("OTEL");
|
|
1848
|
+
return {
|
|
1849
|
+
error: /* @__PURE__ */ __name((message, ...args) => debugLogger3.error(message, ...args), "error"),
|
|
1850
|
+
warn: /* @__PURE__ */ __name((message, ...args) => debugLogger3.warn(message, ...args), "warn"),
|
|
1851
|
+
info: /* @__PURE__ */ __name((message, ...args) => debugLogger3.info(message, ...args), "info"),
|
|
1852
|
+
debug: /* @__PURE__ */ __name((message, ...args) => debugLogger3.debug(message, ...args), "debug"),
|
|
1853
|
+
verbose: /* @__PURE__ */ __name((message, ...args) => debugLogger3.debug(message, ...args), "verbose")
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
__name(createTelemetryDiagLogger, "createTelemetryDiagLogger");
|
|
1857
|
+
diag.setLogger(createTelemetryDiagLogger(), DiagLogLevel.WARN);
|
|
1858
|
+
var SHUTDOWN_TIMEOUT_MS = 1e4;
|
|
1859
|
+
var sdk;
|
|
1860
|
+
var telemetryInitialized = false;
|
|
1861
|
+
var telemetryInitPromise;
|
|
1862
|
+
var telemetryShutdownPromise;
|
|
1863
|
+
var activeMetricReader;
|
|
1864
|
+
function isTelemetrySdkInitialized() {
|
|
1865
|
+
return telemetryInitialized;
|
|
1866
|
+
}
|
|
1867
|
+
__name(isTelemetrySdkInitialized, "isTelemetrySdkInitialized");
|
|
1868
|
+
function initializeTelemetry(config) {
|
|
1869
|
+
if (telemetryInitialized || !config.getTelemetryEnabled()) {
|
|
1870
|
+
return Promise.resolve();
|
|
1871
|
+
}
|
|
1872
|
+
telemetryInitPromise ??= (async () => {
|
|
1873
|
+
const debugLogger3 = createDebugLogger("OTEL");
|
|
1874
|
+
try {
|
|
1875
|
+
const { startTelemetrySdk } = await import("./sdk-impl-TLQOC7P4.js");
|
|
1876
|
+
if (telemetryInitialized) return;
|
|
1877
|
+
const started = await startTelemetrySdk(config);
|
|
1878
|
+
if (!started) return;
|
|
1879
|
+
sdk = started.sdk;
|
|
1880
|
+
sdk.start();
|
|
1881
|
+
debugLogger3.debug("OpenTelemetry SDK started successfully.");
|
|
1882
|
+
telemetryInitialized = true;
|
|
1883
|
+
activeMetricReader = started.metricReader;
|
|
1884
|
+
const sessionId = config.getSessionId();
|
|
1885
|
+
setSessionContext(createSessionRootContext(sessionId), sessionId);
|
|
1886
|
+
setShellTracePropagation(
|
|
1887
|
+
config.getOutboundCorrelationPropagateTraceContext()
|
|
1888
|
+
);
|
|
1889
|
+
initializeMetrics(config);
|
|
1890
|
+
} catch (error) {
|
|
1891
|
+
debugLogger3.error("Error starting OpenTelemetry SDK:", error);
|
|
1892
|
+
}
|
|
1893
|
+
})().finally(() => {
|
|
1894
|
+
telemetryInitPromise = void 0;
|
|
1895
|
+
});
|
|
1896
|
+
return telemetryInitPromise;
|
|
1897
|
+
}
|
|
1898
|
+
__name(initializeTelemetry, "initializeTelemetry");
|
|
1899
|
+
function refreshSessionContext(sessionId) {
|
|
1900
|
+
if (!telemetryInitialized) return;
|
|
1901
|
+
try {
|
|
1902
|
+
setSessionContext(createSessionRootContext(sessionId), sessionId);
|
|
1903
|
+
} catch (error) {
|
|
1904
|
+
createDebugLogger("OTEL").warn("Failed to refresh session context:", error);
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
__name(refreshSessionContext, "refreshSessionContext");
|
|
1908
|
+
function shutdownTelemetry() {
|
|
1909
|
+
if (telemetryShutdownPromise) {
|
|
1910
|
+
return telemetryShutdownPromise;
|
|
1911
|
+
}
|
|
1912
|
+
const pendingInit = telemetryInitPromise;
|
|
1913
|
+
if (!pendingInit && (!telemetryInitialized || !sdk)) {
|
|
1914
|
+
return Promise.resolve();
|
|
1915
|
+
}
|
|
1916
|
+
telemetryShutdownPromise = (async () => {
|
|
1917
|
+
if (pendingInit) {
|
|
1918
|
+
await pendingInit.catch(() => {
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
if (!telemetryInitialized || !sdk) {
|
|
1922
|
+
telemetryShutdownPromise = void 0;
|
|
1923
|
+
return;
|
|
1924
|
+
}
|
|
1925
|
+
endInteractionSpan("cancelled");
|
|
1926
|
+
const currentSdk = sdk;
|
|
1927
|
+
const debugLogger3 = createDebugLogger("OTEL");
|
|
1928
|
+
let timer;
|
|
1929
|
+
let timedOut = false;
|
|
1930
|
+
try {
|
|
1931
|
+
const sdkShutdown = Promise.resolve(currentSdk.shutdown());
|
|
1932
|
+
sdkShutdown.catch((err) => {
|
|
1933
|
+
if (timedOut) {
|
|
1934
|
+
debugLogger3.warn(
|
|
1935
|
+
"SDK shutdown rejected after timeout:",
|
|
1936
|
+
err instanceof Error ? err.message : err
|
|
1937
|
+
);
|
|
1938
|
+
}
|
|
1939
|
+
});
|
|
1940
|
+
const timeout = new Promise((resolve) => {
|
|
1941
|
+
timer = setTimeout(() => {
|
|
1942
|
+
timedOut = true;
|
|
1943
|
+
resolve("timeout");
|
|
1944
|
+
}, SHUTDOWN_TIMEOUT_MS);
|
|
1945
|
+
timer.unref?.();
|
|
1946
|
+
});
|
|
1947
|
+
const result = await Promise.race([sdkShutdown, timeout]);
|
|
1948
|
+
clearTimeout(timer);
|
|
1949
|
+
if (result === "timeout") {
|
|
1950
|
+
const msg = `Telemetry shutdown timed out after ${SHUTDOWN_TIMEOUT_MS}ms.`;
|
|
1951
|
+
diag.warn(msg);
|
|
1952
|
+
debugLogger3.warn(msg);
|
|
1953
|
+
} else {
|
|
1954
|
+
debugLogger3.debug("OpenTelemetry SDK shut down successfully.");
|
|
1955
|
+
}
|
|
1956
|
+
} catch (error) {
|
|
1957
|
+
clearTimeout(timer);
|
|
1958
|
+
diag.error("Error shutting down SDK:", error);
|
|
1959
|
+
debugLogger3.error("Error shutting down SDK:", error);
|
|
1960
|
+
} finally {
|
|
1961
|
+
telemetryInitialized = false;
|
|
1962
|
+
sdk = void 0;
|
|
1963
|
+
activeMetricReader = void 0;
|
|
1964
|
+
telemetryShutdownPromise = void 0;
|
|
1965
|
+
setSessionContext(void 0);
|
|
1966
|
+
setShellTracePropagation(false);
|
|
1967
|
+
}
|
|
1968
|
+
})();
|
|
1969
|
+
return telemetryShutdownPromise;
|
|
1970
|
+
}
|
|
1971
|
+
__name(shutdownTelemetry, "shutdownTelemetry");
|
|
1972
|
+
var FORCE_FLUSH_TIMEOUT_MS = 2e3;
|
|
1973
|
+
async function forceFlushMetrics() {
|
|
1974
|
+
if (!telemetryInitialized || !activeMetricReader) return;
|
|
1975
|
+
const flush = activeMetricReader.forceFlush();
|
|
1976
|
+
flush.catch(() => {
|
|
1977
|
+
});
|
|
1978
|
+
let timer;
|
|
1979
|
+
const timeout = new Promise((_, reject) => {
|
|
1980
|
+
timer = setTimeout(
|
|
1981
|
+
() => reject(
|
|
1982
|
+
new Error(
|
|
1983
|
+
`forceFlushMetrics timed out after ${FORCE_FLUSH_TIMEOUT_MS}ms`
|
|
1984
|
+
)
|
|
1985
|
+
),
|
|
1986
|
+
FORCE_FLUSH_TIMEOUT_MS
|
|
1987
|
+
);
|
|
1988
|
+
timer.unref?.();
|
|
1989
|
+
});
|
|
1990
|
+
try {
|
|
1991
|
+
await Promise.race([flush, timeout]);
|
|
1992
|
+
} finally {
|
|
1993
|
+
clearTimeout(timer);
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
__name(forceFlushMetrics, "forceFlushMetrics");
|
|
1997
|
+
|
|
1998
|
+
// packages/core/src/telemetry/detailed-span-attributes.ts
|
|
1999
|
+
var SYSTEM_PROMPT_PREVIEW_LENGTH = 500;
|
|
2000
|
+
var SHORT_TRUNCATION_SUFFIX = "...[TRUNCATED]";
|
|
2001
|
+
var seenHashes = /* @__PURE__ */ new Set();
|
|
2002
|
+
function areSensitiveSpanAttributesEnabled(config) {
|
|
2003
|
+
return isTelemetrySdkInitialized() && config.getTelemetryIncludeSensitiveSpanAttributes();
|
|
2004
|
+
}
|
|
2005
|
+
__name(areSensitiveSpanAttributesEnabled, "areSensitiveSpanAttributesEnabled");
|
|
2006
|
+
function truncateContent(content, maxSize = DEFAULT_SENSITIVE_SPAN_ATTRIBUTE_MAX_LENGTH, originalLength = content.length) {
|
|
2007
|
+
if (!Number.isSafeInteger(maxSize) || maxSize < 1) {
|
|
2008
|
+
throw new TypeError(
|
|
2009
|
+
`maxSize must be a positive safe integer, got ${String(maxSize)}`
|
|
2010
|
+
);
|
|
2011
|
+
}
|
|
2012
|
+
if (!Number.isSafeInteger(originalLength) || originalLength < 0) {
|
|
2013
|
+
throw new TypeError(
|
|
2014
|
+
`originalLength must be a non-negative safe integer, got ${String(
|
|
2015
|
+
originalLength
|
|
2016
|
+
)}`
|
|
2017
|
+
);
|
|
2018
|
+
}
|
|
2019
|
+
if (originalLength < content.length) {
|
|
2020
|
+
throw new TypeError(
|
|
2021
|
+
`originalLength must be greater than or equal to content length, got ${originalLength} for content length ${content.length}`
|
|
2022
|
+
);
|
|
2023
|
+
}
|
|
2024
|
+
if (originalLength <= maxSize && content.length <= maxSize) {
|
|
2025
|
+
return { content, truncated: false };
|
|
2026
|
+
}
|
|
2027
|
+
if (originalLength > content.length && content.length <= maxSize) {
|
|
2028
|
+
return { content, truncated: true };
|
|
2029
|
+
}
|
|
2030
|
+
const suffix = `
|
|
2031
|
+
|
|
2032
|
+
[TRUNCATED - Content exceeds configured limit of ${maxSize} characters]`;
|
|
2033
|
+
if (suffix.length >= maxSize) {
|
|
2034
|
+
if (SHORT_TRUNCATION_SUFFIX.length >= maxSize) {
|
|
2035
|
+
return {
|
|
2036
|
+
content: SHORT_TRUNCATION_SUFFIX.slice(0, maxSize),
|
|
2037
|
+
truncated: true
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
return {
|
|
2041
|
+
content: content.slice(0, maxSize - SHORT_TRUNCATION_SUFFIX.length) + SHORT_TRUNCATION_SUFFIX,
|
|
2042
|
+
truncated: true
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
return {
|
|
2046
|
+
content: content.slice(0, maxSize - suffix.length) + suffix,
|
|
2047
|
+
truncated: true
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
__name(truncateContent, "truncateContent");
|
|
2051
|
+
function getMaxContentSize(config) {
|
|
2052
|
+
return config.getTelemetrySensitiveSpanAttributeMaxLength();
|
|
2053
|
+
}
|
|
2054
|
+
__name(getMaxContentSize, "getMaxContentSize");
|
|
2055
|
+
function truncatePrefixedContent(prefix, content, maxSize) {
|
|
2056
|
+
const prefixedContent = `${prefix}${content}`;
|
|
2057
|
+
const result = truncateContent(prefixedContent, maxSize);
|
|
2058
|
+
return {
|
|
2059
|
+
...result,
|
|
2060
|
+
originalLength: content.length
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
__name(truncatePrefixedContent, "truncatePrefixedContent");
|
|
2064
|
+
function shortHash(content) {
|
|
2065
|
+
return createHash2("sha256").update(content).digest("hex").slice(0, 12);
|
|
2066
|
+
}
|
|
2067
|
+
__name(shortHash, "shortHash");
|
|
2068
|
+
function stringifyContentUnion(value) {
|
|
2069
|
+
if (typeof value === "string") return value;
|
|
2070
|
+
return safeJsonStringify(value) ?? "";
|
|
2071
|
+
}
|
|
2072
|
+
__name(stringifyContentUnion, "stringifyContentUnion");
|
|
2073
|
+
function addUserPromptAttributes(config, span, promptText) {
|
|
2074
|
+
if (!areSensitiveSpanAttributesEnabled(config) || !promptText) return;
|
|
2075
|
+
const { content, truncated, originalLength } = truncatePrefixedContent(
|
|
2076
|
+
`[USER PROMPT]
|
|
2077
|
+
`,
|
|
2078
|
+
promptText,
|
|
2079
|
+
getMaxContentSize(config)
|
|
2080
|
+
);
|
|
2081
|
+
span.setAttributes({
|
|
2082
|
+
new_context: content,
|
|
2083
|
+
...truncated && {
|
|
2084
|
+
new_context_truncated: true,
|
|
2085
|
+
new_context_original_length: originalLength
|
|
2086
|
+
}
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
__name(addUserPromptAttributes, "addUserPromptAttributes");
|
|
2090
|
+
function addSystemPromptAttributes(config, span, systemInstruction) {
|
|
2091
|
+
if (!areSensitiveSpanAttributesEnabled(config) || !systemInstruction) return;
|
|
2092
|
+
const text = stringifyContentUnion(systemInstruction);
|
|
2093
|
+
if (!text) return;
|
|
2094
|
+
const hash = `sp_${shortHash(text)}`;
|
|
2095
|
+
span.setAttributes({
|
|
2096
|
+
system_prompt_hash: hash,
|
|
2097
|
+
system_prompt_preview: text.slice(0, SYSTEM_PROMPT_PREVIEW_LENGTH),
|
|
2098
|
+
system_prompt_length: text.length
|
|
2099
|
+
});
|
|
2100
|
+
if (!seenHashes.has(hash)) {
|
|
2101
|
+
seenHashes.add(hash);
|
|
2102
|
+
const { content, truncated } = truncateContent(
|
|
2103
|
+
text,
|
|
2104
|
+
getMaxContentSize(config)
|
|
2105
|
+
);
|
|
2106
|
+
span.setAttribute("system_prompt", content);
|
|
2107
|
+
if (truncated) {
|
|
2108
|
+
span.setAttribute("system_prompt_truncated", true);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
__name(addSystemPromptAttributes, "addSystemPromptAttributes");
|
|
2113
|
+
function addToolSchemaAttributes(config, span, tools) {
|
|
2114
|
+
if (!areSensitiveSpanAttributesEnabled(config) || !tools?.length) return;
|
|
2115
|
+
const declarations = [];
|
|
2116
|
+
for (const tool of tools) {
|
|
2117
|
+
const inner = tool["functionDeclarations"];
|
|
2118
|
+
if (Array.isArray(inner)) {
|
|
2119
|
+
declarations.push(...inner);
|
|
2120
|
+
} else {
|
|
2121
|
+
declarations.push(tool);
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
const summary = [];
|
|
2125
|
+
for (const decl of declarations) {
|
|
2126
|
+
const declObj = decl;
|
|
2127
|
+
const name = typeof declObj["name"] === "string" ? declObj["name"] : "unknown_tool";
|
|
2128
|
+
const declJson = safeJsonStringify(decl) ?? `unstringifiable_${name}`;
|
|
2129
|
+
const hash = shortHash(declJson);
|
|
2130
|
+
summary.push({ name, hash });
|
|
2131
|
+
const hashKey = `tool_${hash}`;
|
|
2132
|
+
if (!seenHashes.has(hashKey)) {
|
|
2133
|
+
seenHashes.add(hashKey);
|
|
2134
|
+
const { content, truncated } = truncateContent(
|
|
2135
|
+
declJson,
|
|
2136
|
+
getMaxContentSize(config)
|
|
2137
|
+
);
|
|
2138
|
+
span.addEvent("tool_schema", {
|
|
2139
|
+
tool_name: name,
|
|
2140
|
+
tool_hash: hash,
|
|
2141
|
+
tool_definition: content,
|
|
2142
|
+
...truncated && {
|
|
2143
|
+
tool_definition_truncated: true,
|
|
2144
|
+
tool_definition_original_length: declJson.length
|
|
2145
|
+
}
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
span.setAttributes({
|
|
2150
|
+
tools: safeJsonStringify(summary) ?? "[]",
|
|
2151
|
+
tools_count: summary.length
|
|
2152
|
+
});
|
|
2153
|
+
}
|
|
2154
|
+
__name(addToolSchemaAttributes, "addToolSchemaAttributes");
|
|
2155
|
+
function addModelOutputAttributes(config, span, responseText, originalLength) {
|
|
2156
|
+
if (!areSensitiveSpanAttributesEnabled(config) || !responseText) return;
|
|
2157
|
+
const responseTextOriginalLength = originalLength ?? responseText.length;
|
|
2158
|
+
const { content, truncated } = truncateContent(
|
|
2159
|
+
responseText,
|
|
2160
|
+
getMaxContentSize(config),
|
|
2161
|
+
responseTextOriginalLength
|
|
2162
|
+
);
|
|
2163
|
+
span.setAttributes({
|
|
2164
|
+
"response.model_output": content,
|
|
2165
|
+
...truncated && {
|
|
2166
|
+
"response.model_output_truncated": true,
|
|
2167
|
+
"response.model_output_original_length": responseTextOriginalLength
|
|
2168
|
+
}
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
__name(addModelOutputAttributes, "addModelOutputAttributes");
|
|
2172
|
+
function addToolInputAttributes(config, span, toolName, toolInput) {
|
|
2173
|
+
if (!areSensitiveSpanAttributesEnabled(config)) return;
|
|
2174
|
+
const { content, truncated, originalLength } = truncatePrefixedContent(
|
|
2175
|
+
`[TOOL INPUT: ${toolName}]
|
|
2176
|
+
`,
|
|
2177
|
+
toolInput,
|
|
2178
|
+
getMaxContentSize(config)
|
|
2179
|
+
);
|
|
2180
|
+
span.setAttributes({
|
|
2181
|
+
tool_input: content,
|
|
2182
|
+
...truncated && {
|
|
2183
|
+
tool_input_truncated: true,
|
|
2184
|
+
tool_input_original_length: originalLength
|
|
2185
|
+
}
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
__name(addToolInputAttributes, "addToolInputAttributes");
|
|
2189
|
+
function addToolResultAttributes(config, span, toolName, toolResult) {
|
|
2190
|
+
if (!areSensitiveSpanAttributesEnabled(config)) return;
|
|
2191
|
+
const { content, truncated, originalLength } = truncatePrefixedContent(
|
|
2192
|
+
`[TOOL RESULT: ${toolName}]
|
|
2193
|
+
`,
|
|
2194
|
+
toolResult,
|
|
2195
|
+
getMaxContentSize(config)
|
|
2196
|
+
);
|
|
2197
|
+
span.setAttributes({
|
|
2198
|
+
tool_result: content,
|
|
2199
|
+
...truncated && {
|
|
2200
|
+
tool_result_truncated: true,
|
|
2201
|
+
tool_result_original_length: originalLength
|
|
2202
|
+
}
|
|
2203
|
+
});
|
|
2204
|
+
}
|
|
2205
|
+
__name(addToolResultAttributes, "addToolResultAttributes");
|
|
2206
|
+
function clearDetailedSpanState() {
|
|
2207
|
+
seenHashes.clear();
|
|
2208
|
+
}
|
|
2209
|
+
__name(clearDetailedSpanState, "clearDetailedSpanState");
|
|
2210
|
+
|
|
2211
|
+
export {
|
|
2212
|
+
FileOperation,
|
|
2213
|
+
PerformanceMetricType,
|
|
2214
|
+
MemoryMetricType,
|
|
2215
|
+
ToolExecutionPhase,
|
|
2216
|
+
ApiRequestPhase,
|
|
2217
|
+
getMeter,
|
|
2218
|
+
recordChatCompressionMetrics,
|
|
2219
|
+
recordToolCallMetrics,
|
|
2220
|
+
recordTokenUsageMetrics,
|
|
2221
|
+
recordApiResponseMetrics,
|
|
2222
|
+
recordApiErrorMetrics,
|
|
2223
|
+
recordFileOperationMetric,
|
|
2224
|
+
recordInvalidChunk,
|
|
2225
|
+
recordContentRetry,
|
|
2226
|
+
recordContentRetryFailure,
|
|
2227
|
+
recordApiRetry,
|
|
2228
|
+
recordModelSlashCommand,
|
|
2229
|
+
recordStartupPerformance,
|
|
2230
|
+
recordMemoryUsage,
|
|
2231
|
+
recordCpuUsage,
|
|
2232
|
+
recordToolQueueDepth,
|
|
2233
|
+
recordToolExecutionBreakdown,
|
|
2234
|
+
recordTokenEfficiency,
|
|
2235
|
+
recordApiRequestBreakdown,
|
|
2236
|
+
recordPerformanceScore,
|
|
2237
|
+
recordPerformanceRegression,
|
|
2238
|
+
recordBaselineComparison,
|
|
2239
|
+
isPerformanceMonitoringActive,
|
|
2240
|
+
recordSubagentExecutionMetrics,
|
|
2241
|
+
recordArenaSessionStartedMetrics,
|
|
2242
|
+
recordArenaAgentCompletedMetrics,
|
|
2243
|
+
recordArenaSessionEndedMetrics,
|
|
2244
|
+
recordMemoryExtractMetrics,
|
|
2245
|
+
recordMemoryDreamMetrics,
|
|
2246
|
+
recordMemoryRecallMetrics,
|
|
2247
|
+
recordChannelMemoryRecallMetrics,
|
|
2248
|
+
recordMemoryRecallDeliveryMetrics,
|
|
2249
|
+
deriveTraceId,
|
|
2250
|
+
randomSpanId,
|
|
2251
|
+
randomHexString,
|
|
2252
|
+
API_CALL_FAILED_SPAN_STATUS_MESSAGE,
|
|
2253
|
+
API_CALL_ABORTED_SPAN_STATUS_MESSAGE,
|
|
2254
|
+
safeSetStatus,
|
|
2255
|
+
areSensitiveSpanAttributesEnabled,
|
|
2256
|
+
truncateContent,
|
|
2257
|
+
addUserPromptAttributes,
|
|
2258
|
+
addSystemPromptAttributes,
|
|
2259
|
+
addToolSchemaAttributes,
|
|
2260
|
+
addModelOutputAttributes,
|
|
2261
|
+
addToolInputAttributes,
|
|
2262
|
+
addToolResultAttributes,
|
|
2263
|
+
clearDetailedSpanState,
|
|
2264
|
+
isInNativeSubagentSpan,
|
|
2265
|
+
truncateSpanError,
|
|
2266
|
+
startInteractionSpan,
|
|
2267
|
+
endInteractionSpan,
|
|
2268
|
+
withInteractionSpan,
|
|
2269
|
+
startLLMRequestSpan,
|
|
2270
|
+
endLLMRequestSpan,
|
|
2271
|
+
startToolSpan,
|
|
2272
|
+
runInToolSpanContext,
|
|
2273
|
+
endToolSpan,
|
|
2274
|
+
startToolExecutionSpan,
|
|
2275
|
+
endToolExecutionSpan,
|
|
2276
|
+
startToolBlockedOnUserSpan,
|
|
2277
|
+
endToolBlockedOnUserSpan,
|
|
2278
|
+
startHookSpan,
|
|
2279
|
+
endHookSpan,
|
|
2280
|
+
startSubagentSpan,
|
|
2281
|
+
runInSubagentSpanContext,
|
|
2282
|
+
endSubagentSpan,
|
|
2283
|
+
getActiveInteractionSpan,
|
|
2284
|
+
isTelemetrySdkInitialized,
|
|
2285
|
+
initializeTelemetry,
|
|
2286
|
+
refreshSessionContext,
|
|
2287
|
+
shutdownTelemetry,
|
|
2288
|
+
forceFlushMetrics
|
|
2289
|
+
};
|
|
2290
|
+
/**
|
|
2291
|
+
* @license
|
|
2292
|
+
* Copyright 2025 Google LLC
|
|
2293
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2294
|
+
*/
|
|
2295
|
+
/**
|
|
2296
|
+
* @license
|
|
2297
|
+
* Copyright 2026 Qwen Team
|
|
2298
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2299
|
+
*/
|