Skip to content

Conversation

@carloshernandez2
Copy link
Contributor

@carloshernandez2 carloshernandez2 commented Dec 18, 2025

Add OpenTelemetry Metrics Support

Summary

Extends the existing otlp exporter to support OpenTelemetry metrics in addition to logs. This enables efficient aggregation, querying, and analysis of REPL usage patterns.

Motivation

While the existing otlp exporter sends data as OpenTelemetry logs, metrics are better suited for:

  • Aggregation and querying: Counters with labels enable efficient filtering and grouping
  • Performance: Metrics are optimized for time-series data and queries
  • Analysis: Session duration, operation frequency, and usage patterns can be calculated using PromQL
  • Dashboards: Native support for visualization in Grafana and similar tools

Implementation

Unified OTLP Exporter

The otlp exporter now supports both logs and metrics:

  • Exports a single counter: metrepl.events.total
  • Uses labels/attributes for dimensions:
    • :metric - Event type (e.g., :event/op-completed)
    • :operation - REPL operation name (e.g., "eval") - only present for operation events
    • :correlation-id - Session identifier for grouping related events
    • System attributes: :hostname, :os, etc.

Users control which signals are exported via standard OpenTelemetry configuration:

  • "otel.logs.exporter" - logs export control
  • "otel.metrics.exporter" - metrics export control

Changes

Backward Compatibility

  • Existing :otlp config key preserved (no breaking changes)
  • Default configuration exports logs only (existing behavior)
  • All existing configurations continue to work unchanged
  • Users opt-in to metrics by configuring "otel.metrics.exporter": "otlp"

Testing

To test the metrics exporter, create .metrepl.edn:

{:exporters {:otlp {:enabled? true
                    :config {"otel.logs.exporter" "none"
                             "otel.metrics.exporter" "otlp"
                             "otel.exporter.otlp.metrics.protocol" "http/protobuf"
                             "otel.exporter.otlp.metrics.endpoint" "https://your-endpoint/metrics"}}}}

Tested with real project REPL sessions. Both logs and metrics successfully exported and visible in Grafana.

Screenshot 2025-12-18 at 2 47 01 PM Screenshot 2025-12-19 at 3 11 53 PM

@carloshernandez2 carloshernandez2 marked this pull request as ready for review December 18, 2025 19:53
Copy link
Owner

@ericdallo ericdallo left a comment

Choose a reason for hiding this comment

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

Thank you for the help!
I'm not sure it makes sense to add another exporter just because of a specific existing one config, I think we should keep using otlp and user can override its config to :

:config {"otel.logs.exporter"  "none"
     "otel.metrics.exporter" "otlp" 

WDYT?

@carloshernandez2
Copy link
Contributor Author

carloshernandez2 commented Dec 19, 2025

I believe it makes sense. I initially thought it could be a bit awkward given the config structure (enabled flag and stuff) and that it might introduce coupling. But thinking it over I agree with you, the OTLP lib config structure looks flexible enough.

Copy link
Owner

@ericdallo ericdallo left a comment

Choose a reason for hiding this comment

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

Looks good!

@ericdallo ericdallo merged commit 641fda9 into ericdallo:master Dec 19, 2025
2 checks passed
@carloshernandez2 carloshernandez2 deleted the feature/otlp-metrics branch January 9, 2026 13:25
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