Skip to content

Commit

Permalink
Support OTEL_RESOURCE_ATTRIBUTES in the proxy (#3580)
Browse files Browse the repository at this point in the history
This environment variable is definted by the OpenTelemetry conventions as a way of specifying additional resource attributes to be included in traces: https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration

Note that this is parallel to LINKERD2_PROXY_TRACE_EXTRA_ATTRIBUTES, which is meant for common attributes that should always be provided by the proxy (pod UID, contianer name, etc.). We do not expect users to override that one, as OTEL_RESOURCE_ATTRIBUTES is the conventional way of specifying custom attributes.

Signed-off-by: Scott Fleener <[email protected]>
  • Loading branch information
sfleen authored Jan 31, 2025
1 parent 63dce67 commit 4e791fe
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions linkerd/app/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ const ENV_TRACE_ATTRIBUTES_PATH: &str = "LINKERD2_PROXY_TRACE_ATTRIBUTES_PATH";
const ENV_TRACE_PROTOCOL: &str = "LINKERD2_PROXY_TRACE_PROTOCOL";
const ENV_TRACE_SERVICE_NAME: &str = "LINKERD2_PROXY_TRACE_SERVICE_NAME";
const ENV_TRACE_EXTRA_ATTRIBUTES: &str = "LINKERD2_PROXY_TRACE_EXTRA_ATTRIBUTES";
// This doesn't have the LINKERD2_ prefix because it is a conventional env var from OpenTelemetry:
// https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration
const ENV_OTEL_TRACE_ATTRIBUTES: &str = "OTEL_RESOURCE_ATTRIBUTES";

/// Constrains which destination names may be used for profile/route discovery.
///
Expand Down Expand Up @@ -434,6 +437,7 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>

let trace_attributes_file_path = strings.get(ENV_TRACE_ATTRIBUTES_PATH);
let trace_extra_attributes = strings.get(ENV_TRACE_EXTRA_ATTRIBUTES);
let trace_otel_attributes = strings.get(ENV_OTEL_TRACE_ATTRIBUTES);
let trace_protocol = strings.get(ENV_TRACE_PROTOCOL);
let trace_service_name = strings.get(ENV_TRACE_SERVICE_NAME);

Expand Down Expand Up @@ -844,6 +848,11 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
attributes.extend(trace::parse_env_trace_attributes(&attrs));
}
}
if let Ok(Some(attrs)) = trace_otel_attributes {
if !attrs.is_empty() {
attributes.extend(trace::parse_env_trace_attributes(&attrs));
}
}

let trace_protocol = trace_protocol
.map(|proto| proto.and_then(|p| p.parse::<CollectorProtocol>().ok()))
Expand Down

0 comments on commit 4e791fe

Please sign in to comment.