|
| 1 | +# dotnet-monitor Repository - Copilot Instructions |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +`dotnet-monitor` is a diagnostic tool for capturing diagnostic artifacts from .NET applications in an operator-driven or automated manner. It provides a unified HTTP API for collecting diagnostics regardless of where the application runs (local, Docker, Kubernetes). |
| 6 | + |
| 7 | +**Key Features:** |
| 8 | +- HTTP API for on-demand collection of diagnostic artifacts (dumps, traces, logs, metrics) |
| 9 | +- Collection Rules for automated, rule-based artifact collection based on triggers |
| 10 | +- Egress providers for storing artifacts in various destinations |
| 11 | +- Cross-platform support (Windows, Linux, macOS) |
| 12 | + |
| 13 | +## Technology Stack |
| 14 | + |
| 15 | +- **Primary Language:** C# |
| 16 | +- **.NET SDK:** 10.0 |
| 17 | +- **Target Frameworks:** .NET 8.0, 9.0, 10.0 |
| 18 | +- **ASP.NET Core:** Multi-version support (8.0, 9.0, 10.0) |
| 19 | +- **Build System:** MSBuild with .NET Arcade SDK |
| 20 | +- **Native Code:** C++ (for profilers and native components) |
| 21 | +- **Testing:** xUnit |
| 22 | +- **Documentation:** Markdown |
| 23 | +- **Package Management:** NuGet with Central Package Management |
| 24 | + |
| 25 | +## Repository Structure |
| 26 | + |
| 27 | +- **`src/Tools/dotnet-monitor/`** - Main dotnet-monitor tool |
| 28 | +- **`src/Microsoft.Diagnostics.Monitoring.WebApi/`** - Core Web API implementation |
| 29 | +- **`src/Microsoft.Diagnostics.Monitoring.Options/`** - Configuration options |
| 30 | +- **`src/Microsoft.Diagnostics.Monitoring.StartupHook/`** - Startup hook for in-process features |
| 31 | +- **`src/Extensions/`** - Extension implementations (Azure Blob, S3 storage, etc.) |
| 32 | +- **`src/Profilers/`** - Native profiler implementations |
| 33 | +- **`src/Tests/`** - All test projects |
| 34 | +- **`documentation/`** - User-facing documentation |
| 35 | +- **`eng/`** - Build and engineering infrastructure |
| 36 | + |
| 37 | +## Build and Test Commands |
| 38 | + |
| 39 | +### Build |
| 40 | +```bash |
| 41 | +# Windows |
| 42 | +.\Build.cmd |
| 43 | + |
| 44 | +# Linux/macOS |
| 45 | +./build.sh |
| 46 | +``` |
| 47 | + |
| 48 | +### Test |
| 49 | +```bash |
| 50 | +# Windows |
| 51 | +.\Test.cmd |
| 52 | + |
| 53 | +# Linux/macOS |
| 54 | +./test.sh |
| 55 | +``` |
| 56 | + |
| 57 | +### Restore Dependencies |
| 58 | +```bash |
| 59 | +# Windows |
| 60 | +.\Restore.cmd |
| 61 | + |
| 62 | +# Linux/macOS |
| 63 | +./restore.sh |
| 64 | +``` |
| 65 | + |
| 66 | +## Coding Guidelines |
| 67 | + |
| 68 | +### C# Code Style |
| 69 | + |
| 70 | +1. **File Headers:** All C# files must include the .NET Foundation license header: |
| 71 | + ```csharp |
| 72 | + // Licensed to the .NET Foundation under one or more agreements. |
| 73 | + // The .NET Foundation licenses this file to you under the MIT license. |
| 74 | + ``` |
| 75 | + |
| 76 | +2. **Language Version:** Use `Latest` C# language features |
| 77 | + |
| 78 | +3. **Code Style Preferences:** |
| 79 | + - Do NOT use `var` - use explicit types |
| 80 | + - Prefer explicit types for locals, parameters, and member access |
| 81 | + - Use `this.` qualification: NO (avoid using `this.` unless necessary) |
| 82 | + - Expression-bodied members: Use for properties, accessors, indexers, lambdas |
| 83 | + - Expression-bodied members: DO NOT use for methods, constructors, operators |
| 84 | + - Pattern matching: Prefer pattern matching over `as` with null checks |
| 85 | + - Null-checking: Use null-conditional operators and null-coalescing |
| 86 | + - Using directives: Place outside namespace |
| 87 | + - Namespace style: Use block-scoped namespaces (not file-scoped) |
| 88 | + - Braces: Always use braces even for single-line blocks |
| 89 | + |
| 90 | +4. **Modifier Order:** |
| 91 | + ``` |
| 92 | + public, private, protected, internal, static, extern, new, virtual, |
| 93 | + abstract, sealed, override, readonly, unsafe, volatile, async |
| 94 | + ``` |
| 95 | + |
| 96 | +5. **Documentation:** Generate XML documentation files for all projects |
| 97 | + |
| 98 | +6. **Warnings:** Treat all warnings as errors (`TreatWarningsAsErrors=true`) |
| 99 | + |
| 100 | +7. **Code Style Enforcement:** Code style rules are enforced during build (`EnforceCodeStyleInBuild=true`) |
| 101 | + |
| 102 | +### Formatting |
| 103 | + |
| 104 | +- **Indentation:** 4 spaces (2 spaces for XML/YAML/JSON config files) |
| 105 | +- **Line Endings:** Insert final newline |
| 106 | +- **Trailing Whitespace:** Trim trailing whitespace |
| 107 | +- **C++ Code:** Use Allman brace style |
| 108 | + |
| 109 | +### Testing |
| 110 | + |
| 111 | +- All test projects are in `src/Tests/` |
| 112 | +- Use xUnit for unit tests |
| 113 | +- Test project naming: `<Component>.UnitTests` or `<Component>.IntegrationTests` |
| 114 | +- Always add tests when adding new features |
| 115 | +- Start with a failing test when fixing bugs |
| 116 | + |
| 117 | +## Security Considerations |
| 118 | + |
| 119 | +1. **Authentication:** dotnet-monitor supports API Key authentication (recommended) and Windows authentication |
| 120 | +2. **Sensitive Data:** Never commit secrets or API keys to source code |
| 121 | +3. **Security Documentation:** See `documentation/security-considerations.md` for security topics |
| 122 | + |
| 123 | +## Pull Request Process |
| 124 | + |
| 125 | +1. Create an issue for non-trivial changes |
| 126 | +2. Fork the repository and create a feature branch from `main` |
| 127 | +3. Make focused, minimal changes |
| 128 | +4. Add tests for new features or bug fixes |
| 129 | +5. Ensure builds are clean and all tests pass |
| 130 | +6. Sign the .NET Foundation CLA (automated on first PR) |
| 131 | +7. Wait for review from Microsoft team members |
| 132 | +8. Address feedback and iterate |
| 133 | + |
| 134 | +## Key Configuration Files |
| 135 | + |
| 136 | +- **`Directory.Build.props`** - Common MSBuild properties for all projects |
| 137 | +- **`Directory.Packages.props`** - Central package version management |
| 138 | +- **`.editorconfig`** - Code style and formatting rules |
| 139 | +- **`global.json`** - .NET SDK version pinning |
| 140 | +- **`NuGet.config`** - NuGet feed configuration |
| 141 | + |
| 142 | +## Common Patterns |
| 143 | + |
| 144 | +1. **Options Pattern:** Use strongly-typed options classes in `Microsoft.Diagnostics.Monitoring.Options` |
| 145 | +2. **Collection Rules:** Implement triggers and actions following existing patterns |
| 146 | +3. **Egress Providers:** Extend `IEgressProvider` for new storage backends |
| 147 | +4. **API Endpoints:** Follow RESTful conventions in `Microsoft.Diagnostics.Monitoring.WebApi` |
| 148 | +5. **Configuration:** Use IConfiguration with JSON/environment variable support |
| 149 | +6. **Learning Paths:** Guidance for developers on the various components in `dotnet-monitor`. It may need to be updated based on product changes. |
| 150 | + |
| 151 | +## Documentation |
| 152 | + |
| 153 | +- User documentation in `documentation/` directory |
| 154 | +- API documentation at `documentation/api/` |
| 155 | +- Configuration schema: `documentation/schema.json` |
| 156 | +- Keep documentation synchronized with code changes |
| 157 | +- Follow existing markdown structure and formatting |
| 158 | + |
| 159 | +## Useful Links |
| 160 | + |
| 161 | +- [Contributing Guidelines](CONTRIBUTING.md) |
| 162 | +- [Building Instructions](documentation/building.md) |
| 163 | +- [Security Policy](SECURITY.md) |
| 164 | +- [API Documentation](documentation/api/README.md) |
| 165 | +- [Configuration Guide](documentation/configuration/README.md) |
0 commit comments