Omex
Copilot instructions78 starsChanged 3 months agoMITView on GitHub
This is a collection of shared .NET extensions and utilities for building scalable, distributed systems at Microsoft. The codebase follows a modular architecture with multiple NuGet packages, each serving specific purposes in service orchestration, telemetry, health monitoring, Service Fabric integration, and feature management. All extensions follow this consistent pattern: See src/Hosting/ServiceCollectionExtensions.cs for the canonical example. Use IAccessor<T> for late-bound dependencies not available during DI container build (especially Service Fabric contexts): See src/Abstractions/Accessors/Accessor.cs and src/Hosting.Services/HostBuilderExtensions.cs Health checks use decorator pattern instead…
The file
We split this copilot-instructions.md into the rules it gives an agent
8 rules. About 0 are common, 2 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
All extensions follow this consistent pattern:
- Very specific: line 40
Use IAccessor<T> for late-bound dependencies not available during DI container build (especially Service Fabric contexts):
- Very specific: line 84
Use OmexEnvironments constants instead of magic strings:
- Distinctive: line 96
Always use project-specific validation and automatic tagging:
- Very specific: line 111
All projects use Microsoft.Omex.Extensions.* naming convention
- Very specific: line 122
Treat warnings as errors (<TreatWarningsAsErrors>true</TreatWarningsAsErrors>)
- Very specific: line 128
Test projects mirror source structure with *.UnitTests suffix
- Very specific: line 130
Use [DataRow] for parameterized tests extensively
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Microsoft Omex Extensions - Copilot Instructions
Project Overview
This is a collection of shared .NET extensions and utilities for building scalable, distributed systems at Microsoft. The codebase follows a modular architecture with multiple NuGet packages, each serving specific purposes in service orchestration, telemetry, health monitoring, Service Fabric integration, and feature management.
Architecture & Module Structure
Core Modules
- Abstractions: Base interfaces and utilities (
IAccessor<T>, validation, tagging) - Activities: OpenTelemetry/activity management and metrics collection with W3C trace context
- Hosting: Service hosting utilities with environment-specific configurations (
OmexEnvironments) - Logging: Centralized logging infrastructure with scrubbing capabilities
- Diagnostics.HealthChecks: Composable health check framework using decorator pattern
- FeatureManagement: Advanced feature flags with A/B testing, experimental features, and server-controlled overrides
- ServiceFabricGuest.Abstractions: Service Fabric client wrappers and abstractions
- Services.Remoting: Service Fabric remoting extensions with activity propagation
- Testing.Helpers: Shared testing utilities including
NullableAssert
Key Patterns
Service Registration Pattern
All extensions follow this consistent pattern:
public static IServiceCollection AddOmexServices(this IServiceCollection collection)
{
// Always use TryAdd* methods for idempotency
// Chain multiple registrations fluently
return collection.AddOmexActivitySource();
}See src/Hosting/ServiceCollectionExtensions.cs for the canonical example.
Accessor Pattern
Use IAccessor<T> for late-bound dependencies not available during DI container build (especially Service Fabric contexts):
// Always register with TryAddAccessor<T>() helper
collection.TryAddAccessor<StatefulServiceContext, ServiceContext>();
// Implementation handles weak references for callback cleanup
public void OnFirstSet(Action<TValue> action)
{
if (m_value != null) action(m_value);
else m_actions.AddLast(new WeakReference<Action<TValue>>(action));
}See src/Abstractions/Accessors/Accessor.cs and src/Hosting.Services/HostBuilderExtensions.cs
Health Check Composition
Health checks use decorator pattern instead of inheritance:
// Wrap base checks with observability
services.AddHealthCheck("MyCheck")
.AddObservability() // Telemetry wrapper
.AddStartupCaching() // One-time validation
.Build();Feature Management Integration
The system supports layered feature resolution with experimental overrides:
// Always inject IFeatureGatesConsolidator (higher level)
private readonly IFeatureGatesConsolidator _featureGates;
// Resolution order: Server overrides → Experiments → Static config
var features = await _featureGates.GetFeatureGatesAsync(filters);IPAddressFilter must use only HttpContext.Connection.RemoteIpAddress. Applications behind a reverse proxy must configure ForwardedHeadersMiddleware with trusted KnownProxies or KnownNetworks. Never parse X-Forwarded-For directly or bypass configured IP ranges for local requests.
Environment Configuration
Use OmexEnvironments constants instead of magic strings:
// From src/Hosting/OmexEnvironments.cs
OmexEnvironments.Development // "Development"
OmexEnvironments.Int // "Int" (CI/CD)
OmexEnvironments.EDog // "EDog" (pre-prod)
OmexEnvironments.Production // "Production"Validation & Tagging
Always use project-specific validation and automatic tagging:
// Parameter validation (throws with descriptive messages)
string validated = Validation.ThrowIfNullOrWhiteSpace(value, nameof(value));
// Automatic EventId generation using file path and line number
EventId eventId = Tag.Create(); // Uses [CallerFilePath] and [CallerLineNumber]
logger.LogInformation(eventId, "Message");Build & Development Patterns
Project Structure
- All projects use
Microsoft.Omex.Extensions.*naming convention - Source in
src/, tests intests/with matching directory structure - Central package management via
Directory.Packages.propswith version conditions - Multi-targeting: .NET 10.0 + netstandard2.0 for broad compatibility
- Strong naming with
OmexOpenSource.snk
Build Configuration
Critical settings in Directory.Build.props:
- Nullable reference types enabled (
<Nullable>enable</Nullable>) - Treat warnings as errors (
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>) - Automatic
InternalsVisibleTofor unit test assemblies and Moq - Source linking for debugging with path mapping for build location independence
Testing Conventions
- Test projects mirror source structure with
*.UnitTestssuffix - MSTest framework with
[TestClass]and[TestMethod]attributes - Use
[DataRow]for parameterized tests extensively - Test naming:
MethodName_WhenCondition_ExpectedResult - Mock with Moq (pinned to version 4.20.72)
- Shared testing utilities in
Testing.Helpersproject
Example test structure:
[TestMethod]
[DataRow(typeof(IAccessor<ServiceContext>), typeof(Accessor<StatefulServiceContext>))]
public void BuildService_RegistersTypes(Type interfaceType, Type implementationType)Dependencies & Integration Points
Core Microsoft.Extensions Integration
- Heavy use of Options pattern with validation
- HttpClient factory pattern for all HTTP operations
- Hosted services for background initialization
- Configuration binding with
appsettings.json
Activity/Telemetry Integration
- W3C trace context propagation across service boundaries
- Custom baggage and tag dimensions through
ICustomBaggageDimensions - Activity metrics with histogram reporting
- Service Fabric remoting headers:
omex-traceparent,omex-tracestate
Service Fabric Specifics
- Requires Service Fabric SDK for development
- Accessor pattern critical for context availability during service lifecycle
- State manager integration for stateful services
- Partition and replica role change handling
Key Commands
# Basic build workflow
dotnet restore
dotnet build --configuration Release
dotnet test --no-build --configuration Release
dotnet pack --no-build --configuration Release
# Service Fabric development (Windows required)
# Ensure Service Fabric SDK installed for SF projectsRecent Architecture Additions
Feature Management System
- Layered resolution: Server overrides → Experiments → Static config
- Support for A/B testing with customer targeting
- HTTP context integration for web scenarios
- Frontend feature handling with automatic partner/platform header processing
Modern Telemetry
- Migration from EventSource to OpenTelemetry metrics
- Histogram-based activity measurement with tenant/environment tagging
- Activity observer pattern for consistent logging format
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

