Skip to content

Conversation

@uddhavdave
Copy link
Contributor

@uddhavdave uddhavdave commented Nov 27, 2025

adding headers to multiple endpoints for usage reporting

@github-actions github-actions bot added ☢️ Bug Something isn't working ✏️ Feature labels Nov 27, 2025
@github-actions
Copy link
Contributor

Failed to generate code suggestions for PR

@uddhavdave uddhavdave marked this pull request as ready for review November 27, 2025 12:38
@github-actions
Copy link
Contributor

Failed to generate code suggestions for PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 27, 2025

Greptile Overview

Greptile Summary

This PR systematically adds user email tracking to metrics and traces ingestion endpoints for usage reporting purposes. The changes thread a user_email parameter through the entire ingestion pipeline, from HTTP/gRPC handlers down to service layer functions.

Key Changes:

  • HTTP handlers now use the Headers<UserEmail> extractor to capture the user_id header
  • gRPC handlers extract user_id from request metadata
  • RUM endpoints have special handling via validator_rum which fetches the user by token and injects the user_id header
  • Service layer functions (metrics::json::ingest, metrics::otlp::handle_otlp_request, traces::handle_otlp_request, etc.) now accept a user_email parameter
  • Internal/system-generated ingestion (like self-metrics) correctly passes empty strings, which are converted to None in req_stats.user_email
  • The user_email field is properly assigned to RequestStats for usage reporting

Implementation Pattern:
The implementation consistently handles empty strings by checking if user_email.is_empty() and setting req_stats.user_email to None for empty values, or Some(user_email.to_string()) otherwise. This ensures clean data in usage reports.

Confidence Score: 5/5

  • This PR is safe to merge with no critical issues found
  • The changes are straightforward parameter additions that thread user email through the ingestion pipeline. The implementation is consistent across all endpoints, properly handles empty strings, and maintains backward compatibility by providing empty strings for internal/system ingestion. All changes follow the existing codebase patterns.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/handler/http/auth/validator.rs 5/5 Added logic to fetch user by token and inject user_id header with email for RUM endpoints to enable usage tracking
src/handler/http/request/metrics/ingest.rs 5/5 Uses Headers extractor to capture UserEmail from headers and passes it to JSON and OTLP metrics ingestion functions
src/handler/http/request/rum/ingest.rs 5/5 Extracts user_id header from HttpRequest and passes to RUM data, log, and session replay ingestion endpoints
src/handler/http/request/traces/mod.rs 5/5 Added Headers extractor to capture UserEmail and threads it through to OTLP trace handlers (both protobuf and JSON)
src/service/metrics/otlp.rs 5/5 Added user_email parameter to otlp_proto, otlp_json, and handle_otlp_request functions, properly assigning to req_stats for usage tracking
src/service/traces/mod.rs 5/5 Adds user_email parameter across otlp_proto, otlp_json, handle_otlp_request, ingest_json, and write_traces_by_stream, properly threading through to req_stats

Sequence Diagram

sequenceDiagram
    participant Client
    participant HTTPHandler
    participant GRPCHandler
    participant AuthValidator
    participant HeadersExtractor
    participant ServiceLayer
    participant UsageReporting

    Note over Client,UsageReporting: HTTP Request Flow (Metrics/Traces)
    Client->>HTTPHandler: POST /org/v1/metrics (with Auth)
    HTTPHandler->>HeadersExtractor: Extract UserEmail from headers
    HeadersExtractor->>HeadersExtractor: Deserialize user_id header
    HeadersExtractor-->>HTTPHandler: UserEmail struct
    HTTPHandler->>ServiceLayer: ingest(org_id, body, user_email)
    ServiceLayer->>ServiceLayer: Process data & create req_stats
    ServiceLayer->>ServiceLayer: req_stats.user_email = Some(user_email)
    ServiceLayer->>UsageReporting: report_request_usage_stats(req_stats)
    UsageReporting-->>Client: Response

    Note over Client,UsageReporting: gRPC Request Flow
    Client->>GRPCHandler: Export(request, metadata)
    GRPCHandler->>GRPCHandler: Extract user_id from metadata
    GRPCHandler->>ServiceLayer: handle_otlp_request(org_id, req, type, user_email)
    ServiceLayer->>ServiceLayer: Process & assign req_stats.user_email
    ServiceLayer->>UsageReporting: report_request_usage_stats(req_stats)
    UsageReporting-->>Client: Response

    Note over Client,UsageReporting: RUM Request Flow (with Validator)
    Client->>AuthValidator: POST /v1/org/rum (with token)
    AuthValidator->>AuthValidator: Validate token
    AuthValidator->>AuthValidator: get_user_by_token()
    AuthValidator->>AuthValidator: Inject user_id header with email
    AuthValidator->>HTTPHandler: Forward with user_id header
    HTTPHandler->>HTTPHandler: Extract user_id from headers
    HTTPHandler->>ServiceLayer: logs ingest with user_email
    ServiceLayer->>UsageReporting: report_request_usage_stats(req_stats)
    UsageReporting-->>Client: Response

    Note over Client,UsageReporting: Internal/System Flow
    HTTPHandler->>ServiceLayer: self-metrics ingest with empty string
    ServiceLayer->>ServiceLayer: req_stats.user_email = None
    ServiceLayer->>UsageReporting: report_request_usage_stats(req_stats)

Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

13 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@YashodhanJoshi1 YashodhanJoshi1 left a comment

Choose a reason for hiding this comment

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

lgtm with a small nit

@uddhavdave uddhavdave merged commit e5284b8 into main Nov 28, 2025
37 of 43 checks passed
@uddhavdave uddhavdave deleted the ud/user-email-reporting branch November 28, 2025 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working ✏️ Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants