Skip to content

Commit c68741c

Browse files
committed
Allow configuring proxy trace exporter service name
Currently, we hard-code the trace service name to "linkerd-proxy". This allows this name to be configured through an env that can be set by the injector, annotations, etc. linkerd/linkerd2#11157 Signed-off-by: Scott Fleener <[email protected]>
1 parent 8bb03cb commit c68741c

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

linkerd/app/src/env.rs

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ const ENV_OUTBOUND_DISABLE_INFORMATIONAL_HEADERS: &str =
148148

149149
pub const ENV_TRACE_ATTRIBUTES_PATH: &str = "LINKERD2_PROXY_TRACE_ATTRIBUTES_PATH";
150150
pub const ENV_TRACE_PROTOCOL: &str = "LINKERD2_PROXY_TRACE_PROTOCOL";
151+
pub const ENV_TRACE_SERVICE_NAME: &str = "LINKERD2_PROXY_TRACE_SERVICE_NAME";
151152

152153
/// Constrains which destination names may be used for profile/route discovery.
153154
///
@@ -432,6 +433,7 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
432433

433434
let trace_attributes_file_path = strings.get(ENV_TRACE_ATTRIBUTES_PATH);
434435
let trace_protocol = strings.get(ENV_TRACE_PROTOCOL);
436+
let trace_service_name = strings.get(ENV_TRACE_SERVICE_NAME);
435437

436438
let trace_collector_addr = parse_control_addr(strings, ENV_TRACE_COLLECTOR_SVC_BASE);
437439

@@ -842,9 +844,12 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
842844
.flatten()
843845
.unwrap_or_default();
844846

847+
let trace_service_name = trace_service_name.ok().flatten();
848+
845849
trace_collector::Config::Enabled(Box::new(trace_collector::EnabledConfig {
846850
attributes,
847851
hostname: hostname?,
852+
service_name: trace_service_name,
848853
control: ControlConfig {
849854
addr,
850855
connect,

linkerd/app/src/trace_collector.rs

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use tracing::info_span;
1111
pub mod oc_collector;
1212
pub mod otel_collector;
1313

14+
const SERVICE_NAME: &str = "linkerd-proxy";
15+
1416
#[derive(Clone, Debug)]
1517
pub enum Config {
1618
Disabled,
@@ -22,6 +24,7 @@ pub struct EnabledConfig {
2224
pub control: control::Config,
2325
pub attributes: HashMap<String, String>,
2426
pub hostname: Option<String>,
27+
pub service_name: Option<String>,
2528
pub kind: CollectorProtocol,
2629
}
2730

@@ -95,18 +98,21 @@ impl Config {
9598
.control
9699
.build(dns, client_metrics, control_metrics, identity)
97100
.new_service(());
101+
let svc_name = inner.service_name.unwrap_or_else(|| SERVICE_NAME.to_string());
98102

99103
let collector = match inner.kind {
100104
CollectorProtocol::OpenCensus => oc_collector::create_collector(
101105
addr.clone(),
102106
inner.hostname,
107+
svc_name,
103108
inner.attributes,
104109
svc,
105110
legacy_oc_metrics,
106111
),
107112
CollectorProtocol::OpenTelemetry => otel_collector::create_collector(
108113
addr.clone(),
109114
inner.hostname,
115+
svc_name,
110116
inner.attributes,
111117
svc,
112118
legacy_otel_metrics,

linkerd/app/src/trace_collector/oc_collector.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use tonic::client::GrpcService;
1212
use tracing::Instrument;
1313

1414
const SPAN_BUFFER_CAPACITY: usize = 100;
15-
const SERVICE_NAME: &str = "linkerd-proxy";
1615

1716
pub(super) fn create_collector<S>(
1817
addr: ControlAddr,
1918
hostname: Option<String>,
19+
service_name: String,
2020
attributes: HashMap<String, String>,
2121
svc: S,
2222
legacy_metrics: metrics::Registry,
@@ -40,9 +40,7 @@ where
4040
pid: std::process::id(),
4141
start_timestamp: Some(SystemTime::now().into()),
4242
}),
43-
service_info: Some(oc::ServiceInfo {
44-
name: SERVICE_NAME.to_string(),
45-
}),
43+
service_info: Some(oc::ServiceInfo { name: service_name }),
4644
attributes,
4745
..oc::Node::default()
4846
};

linkerd/app/src/trace_collector/otel_collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use tonic::client::GrpcService;
1717
use tracing::Instrument;
1818

1919
const SPAN_BUFFER_CAPACITY: usize = 100;
20-
const SERVICE_NAME: &str = "linkerd-proxy";
2120

2221
pub(super) fn create_collector<S>(
2322
addr: ControlAddr,
2423
hostname: Option<String>,
24+
service_name: String,
2525
attributes: HashMap<String, String>,
2626
svc: S,
2727
legacy_metrics: metrics::Registry,
@@ -41,7 +41,7 @@ where
4141
resources
4242
.attributes
4343
.0
44-
.push(SERVICE_NAME.with_key("service.name"));
44+
.push(service_name.with_key("service.name"));
4545
resources
4646
.attributes
4747
.0

0 commit comments

Comments
 (0)