feat: adds http metrics to OTEL - #4294
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds explicit HTTP body-size histogram buckets and two new histograms, implements OtelPlugin.RecordHTTPMetrics to record request count, duration, and optional sizes, wires a server middleware to capture per-request timing and sizes and call the new method, and updates docs to list the new metrics. ChangesHTTP Metrics Recording Integration
Sequence DiagramsequenceDiagram
participant HTTPRequest
participant ServerMiddleware
participant OtelPlugin
participant MetricsExporter
HTTPRequest->>ServerMiddleware: incoming request
activate ServerMiddleware
ServerMiddleware->>ServerMiddleware: capture start time, content-length
ServerMiddleware->>ServerMiddleware: execute handler, capture response status and size
ServerMiddleware->>OtelPlugin: RecordHTTPMetrics(path, method, status, duration, requestSize, responseSize)
activate OtelPlugin
OtelPlugin->>OtelPlugin: build HTTP attributes
OtelPlugin->>MetricsExporter: record metrics for active targets
deactivate OtelPlugin
ServerMiddleware->>HTTPRequest: return response
deactivate ServerMiddleware
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/features/observability/otel.mdx`:
- Around line 944-945: The table entries for `http_request_size_bytes` and
`http_response_size_bytes` don't mention that sizes are only recorded when
Content-Length is known (fasthttp reports -1 otherwise); update the
documentation to clarify this by modifying the descriptions for those two
metrics to something like "HTTP request body size (when Content-Length is
present)" and/or add a short callout below the table stating "Note: Size metrics
are only recorded when the Content-Length header is present; requests without
Content-Length (e.g., chunked transfer) will not produce data points in these
histograms."
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 84286416-735c-4234-a23f-e350782f496e
📒 Files selected for processing (3)
docs/features/observability/otel.mdxplugins/otel/main.gotransports/bifrost-http/server/server.go
Confidence Score: 4/5Safe to merge for the OTel metrics feature; the bundled migration is functionally correct but performs a full-table UPDATE without batching. The OTel plugin and server middleware changes are straightforward and correct — size guards, histogram boundaries, and per-request plugin resolution all look right. The one concern is in the bundled migration: the final framework/configstore/migrations.go — the final bulk UPDATE in Important Files Changed
Reviews (4): Last reviewed commit: "feat: adds http metrics to OTEL" | Re-trigger Greptile |
e69befb to
3d6a2dd
Compare
Merge activity
|
066504c to
8865f7c
Compare
3d6a2dd to
069a2a9
Compare
## Summary Adds `http_request_size_bytes` and `http_response_size_bytes` histogram metrics to the OTel plugin, giving operators visibility into HTTP payload sizes alongside the existing request count and duration metrics. ## Changes - Added `RecordHTTPMetrics` method to `OtelPlugin` that records request count, duration, and request/response body sizes in a single call. Non-positive sizes (e.g. `-1` when `Content-Length` is unknown in fasthttp) are skipped to avoid polluting histograms with sentinel values. - Added an OTel HTTP metrics middleware in `PrepareCommonMiddlewares` that captures request size before the handler runs, then resolves the OTel plugin instance after the response is complete. The plugin is resolved per-request rather than captured at startup to avoid recording against stale meter providers after a config reload. - Documented the two new metrics (`http_request_size_bytes`, `http_response_size_bytes`) in the OTel observability reference docs. ## Type of change - [ ] Bug fix - [x] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [x] Docs ## How to test Start Bifrost with an OTel plugin configured and a metrics exporter pointing at an OTLP-compatible backend (e.g. Prometheus via the OTLP receiver or an OTel Collector). Send a few HTTP requests and verify the following metrics appear with `path`, `method`, and `status` labels: ```sh # Example: query Prometheus curl -s http://localhost:9090/api/v1/query?query=http_request_size_bytes_bucket | jq . curl -s http://localhost:9090/api/v1/query?query=http_response_size_bytes_bucket | jq . ``` Confirm that requests without a `Content-Length` header (size reported as `-1` by fasthttp) do **not** produce a data point in `http_request_size_bytes`. ```sh go test ./plugins/otel/... ./transports/bifrost-http/... ``` ## Screenshots/Recordings N/A ## Breaking changes - [x] No ## Related issues N/A ## Security considerations No new auth, secrets, or PII surface. Request and response sizes are recorded as numeric values only; no body content is captured. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [x] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * HTTP request and response body size histograms are now collected and exported via OpenTelemetry with explicit bucket boundaries; sizes are recorded only when Content-Length is present. * Per-request metrics now include counts, durations, and conditional payload-size measurements to improve request observability. * **Documentation** * Observability docs updated to describe the new size histograms and their recording conditions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->

Summary
Adds
http_request_size_bytesandhttp_response_size_byteshistogram metrics to the OTel plugin, giving operators visibility into HTTP payload sizes alongside the existing request count and duration metrics.Changes
RecordHTTPMetricsmethod toOtelPluginthat records request count, duration, and request/response body sizes in a single call. Non-positive sizes (e.g.-1whenContent-Lengthis unknown in fasthttp) are skipped to avoid polluting histograms with sentinel values.PrepareCommonMiddlewaresthat captures request size before the handler runs, then resolves the OTel plugin instance after the response is complete. The plugin is resolved per-request rather than captured at startup to avoid recording against stale meter providers after a config reload.http_request_size_bytes,http_response_size_bytes) in the OTel observability reference docs.Type of change
Affected areas
How to test
Start Bifrost with an OTel plugin configured and a metrics exporter pointing at an OTLP-compatible backend (e.g. Prometheus via the OTLP receiver or an OTel Collector).
Send a few HTTP requests and verify the following metrics appear with
path,method, andstatuslabels:Confirm that requests without a
Content-Lengthheader (size reported as-1by fasthttp) do not produce a data point inhttp_request_size_bytes.go test ./plugins/otel/... ./transports/bifrost-http/...Screenshots/Recordings
N/A
Breaking changes
Related issues
N/A
Security considerations
No new auth, secrets, or PII surface. Request and response sizes are recorded as numeric values only; no body content is captured.
Checklist
docs/contributing/README.mdand followed the guidelinesSummary by CodeRabbit
New Features
Documentation