feat: OTLP metrics export for low-cardinality business outcomes - #793
Merged
Conversation
Add MeterProvider/OTLP HTTP metrics alongside traces and logs, and emit cheap scrape, store sync, sitespeed, mail, and notify outcome counters so Datadog can alert without scanning high-volume APM spans. Co-authored-by: Soner <github@shyim.de>
shyim
marked this pull request as ready for review
August 12, 2026 06:04
Contributor
Greptile SummaryThis PR adds optional OTLP HTTP metric export and bounded business-outcome counters for scrapes, store synchronization, sitespeed checks, mail, and notification delivery.
Confidence Score: 5/5The PR appears safe to merge; no concrete blocking or independently actionable non-blocking defects were identified. Metrics-only configuration reaches provider registration correctly, disabled telemetry remains a safe no-op, outcome branches avoid duplicate counts, and attribute normalization keeps the new series bounded.
|
| Filename | Overview |
|---|---|
| api/internal/telemetry/telemetry.go | Adds optional OTLP metrics exporter setup, global provider registration, and coordinated shutdown. |
| api/internal/metrics/metrics.go | Defines thread-safe outcome counters with strict enum normalization to bound cardinality. |
| api/internal/monitoring/scrape/service.go | Records one scrape outcome for lookup failures, normal completion, authentication failures, data-fetch failures, and returned errors. |
| api/internal/catalog/sync/service.go | Records store-sync outcomes while intentionally excluding freshness no-ops and distinguishing rate limits. |
| api/internal/monitoring/sitespeed/service.go | Records sitespeed success, error, and configuration-skip outcomes across current return paths. |
| api/internal/notify/dispatcher.go | Records per-channel notification delivery outcomes without double-counting failed sends. |
| api/internal/mail/mail.go | Records SMTP send outcomes without recipient-derived attributes. |
| api/internal/config/config.go | Adds metrics-specific OTLP endpoint configuration with generic endpoint fallback. |
| api/telemetry.go | Propagates the configured metrics endpoint into telemetry setup. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Config["OTLP environment configuration"] --> Setup["telemetry.Setup"]
Setup --> Provider["OTLP MeterProvider"]
Provider --> Register["metrics.Register"]
Register --> Counters["Bounded outcome counters"]
Scrape["Environment scrape"] --> Counters
StoreSync["Store catalog sync"] --> Counters
Sitespeed["Sitespeed scrape"] --> Counters
Mail["Mail send"] --> Counters
Notify["Notification delivery"] --> Counters
Counters --> Collector["OTLP collector"]
Reviews (1): Last reviewed commit: "feat: export OTLP metrics for low-cardin..." | Re-trigger Greptile
This was referenced Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Datadog monitors that scan millions of APM spans for SES 451s, Store API 429s, scrape failures, or Sitespeed errors are expensive and noisy. Cheap OTLP outcome counters with tiny enum labels let us alert on business results without high-cardinality span queries.
What
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, falling back toOTEL_EXPORTER_OTLP_ENDPOINTlike traces/logs). Empty endpoint keeps metrics disabled (no-op meters).api/internal/metricshelpers that register instruments after the MeterProvider is installed, and coerce unexpected attribute values tounknownso cardinality stays bounded.shopmon.scrape.outcomeoutcomeok,error,auth_error,data_fetch_errorshopmon.store_sync.outcomeoutcomeok,rate_limited,error(no-op freshness skips not counted)shopmon.sitespeed.outcomeoutcomeok,error,skippedshopmon.mail.sendoutcomeok,error(no recipient addresses)shopmon.notify.deliveryoutcome,channelok/error×email/in_appConfig
Out of scope
HTTP span renaming (separate PR).
Test plan
mise run lint(API + frontend)mise run test