agentleFS
triggerdotdevtriggerdotdev/trigger.dev/.cursor/rules/otel-metrics.mdc

trigger.dev / rules

Cursor rule16k starsChanged 4 months agoApache-2.0View on GitHub

Guidelines for creating OpenTelemetry metrics to avoid cardinality issues

Trending

More talk lately.about the whole repository

Dec 2025: 1 mentionJan 2026: 1 mentionFeb 2026: 1 mentionMar 2026: 0 mentionsApr 2026: 1 mentionMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 10 mentionsOct 2026: 34 mentionsNov 2026: 3 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the triggerdotdev/trigger.dev repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about triggerdotdev/trigger.dev

The biggest 5 of 60 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 60

Talked about on GitHub and Bluesky (60 times).

On GitHub · 50

45 more on GitHub

On Bluesky · 10

5 more on Bluesky

The file

We split this otel-metrics.mdc into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When creating or editing OTEL metrics (counters, histograms, gauges), always ensure metric attributes have low cardinality.

    line 9
  2. Distinctive:

    Shard IDs: When sharding is bounded (e.g., 0-15)

    line 21
  3. Distinctive:

    When metrics are exported via OTLP to Prometheus, the exporter automatically adds unit suffixes to metric names:

    line 47
  4. Distinctive:

    Keep this in mind when writing Grafana dashboards or Prometheus queries—the metric names in Prometheus will differ from the names defined …

    line 56

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
otel-metrics.mdc
---
description: Guidelines for creating OpenTelemetry metrics to avoid cardinality issues
globs:
  - "**/*.ts"
---

# OpenTelemetry Metrics Guidelines

When creating or editing OTEL metrics (counters, histograms, gauges), always ensure metric attributes have **low cardinality**.

## What is Cardinality?

Cardinality refers to the number of unique values an attribute can have. Each unique combination of attribute values creates a new time series, which consumes memory and storage in your metrics backend.

## Rules

### DO use low-cardinality attributes:
- **Enums**: `environment_type` (PRODUCTION, STAGING, DEVELOPMENT, PREVIEW)
- **Booleans**: `hasFailures`, `streaming`, `success`
- **Bounded error codes**: A finite, controlled set of error types
- **Shard IDs**: When sharding is bounded (e.g., 0-15)

### DO NOT use high-cardinality attributes:
- **UUIDs/IDs**: `envId`, `userId`, `runId`, `projectId`, `organizationId`
- **Unbounded integers**: `itemCount`, `batchSize`, `retryCount`
- **Timestamps**: `createdAt`, `startTime`
- **Free-form strings**: `errorMessage`, `taskName`, `queueName`

## Example

```typescript
// BAD - High cardinality
this.counter.add(1, {
  envId: options.environmentId,        // UUID - unbounded
  itemCount: options.runCount,         // Integer - unbounded
});

// GOOD - Low cardinality
this.counter.add(1, {
  environment_type: options.environmentType,  // Enum - 4 values
  streaming: true,                            // Boolean - 2 values
});
```

## Prometheus Metric Naming

When metrics are exported via OTLP to Prometheus, the exporter automatically adds unit suffixes to metric names:

| OTel Metric Name | Unit | Prometheus Name |
|------------------|------|-----------------|
| `my_duration_ms` | `ms` | `my_duration_ms_milliseconds` |
| `my_counter` | counter | `my_counter_total` |
| `items_inserted` | counter | `items_inserted_inserts_total` |
| `batch_size` | histogram | `batch_size_items_bucket` |

Keep this in mind when writing Grafana dashboards or Prometheus queries—the metric names in Prometheus will differ from the names defined in code.

## Reference

See the schedule engine (`internal-packages/schedule-engine/src/engine/index.ts`) for a good example of low-cardinality metric attributes.

High cardinality metrics can cause:
- Memory bloat in metrics backends (Axiom, Prometheus, etc.)
- Slow queries and dashboard timeouts
- Increased costs (many backends charge per time series)
- Potential data loss or crashes at scale

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.