Skip to content

integrate promotheus and opentelemtry - #3

Merged
Ret2Hell merged 4 commits into
mainfrom
dev
Mar 18, 2026
Merged

Ret2Hell merged 4 commits into
mainfrom
dev

Conversation

@Ret2Hell

@Ret2Hell Ret2Hell commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • OpenTelemetry tracing with graceful tracer shutdown and request-level spans
    • Prometheus metrics endpoint (/metrics) exposing ingestion, rejection, deduplication, latency, batch size, and error metrics
    • Instrumentation across the ingestion flow to emit per-batch and per-event metrics
  • Chores

    • Added OTLP exporter endpoint configuration (OTEL_EXPORTER_OTLP_ENDPOINT)
    • Dependency updates to support tracing and metrics features

@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 9d555fec-174f-47f7-a822-7f7b53d9498e

📥 Commits

Reviewing files that changed from the base of the PR and between 76eed6d and 5a10422.

📒 Files selected for processing (1)
  • internal/observability/tracing.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/observability/tracing.go

📝 Walkthrough

Walkthrough

Adds OpenTelemetry tracing and Prometheus metrics: new OTLP endpoint config, tracer initialization and shutdown, a Prometheus IngestMetrics type, wiring of metrics/tracing into server and handler (including /metrics endpoint), and dependency updates.

Changes

Cohort / File(s) Summary
Configuration & Modules
/.env.example, go.mod, internal/config/config.go
Adds OTEL_EXPORTER_OTLP_ENDPOINT to example env, exposes OTelEndpoint in IngestConfig, and updates go.mod to include OpenTelemetry and Prometheus-related dependencies.
Observability Core
internal/observability/metrics.go, internal/observability/tracing.go
Adds IngestMetrics (Prometheus counters/histograms) and NewIngestMetrics(), and adds InitTracer(ctx, serviceName, otlpEndpoint) (func(), error) to initialize an OTLP HTTP exporter and set the global tracer provider.
Server & Handler Integration
cmd/ingest/main.go, internal/server/server.go, internal/server/handler.go
Initializes tracer at startup with shutdown, creates IngestMetrics, updates NewServer and NewIngestHandler signatures to accept metrics, wires metrics and tracing into request handling, and exposes the /metrics endpoint.

Sequence Diagram

sequenceDiagram
    participant C as Client
    participant S as Server (Fiber)
    participant H as IngestHandler
    participant T as Tracer (OTel)
    participant M as IngestMetrics (Prometheus)
    participant P as Redpanda Producer
    participant R as Prometheus (scraper)

    C->>S: POST /events
    S->>H: forward request
    H->>T: Start span (ctx)
    T-->>H: span context
    H->>M: Observe BatchSize
    alt validation fails
        H->>M: Increment EventsRejected(reason)
        H-->>C: 4xx
    else validation passes
        H->>H: dedup checks
        alt dedup error
            H->>M: Increment DedupErrors
        else duplicate
            H->>M: Increment EventsDeduplicated
        end
        H->>P: Produce events
        alt produce fails
            H->>M: Increment ProduceErrors
            H-->>C: 5xx
        else produce succeeds
            H->>M: Increment EventsIngested (per-site)
            H->>M: Observe IngestLatency
            H-->>C: 2xx
        end
    end
    H->>T: End span
    R->>M: Scrape /metrics
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I traced each hop and counted each cheer,
Buckets and counters make metrics clear,
I start a span, then watch them grow,
Prometheus hums, OTLP flows,
Hop-hop—observability in gear!

📝 Coding Plan
  • Generate coding plan for human review comments

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@Ret2Hell
Ret2Hell merged commit d2415be into main Mar 18, 2026
4 checks passed
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.

1 participant