Yuki Takei 9 месяцев назад
Родитель
Сommit
d6eda80486

+ 0 - 72
apps/app/src/features/opentelemetry/docs/improvement-plan.md

@@ -1,72 +0,0 @@
-# OpenTelemetry 改修計画
-
-## 改修内容
-
-### 1. カスタムメトリクス送信
-**目的**: システム情報とカスタム属性の送信
-
-**追加メトリクス**:
-- CPU使用率、メモリ使用量(手動実装が必要)
-- GROWI固有情報(ユーザー数、ページ数等)
-- サーバーURL、環境情報
-
-**実装方針**:
-- **Resource Attributes**: 永続的情報(サーバーURL等)
-- **Custom Metrics**: 動的情報(CPU・メモリ等、取得ロジックを実装)
-
-### 2. データ匿名化
-**目的**: 機密情報の除外・マスキング
-
-**対象データ**:
-- 検索クエリパラメータ(`?q=secret` → `?q=***`)
-- 認証ヘッダー(完全除外)
-- IPアドレス(部分マスキング)
-
-**実装方針**:
-- **HTTP Instrumentation Hook**: リクエスト/レスポンス時の匿名化
-- **Metric Views**: メトリクス属性のフィルタリング
-
-## 技術選択
-
-### OpenTelemetry標準の活用
-- **セマンティックコンベンション**: 標準メトリクス名を使用
-- **Resource Detection**: 環境情報の自動検出
-- **Instrumentation Hook**: 既存の拡張ポイントを活用
-
-### 設定方式
-- **環境変数**: 基本設定
-- **Feature Flag**: 段階的有効化
-- **Hook Functions**: カスタムロジック
-
-## 非機能要件
-- **パフォーマンス影響**: CPU +5%以下、メモリ +50MB以下
-- **セキュリティ**: 機密データの完全匿名化
-- **運用性**: 設定での有効/無効制御
-
-## 技術実装方針
-
-### カスタムメトリクス
-**パッケージ**: `@opentelemetry/api`
-- **Resource**: `new Resource(attributes)` でカスタム属性追加
-- **Meter**: `metrics.getMeter('growi-metrics')` でカスタムメーター作成
-- **ObservableGauge**: `meter.createObservableGauge()` でシステムメトリクス
-- **システム情報**: Node.js標準の `os` モジュール(`os.cpus()`, `os.totalmem()`)
-- **注意**: CPU・メモリ使用率は自動収集されないため、取得ロジックの実装が必要
-
-### データ匿名化
-**パッケージ**: `@opentelemetry/instrumentation-http`
-- **RequestHook**: `HttpInstrumentation({ requestHook: (span, request) => {} })` 
-- **ResponseHook**: `HttpInstrumentation({ responseHook: (span, response) => {} })`
-- **Metric Views**: `MeterProvider({ views: [{ attributeKeys: [...] }] })` で属性フィルタ
-- **URL操作**: 標準 `URL` クラスで `searchParams.set(key, '***')`
-
-## 参考情報
-- [OpenTelemetry Node.js SDK](https://open-telemetry.github.io/opentelemetry-js/)
-- [Custom Metrics Documentation](https://opentelemetry.io/docs/instrumentation/js/manual/#creating-metrics)
-- [HTTP Instrumentation Configuration](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-http#configuration)
-- [Semantic Conventions for System Metrics](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/system/system-metrics.md)
-- [Resource Semantic Conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md)
-
----
-*作成日: 2025-06-19*  
-*削除予定: 改修完了時*

+ 0 - 95
apps/app/src/features/opentelemetry/docs/improvement-task.md

@@ -1,95 +0,0 @@
-# OpenTelemetry 改修タスク
-
-## 進捗状況
-**開始日**: 2025-06-19  
-**完了予定**: 未設定
-
-## タスク一覧
-
-### Phase 1: カスタムメトリクス
-- [x] **Resource Attributes拡張**
-  - [x] サーバーURL属性追加(環境変数から取得)
-  - [x] GROWI固有属性追加(基本情報)
-  - [x] 環境情報属性追加
-- [x] **System Metrics実装**
-  - [x] CPU使用率収集(計算ロジックの実装が必要)
-  - [x] メモリ使用率収集(process.memoryUsage()使用)
-  - [x] 収集間隔設定(デフォルト15秒)
-- [x] **Application Metrics実装**
-  - [x] ダミーメトリクス実装(将来の拡張用)
-  - [ ] ユーザー数メトリクス
-  - [ ] ページ数メトリクス
-  - [ ] 検索回数カウンター
-
-### Phase 2: データ匿名化
-- [x] **HTTP匿名化**
-  - [x] クエリパラメータマスキング(`q`, `query`, `search`)
-  - [x] HTTP Instrumentation統合
-  - [x] 未使用コードの削除・リファクタリング
-  - [ ] 認証ヘッダー除外(`authorization`, `cookie`)
-  - [ ] IPアドレス部分マスキング
-- [x] **設定機能**
-  - [x] 匿名化有効/無効制御(環境変数)
-  - [x] 設定の定数化
-  - [ ] カスタム除外パターン設定
-
-### Phase 3: 統合・テスト
-- [ ] **統合テスト**
-  - [ ] メトリクス送信確認
-  - [ ] 匿名化動作確認
-  - [ ] パフォーマンス影響測定
-- [ ] **ドキュメント更新**
-  - [ ] `overview.md`更新
-  - [ ] 設定項目ドキュメント追加
-
-## 実装メモ
-
-### 実装場所
-- **Resource Attributes**: `node-sdk-resource.ts`に追加
-- **Custom Metrics**: 新規`custom-metrics.ts`作成
-- **データ匿名化**: `node-sdk-configuration.ts`のHook設定
-
-### 技術詳細
-**カスタムメトリクス**:
-- `@opentelemetry/api.metrics.getMeter()` でメーター取得
-- `meter.createObservableGauge()` でシステムメトリクス作成
-- `meter.addBatchObservableCallback()` で定期収集
-- `os.cpus()`, `process.memoryUsage()` でシステム情報取得
-- **重要**: CPU使用率計算ロジックは実装者が作成(OpenTelemetryは送信のみ)
-
-**データ匿名化**:
-- `@opentelemetry/instrumentation-http.HttpInstrumentation` の `requestHook` オプション
-- `span.setAttribute()` で属性値を `'***'` に置換
-- `URL.searchParams.set(param, '***')` でクエリパラメータマスキング
-- 正規表現 `/(\?|&)(q|query|search)=([^&]*)/gi` で検索パラメータ検出
-
-**Resource Attributes**:
-- `@opentelemetry/resources.Resource` クラス
-- `resource.merge(otherResource)` で既存リソースに追加
-- `os.hostname()`, `process.env.NODE_ENV` で環境情報取得
-
-### 設定例
-```typescript
-// Resource Attributes
-const customResource = new Resource({
-  'growi.server.url': process.env.GROWI_SERVER_URL,
-  'growi.installation.type': detectInstallationType(),
-});
-
-// HTTP Hook
-const httpInstrumentation = new HttpInstrumentation({
-  requestHook: (span, request) => {
-    // クエリパラメータ匿名化
-    anonymizeSearchQueries(span);
-  }
-});
-```
-
-### 注意点
-- 既存のOTEL設定に影響しないよう追加実装
-- Feature Flagで段階的有効化
-- パフォーマンス監視必須
-
----
-*最終更新: 2025-06-19*  
-*削除予定: 改修完了時*

+ 7 - 1
apps/app/src/features/opentelemetry/docs/overview.md

@@ -35,9 +35,15 @@
 3. **OTLP Exporter** が外部Collectorに送信
 3. **OTLP Exporter** が外部Collectorに送信
 
 
 ## 制限事項
 ## 制限事項
-- カスタムメトリクス(CPU・メモリ等)未実装
 - 機密データの匿名化未実装
 - 機密データの匿名化未実装
 - GROWIアプリ固有の情報未送信
 - GROWIアプリ固有の情報未送信
 
 
+## 参考情報
+- [OpenTelemetry Node.js SDK](https://open-telemetry.github.io/opentelemetry-js/)
+- [Custom Metrics Documentation](https://opentelemetry.io/docs/instrumentation/js/manual/#creating-metrics)
+- [HTTP Instrumentation Configuration](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/opentelemetry-instrumentation-http#configuration)
+- [Semantic Conventions for System Metrics](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/system/system-metrics.md)
+- [Resource Semantic Conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md)
+
 ---
 ---
 *更新日: 2025-06-19*
 *更新日: 2025-06-19*