Skip to content

Commit b1adf31

Browse files
jchrostek-ddclaude
andcommitted
refactor(otlp): remove redundant should_enable_otlp_agent function
Simplify enablement logic by using only should_enable_http and should_enable_grpc functions directly. The combined check is now inlined in start_otlp_agent. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d585b68 commit b1adf31

2 files changed

Lines changed: 20 additions & 31 deletions

File tree

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use bottlecap::{
5454
},
5555
otlp::{
5656
agent::Agent as OtlpAgent, grpc_agent::GrpcAgent as OtlpGrpcAgent, should_enable_grpc,
57-
should_enable_http, should_enable_otlp_agent,
57+
should_enable_http,
5858
},
5959
proxy::{interceptor, should_start_proxy},
6060
secrets::decrypt,
@@ -1357,13 +1357,17 @@ fn start_otlp_agent(
13571357
trace_tx: Sender<SendDataBuilderInfo>,
13581358
stats_concentrator: StatsConcentratorHandle,
13591359
) -> Option<CancellationToken> {
1360-
if !should_enable_otlp_agent(config) {
1360+
let http_enabled = should_enable_http(config);
1361+
let grpc_enabled = should_enable_grpc(config);
1362+
1363+
if !http_enabled && !grpc_enabled {
13611364
return None;
13621365
}
1366+
13631367
let stats_generator = Arc::new(StatsGenerator::new(stats_concentrator));
13641368

13651369
// Start HTTP agent if configured
1366-
if should_enable_http(config) {
1370+
if http_enabled {
13671371
let agent = OtlpAgent::new(
13681372
config.clone(),
13691373
tags_provider.clone(),
@@ -1380,7 +1384,7 @@ fn start_otlp_agent(
13801384
}
13811385

13821386
// Start gRPC agent if configured
1383-
let grpc_cancel_token = if should_enable_grpc(config) {
1387+
let grpc_cancel_token = if grpc_enabled {
13841388
let grpc_agent = OtlpGrpcAgent::new(
13851389
config.clone(),
13861390
tags_provider,

bottlecap/src/otlp/mod.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ pub mod grpc_agent;
77
pub mod processor;
88
pub mod transform;
99

10-
/// Check if any OTLP agent (HTTP or gRPC) should be enabled.
11-
#[must_use]
12-
pub fn should_enable_otlp_agent(config: &Arc<Config>) -> bool {
13-
config.otlp_config_traces_enabled
14-
&& (config
15-
.otlp_config_receiver_protocols_http_endpoint
16-
.is_some()
17-
|| config
18-
.otlp_config_receiver_protocols_grpc_endpoint
19-
.is_some())
20-
}
21-
2210
/// Check if the HTTP OTLP agent should be enabled.
2311
#[must_use]
2412
pub fn should_enable_http(config: &Arc<Config>) -> bool {
@@ -46,7 +34,7 @@ mod tests {
4634
use crate::config::get_config;
4735

4836
#[test]
49-
fn test_should_enable_otlp_agent_from_yaml() {
37+
fn test_should_enable_http_from_yaml() {
5038
figment::Jail::expect_with(|jail| {
5139
jail.clear_env();
5240
jail.create_file(
@@ -60,35 +48,35 @@ mod tests {
6048
",
6149
)?;
6250

63-
let config = get_config(Path::new(""));
51+
let config = Arc::new(get_config(Path::new("")));
6452

65-
// Since the default for traces is `true`, we don't need to set it.
66-
assert!(should_enable_otlp_agent(&Arc::new(config)));
53+
assert!(should_enable_http(&config));
54+
assert!(!should_enable_grpc(&config));
6755

6856
Ok(())
6957
});
7058
}
7159

7260
#[test]
73-
fn test_should_enable_otlp_agent_from_env_vars() {
61+
fn test_should_enable_http_from_env_vars() {
7462
figment::Jail::expect_with(|jail| {
7563
jail.clear_env();
7664
jail.set_env(
7765
"DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_HTTP_ENDPOINT",
7866
"0.0.0.0:4318",
7967
);
8068

81-
let config = get_config(Path::new(""));
69+
let config = Arc::new(get_config(Path::new("")));
8270

83-
// Since the default for traces is `true`, we don't need to set it.
84-
assert!(should_enable_otlp_agent(&Arc::new(config)));
71+
assert!(should_enable_http(&config));
72+
assert!(!should_enable_grpc(&config));
8573

8674
Ok(())
8775
});
8876
}
8977

9078
#[test]
91-
fn test_should_not_enable_otlp_agent_if_traces_are_disabled() {
79+
fn test_should_not_enable_http_if_traces_disabled() {
9280
figment::Jail::expect_with(|jail| {
9381
jail.clear_env();
9482
jail.set_env("DD_OTLP_CONFIG_TRACES_ENABLED", "false");
@@ -97,16 +85,16 @@ mod tests {
9785
"0.0.0.0:4318",
9886
);
9987

100-
let config = get_config(Path::new(""));
88+
let config = Arc::new(get_config(Path::new("")));
10189

102-
assert!(!should_enable_otlp_agent(&Arc::new(config)));
90+
assert!(!should_enable_http(&config));
10391

10492
Ok(())
10593
});
10694
}
10795

10896
#[test]
109-
fn test_should_enable_otlp_agent_with_grpc_endpoint() {
97+
fn test_should_enable_grpc_from_env_vars() {
11098
figment::Jail::expect_with(|jail| {
11199
jail.clear_env();
112100
jail.set_env(
@@ -116,7 +104,6 @@ mod tests {
116104

117105
let config = Arc::new(get_config(Path::new("")));
118106

119-
assert!(should_enable_otlp_agent(&config));
120107
assert!(should_enable_grpc(&config));
121108
assert!(!should_enable_http(&config));
122109

@@ -139,7 +126,6 @@ mod tests {
139126

140127
let config = Arc::new(get_config(Path::new("")));
141128

142-
assert!(should_enable_otlp_agent(&config));
143129
assert!(should_enable_http(&config));
144130
assert!(should_enable_grpc(&config));
145131

@@ -159,7 +145,6 @@ mod tests {
159145

160146
let config = Arc::new(get_config(Path::new("")));
161147

162-
assert!(!should_enable_otlp_agent(&config));
163148
assert!(!should_enable_grpc(&config));
164149

165150
Ok(())

0 commit comments

Comments
 (0)