Skip to content

fix(otel): use monotonic_counter prefix and support temporality env var#7234

Merged
michaelneale merged 1 commit intomainfrom
adrian/metrics
Feb 16, 2026
Merged

fix(otel): use monotonic_counter prefix and support temporality env var#7234
michaelneale merged 1 commit intomainfrom
adrian/metrics

Conversation

@codefromthecrypt
Copy link
Collaborator

Summary

This fixes a regression where most (not all) otel metrics were accidentally changed from monotonic_counter. to counter. and adds ENV support for metrics temporality preference.

The regression is subtle but made the metrics practically unusable for the things you'd actually want (rates, alerts, per-minute breakdowns).
For example, when monotonic a counter becomes a Prometheus counter, suppporting rate() and increase(), allowing you to build dashbaords like "tool calls per minute" or "sessions per hour".

Similar to our other ENV, this adds support for OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE
The default temporarilty is cumulative, which on export sends the total since the process start.
Backends who compute deltas internally, like Prometheus, expect this default.

delta only sends the delta since the last export, which is needed for backends like Elastic Stack and otel-tui.
When this isn't configurable, metrics are counted incorrectly, a total mistaken for a delta. This makes the metrics unusable.

Type of Change

  • Bug fix

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

  • New temporality_preference_from_env parameterized tests

Related Issues

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Copilot AI review requested due to automatic review settings February 15, 2026 15:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical regression where most OTel metrics were accidentally changed from monotonic_counter. to counter. prefix, which broke Prometheus counter functionality (rate() and increase() functions). It also adds environment variable support for configuring metrics temporality preference via OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE.

Changes:

  • Corrected metric prefix from counter. back to monotonic_counter. across all telemetry instrumentation points
  • Added temporality preference configuration via environment variable with support for delta, cumulative, and lowmemory modes
  • Comprehensive parameterized tests for temporality preference parsing

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/goose/src/otel/otlp.rs Added temporality_preference() function to read ENV var, applied temporality to OTLP metrics exporter, added comprehensive test coverage
crates/goose/src/security/mod.rs Fixed metric prefixes from counter. to monotonic_counter. for security scanner metrics (5 locations)
crates/goose/src/agents/tool_execution.rs Fixed metric prefix for prompt_injection_user_decisions counter
crates/goose-server/src/routes/schedule.rs Fixed metric prefix for recipe_runs counter
crates/goose-server/src/routes/reply.rs Fixed metric prefixes for session and tool metrics (7 locations)
crates/goose-cli/src/session/mod.rs Fixed metric prefixes for tool_calls and tool_completions counters
crates/goose-cli/src/cli.rs Fixed metric prefixes for session and CLI command metrics (7 locations)

@michaelneale michaelneale added this pull request to the merge queue Feb 16, 2026
Merged via the queue into main with commit 4a5848e Feb 16, 2026
36 of 39 checks passed
@michaelneale michaelneale deleted the adrian/metrics branch February 16, 2026 21:54
michaelneale added a commit that referenced this pull request Feb 17, 2026
* main:
  fix: handle reasoning_content for Kimi/thinking models (#7252)
  feat: sandboxing for macos (#7197)
  fix(otel): use monotonic_counter prefix and support temporality env var (#7234)
  Streaming markdown (#7233)
  Improve compaction messages to enable better post-compaction agent behavior (#7259)
  fix: avoid shell-escaping special characters except quotes (#7242)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants