From ee78449131b529c1499e351df743c7f45869c6f4 Mon Sep 17 00:00:00 2001 From: "gorbenko.pavel" Date: Fri, 30 Oct 2026 16:16:55 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BE=D0=BD=D0=B8=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3:=20=D0=BB=D0=BE=D0=B3=D0=B8,=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=B8=20=D0=B7=D0=B0=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D1=8C=20=D1=8D=D0=BA=D1=80=D0=B0=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=80=D1=82=D0=B0=D0=BB=D0=B0=20=D0=B7=D0=B0=D1=8F=D0=B2?= =?UTF-8?q?=D0=BE=D0=BA=20=D0=B2=20monitoring.tnsu.kz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit initMonitoring в onInit веб-части (один раз на страницу), service.name = requestPortal, токен — молча через AAD веб-части (spfxTokenProvider). В package-solution.json запрос Logs.Write к регистрации мониторинга. Хэш коммита сборки — патч webpack (config/webpack-patch.json): GIT_COMMIT, GITHUB_SHA или git. Пакет @tnsu/monitoring-web ставится отдельно. Co-Authored-By: Claude Opus 5.5 --- config/package-solution.json | 4 ++++ config/webpack-patch.json | 4 ++++ config/webpack-patch/monitoring.js | 20 +++++++++++++++++++ .../requestPortal/RequestPortalWebPart.ts | 10 ++++++++++ 4 files changed, 38 insertions(+) create mode 100644 config/webpack-patch.json create mode 100644 config/webpack-patch/monitoring.js diff --git a/config/package-solution.json b/config/package-solution.json index 2307bd4..0ef3b19 100644 --- a/config/package-solution.json +++ b/config/package-solution.json @@ -30,6 +30,10 @@ "resource": "9232d9e2-9807-4753-808f-07250e5474b0", "scope": "Reports.Read" }, + { + "resource": "9232d9e2-9807-4753-808f-07250e5474b0", + "scope": "Logs.Write" + }, { "resource": "Microsoft Flow Service", "scope": "Flows.Read.All" diff --git a/config/webpack-patch.json b/config/webpack-patch.json new file mode 100644 index 0000000..4229f6c --- /dev/null +++ b/config/webpack-patch.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/webpack-patch.schema.json", + "patchFiles": ["./config/webpack-patch/monitoring.js"] +} diff --git a/config/webpack-patch/monitoring.js b/config/webpack-patch/monitoring.js new file mode 100644 index 0000000..06655af --- /dev/null +++ b/config/webpack-patch/monitoring.js @@ -0,0 +1,20 @@ +// Хэш коммита сборки — в логи (git.commit) и записи экрана мониторинга: @tnsu/monitoring-web читает +// __TNSU_GIT_COMMIT__, а webpack подставляет его при сборке. Хэш — GIT_COMMIT или GITHUB_SHA пайплайна, иначе git. +const { execSync } = require('node:child_process'); +const webpack = require('webpack'); + +function gitCommit() { + const fromEnv = process.env.GIT_COMMIT || process.env.GITHUB_SHA; + if (fromEnv) return fromEnv; + try { + return execSync('git rev-parse HEAD', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim(); + } catch { + return ''; + } +} + +module.exports = function monitoringPatch(config) { + config.plugins = config.plugins || []; + config.plugins.push(new webpack.DefinePlugin({ __TNSU_GIT_COMMIT__: JSON.stringify(gitCommit()) })); + return config; +}; diff --git a/src/webparts/requestPortal/RequestPortalWebPart.ts b/src/webparts/requestPortal/RequestPortalWebPart.ts index 988eb37..7a391c1 100644 --- a/src/webparts/requestPortal/RequestPortalWebPart.ts +++ b/src/webparts/requestPortal/RequestPortalWebPart.ts @@ -9,6 +9,7 @@ import { } from '@microsoft/sp-property-pane'; import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base'; import { IReadonlyTheme } from '@microsoft/sp-component-base'; +import { initMonitoring, spfxTokenProvider } from '@tnsu/monitoring-web'; import * as strings from 'RequestPortalWebPartStrings'; import RequestPortal from './components/RequestPortal'; @@ -62,6 +63,9 @@ export interface IRequestPortalWebPartProps { chatSelfNotify?: boolean; } +// Мониторинг — один на страницу: экземпляров веб-части на странице может быть несколько. +let monitoringStarted = false; + export default class RequestPortalWebPart extends BaseClientSideWebPart { private _isDarkTheme: boolean = false; @@ -98,6 +102,12 @@ export default class RequestPortalWebPart extends BaseClientSideWebPart { + // Логи, ошибки, console.error и запись экрана в мониторинг (monitoring.tnsu.kz). Токен — молча через + // AAD веб-части (разрешение Logs.Write в package-solution.json); при отладке в workbench окружение — development. + if (!monitoringStarted) { + monitoringStarted = true; + initMonitoring({ service: 'requestPortal', getAccessToken: spfxTokenProvider(this.context.aadTokenProviderFactory) }); + } installErrorLogging(); // до всего остального — чтобы поймать и ранние отклонения initSP(this.context); // единый клиент PnPjs для записи в списки