@@ -371,6 +371,157 @@ dotnet build -c Release
371371.\src\ExcelMcp.CLI\bin\Release\net10.0\excelcli.exe --version
372372```
373373
374+ ## 📊 ** Application Insights / Telemetry Setup**
375+
376+ ExcelMcp uses Azure Application Insights for anonymous usage telemetry and crash reporting. Telemetry is ** opt-out** (enabled by default in release builds).
377+
378+ ### ** What is Tracked**
379+
380+ - ** Tool invocations** : Tool name, action, duration (ms), success/failure
381+ - ** Unhandled exceptions** : Exception type and redacted stack trace
382+ - ** Session ID** : Random GUID per process (no user identification)
383+
384+ ### ** What is NOT Tracked**
385+
386+ - File paths, file names, or file contents
387+ - User identity, machine name, or IP address
388+ - Excel data, formulas, or cell values
389+ - Connection strings, credentials, or passwords
390+
391+ ### ** Sensitive Data Redaction**
392+
393+ All telemetry passes through ` SensitiveDataRedactingProcessor ` which removes:
394+ - Windows file paths (` C:\Users\... ` → ` [REDACTED_PATH] ` )
395+ - UNC paths (` \\server\share\... ` → ` [REDACTED_PATH] ` )
396+ - Connection string secrets (` Password=... ` → ` [REDACTED_CREDENTIAL] ` )
397+ - Email addresses → ` [REDACTED_EMAIL] `
398+
399+ ### ** Azure Resources Setup (Maintainers Only)**
400+
401+ To deploy the Application Insights infrastructure:
402+
403+ ``` powershell
404+ # 1. Login to Azure
405+ az login
406+
407+ # 2. Deploy resources (creates RG, Log Analytics, App Insights)
408+ .\infrastructure\azure\deploy-appinsights.ps1 -SubscriptionId "<your-subscription-id>"
409+
410+ # 3. Copy the connection string from output
411+ # Output: "Connection String: InstrumentationKey=xxx;IngestionEndpoint=..."
412+ ```
413+
414+ ### ** GitHub Secret Configuration (Maintainers Only)**
415+
416+ After deploying Azure resources:
417+
418+ 1 . Go to GitHub repo → ** Settings** → ** Secrets and variables** → ** Actions**
419+ 2 . Add new secret: ` APPINSIGHTS_CONNECTION_STRING `
420+ 3 . Paste the connection string from deployment output
421+
422+ The release workflow automatically injects this at build time.
423+
424+ ### ** Local Development**
425+
426+ During local development, telemetry is ** disabled by default** because the placeholder connection string is not replaced. This is intentional - no telemetry data is sent from dev builds.
427+
428+ #### ** Debug Mode: Console Output**
429+
430+ To test telemetry locally without Azure, enable debug mode which logs to stderr:
431+
432+ ``` powershell
433+ # Enable debug telemetry (logs to console instead of Azure)
434+ $env:EXCELMCP_DEBUG_TELEMETRY = "true"
435+
436+ # Build and run the MCP server
437+ dotnet build src/ExcelMcp.McpServer/ExcelMcp.McpServer.csproj
438+ dotnet run --project src/ExcelMcp.McpServer/ExcelMcp.McpServer.csproj
439+
440+ # You'll see telemetry output like:
441+ # [Telemetry] Debug mode enabled - logging to stderr
442+ # Activity.TraceId: abc123...
443+ # Activity.DisplayName: ToolInvocation
444+ # Activity.Tags:
445+ # tool.name: excel_file
446+ # tool.action: list
447+ # tool.duration_ms: 42
448+ # tool.success: true
449+ ```
450+
451+ #### ** Testing with Real Azure Resources**
452+
453+ To test with actual Application Insights:
454+
455+ ``` powershell
456+ # 1. Deploy Azure resources
457+ .\infrastructure\azure\deploy-appinsights.ps1 -SubscriptionId "<your-sub-id>"
458+
459+ # 2. Temporarily inject connection string (DON'T COMMIT!)
460+ $connStr = "InstrumentationKey=xxx;IngestionEndpoint=https://..."
461+ (Get-Content "src/ExcelMcp.McpServer/Telemetry/ExcelMcpTelemetry.cs") -replace `
462+ '__APPINSIGHTS_CONNECTION_STRING__', $connStr | `
463+ Set-Content "src/ExcelMcp.McpServer/Telemetry/ExcelMcpTelemetry.cs"
464+
465+ # 3. Build and run
466+ dotnet build src/ExcelMcp.McpServer/ExcelMcp.McpServer.csproj
467+ dotnet run --project src/ExcelMcp.McpServer/ExcelMcp.McpServer.csproj
468+
469+ # 4. Check Azure Portal → Application Insights → Transaction search
470+
471+ # 5. IMPORTANT: Revert the file (don't commit connection string!)
472+ git checkout src/ExcelMcp.McpServer/Telemetry/ExcelMcpTelemetry.cs
473+ ```
474+
475+ To verify telemetry state:
476+ ``` csharp
477+ // ExcelMcpTelemetry.IsEnabled returns false when:
478+ // - Connection string is placeholder "__APPINSIGHTS_CONNECTION_STRING__"
479+ // - User has opted out via EXCELMCP_TELEMETRY_OPTOUT=true
480+
481+ // ExcelMcpTelemetry.IsEnabled returns true when:
482+ // - EXCELMCP_DEBUG_TELEMETRY=true (console output mode)
483+ // - Connection string is real (injected at build time)
484+ ```
485+
486+ ### ** User Opt-Out**
487+
488+ Users can disable telemetry by setting an environment variable:
489+
490+ ``` powershell
491+ # Windows
492+ $env:EXCELMCP_TELEMETRY_OPTOUT = "true"
493+
494+ # Or permanently via System Properties → Environment Variables
495+ ```
496+
497+ ### ** Telemetry Architecture**
498+
499+ ```
500+ MCP Tool Invocation
501+ │
502+ ▼
503+ ExcelToolsBase.ExecuteToolAction()
504+ │ (tracks: tool, action, duration, success)
505+ ▼
506+ ExcelMcpTelemetry.TrackToolInvocation()
507+ │
508+ ▼
509+ SensitiveDataRedactingProcessor
510+ │ (removes: paths, credentials, emails)
511+ ▼
512+ Azure Monitor Exporter → Application Insights
513+ ```
514+
515+ ### ** Files Overview**
516+
517+ | File | Purpose |
518+ | ------| ---------|
519+ | ` Telemetry/ExcelMcpTelemetry.cs ` | Static helper for tracking |
520+ | ` Telemetry/SensitiveDataRedactingProcessor.cs ` | Redacts PII before transmission |
521+ | ` Program.cs ` | OpenTelemetry configuration |
522+ | ` infrastructure/azure/appinsights.bicep ` | Azure resource definitions |
523+ | ` infrastructure/azure/deploy-appinsights.ps1 ` | Deployment script |
524+
374525## 📞 ** Need Help?**
375526
376527- ** Read the docs** : [ Contributing Guide] ( CONTRIBUTING.md )
0 commit comments