monica-opentelemetry
Skill18 starsChanged 7 months agoMITView on GitHub
Monica OpenTelemetry and metrics development guidance. Use when adding or refactoring Monica module telemetry, creating a Metrics/ folder, designing System.Diagnostics.Metrics instruments with IMeterFactory, exposing OpenTelemetry-compatible meter names, choosing Counter/Histogram/Gauge instruments, handling app-owned diagnostic snapshots, avoiding high-cardinality tags, or deciding where metrics instrumentation belongs in Monica modules.
In this repository34 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- monica-application-building-block-developmentSkill
- monica-application-microserviceSkill
- monica-application-modular-monolithSkill
- monica-applicationSkill
- monica-application-ui-developmentSkill
- monica-application-uiSkill
- monica-application-unit-testingSkill
- monica-architectureSkill
- monica-coding-standardsSkill
- monica-contributionSkill
- monica-developmentSkill
- monica-docs-authoringSkill
- monica-frameworkSkill
- monica-guideSkill
- monica-infra-aiSkill
- monica-infra-configurationSkill
- monica-infra-hostingSkill
- monica-infra-jobsSkill
- monica-infra-messagingSkill
- monica-infra-observabilitySkill
- monica-infra-persistenceSkill
- monica-infra-uiSkill
- monica-infra-webSkill
- monica-requirement-designSkill
- monica-third-party-module-developmentSkill
- monica-troubleshootingSkill
- monica-ui-auditSkill
- monica-ui-bridge-debugSkill
- monica-ui-designSkill
- monica-ui-developmentSkill
- monica-ui-localizationSkill
- monica-unit-testingSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 3 are distinctive, and 13 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Use this skill to author Monica module instruments.
- Very specific: line 18
Do not add OpenTelemetry.* package references to Monica infrastructure modules unless the module is explicitly an observability …
- Very specific: line 22
Use Metrics/ for telemetry names, instruments, app-owned metric state, and instrumentation adapters.
- Very specific: line 44
Create one internal singleton metric owner per coherent telemetry area.
- Very specific: line 95
Use Counter<T> for monotonic totals such as requests, failures, lifecycle events, bytes sent, or jobs completed.
- Very specific: line 96
Use Histogram<T> for distributions such as duration, payload size, queue latency, or retry delay.
- Very specific: line 97
Use ObservableGauge<T> for current values read from app-owned state, such as active jobs, pending sends, or open connections.
- Very specific: line 98
Use app-owned state only when Monica needs a current snapshot, UI data, or observable gauge values.
- Distinctive: line 102
Keep tags low-cardinality and stable.
- Distinctive: line 114
Avoid tags with unbounded or sensitive values:
- Very specific: line 125
Use private constants for tag names and stable tag values.
- Very specific: line 146
Keep app-owned fields only when an ObservableGauge, snapshot model, or Monica runtime behavior reads them.
- Very specific: line 151
Avoid locks in metric recording.
- Very specific: line 152
Avoid large tag sets; Add/Record with three or fewer individually supplied tags is preferred for hot paths.
- Distinctive: line 153
Keep observable callbacks fast: read cached state and return measurements.
- Very specific: line 154
Do not register custom MeterListener aggregation in Monica modules unless explicitly designing a collector.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill 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
Monica OpenTelemetry
Use this skill to author Monica module instruments. For an application registering exporters or consuming existing diagnostics, use $monica-infra-observability.
Core Rule
Monica modules emit standard .NET metrics through System.Diagnostics.Metrics. Hosts configure OpenTelemetry exporters, Prometheus scraping, OTLP, Azure Monitor, storage, and dashboards.
Monica module -> System.Diagnostics.Metrics -> host OpenTelemetry setup -> backend/UIDo not add OpenTelemetry.* package references to Monica infrastructure modules unless the module is explicitly an observability host/integration module.
Folder Placement
Use Metrics/ for telemetry names, instruments, app-owned metric state, and instrumentation adapters.
Monica.{Name}/
├── Metrics/
│ ├── {Name}MetricNames.cs # public constants when hosts need meter names
│ ├── {Feature}Metrics.cs # internal singleton metric owner
│ └── {Feature}MetricsInterceptor.cs # optional adapter, e.g. EF Core interceptorFor feature-folder modules, place telemetry under the feature:
Monica.Repository/
└── Persistence/
└── Metrics/Snapshot DTOs exposed to Facades or UI stay in Models/, not Metrics/.
Standard Pattern
Create one internal singleton metric owner per coherent telemetry area. Use IMeterFactory, not static new Meter(...), in DI-based Monica modules.
using System.Diagnostics.Metrics;
namespace Monica.Repository.Persistence.Metrics;
public static class RepositoryPersistenceMetricNames
{
public const string MeterName = "Monica.Repository.Persistence";
public const string EfCoreConnectionEvents =
"monica.repository.persistence.ef_core.connection.events";
}
internal sealed class EfCoreConnectionMetrics(IMeterFactory meterFactory)
{
private const string EVENT_TAG_NAME = "event";
private readonly Counter<long> _connectionEvents = meterFactory
.Create(RepositoryPersistenceMetricNames.MeterName)
.CreateCounter<long>(
RepositoryPersistenceMetricNames.EfCoreConnectionEvents,
unit: "events",
description: "EF Core connection lifecycle events observed by Monica Repository.");
public void RecordConnectionOpened()
{
_connectionEvents.Add(1, new KeyValuePair<string, object?>(EVENT_TAG_NAME, "opened"));
}
}Register metric owners as singleton:
services.TryAddSingleton<EfCoreConnectionMetrics>();
services.TryAddSingleton<EfCoreConnectionMetricsInterceptor>();Host Bootstrap
IMeterFactory is auto-registered by Microsoft.Extensions.Hosting in .NET 8+ and by ASP.NET Core hosts. Monica modules just register their metric owners with TryAddSingleton<TMetrics>(). Call services.AddMetrics() only in non-Hosting scenarios such as bare ServiceCollection test fixtures.
Expose a module option when instrumentation has non-trivial overhead or attaches framework adapters:
public bool EnableEfCoreConnectionMetrics { get; set; }Instrument Choice
- Use
Counter<T>for monotonic totals such as requests, failures, lifecycle events, bytes sent, or jobs completed. - Use
Histogram<T>for distributions such as duration, payload size, queue latency, or retry delay. - Use
ObservableGauge<T>for current values read from app-owned state, such as active jobs, pending sends, or open connections. - Use app-owned state only when Monica needs a current snapshot, UI data, or observable gauge values. Do not mirror counters just to read metric values later.
Tags
Keep tags low-cardinality and stable.
Good tags:
event=opened
result=success
reason=validation
state=pending
provider=postgresqlAvoid tags with unbounded or sensitive values:
user.id
order.id
trace.id
connection.id
exception.message
raw path/query stringsUse private constants for tag names and stable tag values. Private constants use upper snake case in Monica.
App-Owned Diagnostics vs Telemetry
Telemetry instruments are write/observe APIs, not the source of truth for app logic.
Use this split:
Metric owner state
-> only when observable gauges or Monica snapshots need current values
Metric instruments
-> emit Counter/Histogram/Gauge measurements
Snapshot models
-> public Models/ types returned by Facades/UIFor UI diagnostics like SignalR pending sends, keep the state owner cohesive and expose snapshots through a Facade. Emit OpenTelemetry-compatible metrics from the same owner only when useful.
Keep app-owned fields only when an ObservableGauge, snapshot model, or Monica runtime behavior reads them. Do not duplicate Counter<T> values into local Interlocked fields just because the event also increments.
Performance Rules
- Metric calls should stay on hot paths only when they do minimal work.
- Avoid locks in metric recording; use
Interlockedonly when app-owned state is required. - Avoid large tag sets;
Add/Recordwith three or fewer individually supplied tags is preferred for hot paths. - Keep observable callbacks fast: read cached state and return measurements. Do not perform I/O, database calls, service calls, or blocking work.
- Do not register custom
MeterListeneraggregation in Monica modules unless explicitly designing a collector.
Host Configuration Boundary
Monica modules should document the meter name and emit metrics. A host can subscribe with OpenTelemetry:
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddMeter(RepositoryPersistenceMetricNames.MeterName);
metrics.AddPrometheusExporter();
});The host maps scraping/export endpoints and configures storage/UI. Monica infrastructure modules do not.
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.

