Skip to content

chore: consolidate agent code for otlp#1132

Merged
duncanista merged 2 commits intomainfrom
jordan.gonzalez/otlp/consolidate-agent-code
Mar 27, 2026
Merged

chore: consolidate agent code for otlp#1132
duncanista merged 2 commits intomainfrom
jordan.gonzalez/otlp/consolidate-agent-code

Conversation

@duncanista
Copy link
Copy Markdown
Contributor

Overview

Consolidates the OTLP agent code by merging grpc_agent.rs into agent.rs, eliminating ~280 lines of duplicated code. A single Agent struct now owns a shared TracePipeline and starts HTTP, gRPC, or both servers based on config.

Changes

  • Introduced TracePipeline struct holding shared state (config, processor, trace channels, stats generator) with a process_and_send_traces method used by both HTTP and gRPC handlers
  • TraceService (gRPC) is implemented directly on TracePipeline, removing the redundant OtlpGrpcService struct
  • Agent now holds Option for http_port/grpc_port, spawning whichever protocols are configured
  • Collapsed should_enable_otlp_http + should_enable_otlp_grpc into a single should_enable_otlp_agent
  • Deleted grpc_agent.rs
  • Simplified start_otlp_agent in main.rs: one Agent, one spawn

Bug fixes

  • parse_port scheme handling — HTTP agent's split(':').nth(1) broke on endpoints with schemes like http://localhost:4318. Replaced with the gRPC version that strips http:///https:// prefixes and uses rsplit(':') for IPv6 support
  • Empty trace check — HTTP handler checked size_of_val(&traces) == 0, which always evaluates to false (returns the 24-byte stack size of the Vec struct). Replaced with traces.iter().all(Vec::is_empty) in the shared pipeline

Tests

Merged and deduplicated parse_port tests (gained scheme-handling coverage), consolidated enablement tests into should_enable_otlp_agent. All 28 OTLP tests pass, zero clippy warnings.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Consolidates OTLP HTTP and gRPC agent implementations into a single Agent with a shared TracePipeline, removing the standalone grpc_agent.rs and reducing duplicated trace-processing logic.

Changes:

  • Introduces TracePipeline shared between HTTP and gRPC, including a unified process_and_send_traces path.
  • Implements OTLP gRPC TraceService directly on the shared pipeline and updates Agent to spawn HTTP, gRPC, or both based on config.
  • Replaces separate enablement helpers with should_enable_otlp_agent, and simplifies OTLP agent startup in main.rs.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
bottlecap/src/otlp/mod.rs Removes separate HTTP/gRPC enablement helpers in favor of should_enable_otlp_agent and updates tests.
bottlecap/src/otlp/grpc_agent.rs Deletes the redundant gRPC agent implementation after consolidation.
bottlecap/src/otlp/agent.rs Merges HTTP+gRPC handling into one agent with a shared pipeline; adds gRPC server startup and shared processing.
bottlecap/src/bin/bottlecap/main.rs Switches OTLP startup to a single consolidated agent and enablement check.
Comments suppressed due to low confidence (1)

bottlecap/src/otlp/agent.rs:388

  • For Protobuf error responses you are encoding tonic_types::Status (google.rpc.Status), but code is being set to the HTTP status code (e.g. 500). In OTLP, this code should be a gRPC/Google RPC code (e.g. INVALID_ARGUMENT, INTERNAL), not an HTTP status value. Map StatusCode to an appropriate tonic::Code/google::rpc::Code numeric value (or omit the Protobuf body on non-OTLP-protobuf errors).
                let status = ProtoStatus {
                    code: i32::from(status_code.as_u16()),
                    message: message.clone(),
                    details: vec![],
                };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bottlecap/src/otlp/agent.rs
Comment thread bottlecap/src/otlp/agent.rs Outdated
@duncanista duncanista merged commit bac6ccb into main Mar 27, 2026
50 checks passed
@duncanista duncanista deleted the jordan.gonzalez/otlp/consolidate-agent-code branch March 27, 2026 16:39
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.

3 participants