Skip to content

Commit bac6ccb

Browse files
authored
chore: consolidate agent code for otlp (#1132)
## 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<u16> 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.
1 parent 54ddaab commit bac6ccb

File tree

5 files changed

+312
-471
lines changed

5 files changed

+312
-471
lines changed

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ use bottlecap::{
5252
},
5353
flusher::LogsFlusher,
5454
},
55-
otlp::{
56-
agent::Agent as OtlpAgent, grpc_agent::GrpcAgent as OtlpGrpcAgent, should_enable_otlp_grpc,
57-
should_enable_otlp_http,
58-
},
55+
otlp::{agent::Agent as OtlpAgent, should_enable_otlp_agent},
5956
proxy::{interceptor, should_start_proxy},
6057
secrets::decrypt,
6158
tags::{
@@ -1357,49 +1354,27 @@ fn start_otlp_agent(
13571354
trace_tx: Sender<SendDataBuilderInfo>,
13581355
stats_concentrator: StatsConcentratorHandle,
13591356
) -> Option<CancellationToken> {
1360-
let http_enabled = should_enable_otlp_http(config);
1361-
let grpc_enabled = should_enable_otlp_grpc(config);
1362-
1363-
if !http_enabled && !grpc_enabled {
1357+
if !should_enable_otlp_agent(config) {
13641358
return None;
13651359
}
13661360

13671361
let stats_generator = Arc::new(StatsGenerator::new(stats_concentrator));
13681362
let cancel_token = CancellationToken::new();
13691363

1370-
if http_enabled {
1371-
let agent = OtlpAgent::new(
1372-
config.clone(),
1373-
tags_provider.clone(),
1374-
trace_processor.clone(),
1375-
trace_tx.clone(),
1376-
stats_generator.clone(),
1377-
cancel_token.clone(),
1378-
);
1379-
1380-
tokio::spawn(async move {
1381-
if let Err(e) = agent.start().await {
1382-
error!("Error starting OTLP HTTP agent: {e:?}");
1383-
}
1384-
});
1385-
}
1386-
1387-
if grpc_enabled {
1388-
let grpc_agent = OtlpGrpcAgent::new(
1389-
config.clone(),
1390-
tags_provider,
1391-
trace_processor,
1392-
trace_tx,
1393-
stats_generator,
1394-
cancel_token.clone(),
1395-
);
1364+
let agent = OtlpAgent::new(
1365+
config.clone(),
1366+
tags_provider,
1367+
trace_processor,
1368+
trace_tx,
1369+
stats_generator,
1370+
cancel_token.clone(),
1371+
);
13961372

1397-
tokio::spawn(async move {
1398-
if let Err(e) = grpc_agent.start().await {
1399-
error!("Error starting OTLP gRPC agent: {e:?}");
1400-
}
1401-
});
1402-
}
1373+
tokio::spawn(async move {
1374+
if let Err(e) = agent.start().await {
1375+
error!("Error starting OTLP agent: {e:?}");
1376+
}
1377+
});
14031378

14041379
Some(cancel_token)
14051380
}

0 commit comments

Comments
 (0)