Skip to content

Commit bc7d402

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 e072e63 commit bc7d402

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
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
const ENV_TRACE_ATTRIBUTES_PATH: &str = "LINKERD2_PROXY_TRACE_ATTRIBUTES_PATH";
150150
const ENV_TRACE_PROTOCOL: &str = "LINKERD2_PROXY_TRACE_PROTOCOL";
151+
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
@@ -24,6 +24,7 @@ pub struct EnabledConfig {
2424
pub control: control::Config,
2525
pub attributes: HashMap<String, String>,
2626
pub hostname: Option<String>,
27+
pub service_name: Option<String>,
2728
pub kind: CollectorProtocol,
2829
}
2930

@@ -78,18 +79,23 @@ impl Config {
7879
.control
7980
.build(dns, client_metrics, control_metrics, identity)
8081
.new_service(());
82+
let svc_name = inner
83+
.service_name
84+
.unwrap_or_else(|| SERVICE_NAME.to_string());
8185

8286
let collector = match inner.kind {
8387
CollectorProtocol::OpenCensus => oc_collector::create_collector(
8488
addr.clone(),
8589
inner.hostname,
90+
svc_name,
8691
inner.attributes,
8792
svc,
8893
legacy_oc_metrics,
8994
),
9095
CollectorProtocol::OpenTelemetry => otel_collector::create_collector(
9196
addr.clone(),
9297
inner.hostname,
98+
svc_name,
9399
inner.attributes,
94100
svc,
95101
legacy_otel_metrics,

linkerd/app/src/trace_collector/oc_collector.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use tracing::Instrument;
1212
pub(super) fn create_collector<S>(
1313
addr: ControlAddr,
1414
hostname: Option<String>,
15+
service_name: String,
1516
attributes: HashMap<String, String>,
1617
svc: S,
1718
legacy_metrics: metrics::Registry,
@@ -35,9 +36,7 @@ where
3536
pid: std::process::id(),
3637
start_timestamp: Some(SystemTime::now().into()),
3738
}),
38-
service_info: Some(oc::ServiceInfo {
39-
name: crate::trace_collector::SERVICE_NAME.to_string(),
40-
}),
39+
service_info: Some(oc::ServiceInfo { name: service_name }),
4140
attributes,
4241
..oc::Node::default()
4342
};

linkerd/app/src/trace_collector/otel_collector.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use tracing::Instrument;
1616
pub(super) fn create_collector<S>(
1717
addr: ControlAddr,
1818
hostname: Option<String>,
19+
service_name: String,
1920
attributes: HashMap<String, String>,
2021
svc: S,
2122
legacy_metrics: metrics::Registry,
@@ -35,7 +36,7 @@ where
3536
resources
3637
.attributes
3738
.0
38-
.push(crate::trace_collector::SERVICE_NAME.with_key("service.name"));
39+
.push(service_name.with_key("service.name"));
3940
resources
4041
.attributes
4142
.0

0 commit comments

Comments
 (0)