-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2463 from calebschoepp/grpc-otel
feat(telemetry): Make telemetry support http/protobuf protocol in addition to grpc protocol
- Loading branch information
Showing
6 changed files
with
242 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/// Returns a boolean indicating if the OTEL layer should be enabled. | ||
/// | ||
/// It is considered enabled if any of the following environment variables are set and not empty: | ||
/// - `OTEL_EXPORTER_OTLP_ENDPOINT` | ||
/// - `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | ||
/// - `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` | ||
/// | ||
/// Note that this is overridden if OTEL_SDK_DISABLED is set and not empty. | ||
pub(crate) fn otel_enabled() -> bool { | ||
const ENABLING_VARS: &[&str] = &[ | ||
"OTEL_EXPORTER_OTLP_ENDPOINT", | ||
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", | ||
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", | ||
]; | ||
ENABLING_VARS | ||
.iter() | ||
.any(|key| std::env::var_os(key).is_some_and(|val| !val.is_empty())) | ||
} | ||
|
||
/// Returns a boolean indicating if the OTEL SDK should be disabled for all signals. | ||
/// | ||
/// It is considered disabled if the environment variable `OTEL_SDK_DISABLED` is set and not empty. | ||
pub(crate) fn otel_sdk_disabled() -> bool { | ||
std::env::var_os("OTEL_SDK_DISABLED").is_some_and(|val| !val.is_empty()) | ||
} | ||
|
||
/// The protocol to use for OTLP exporter. | ||
pub(crate) enum OtlpProtocol { | ||
Grpc, | ||
HttpProtobuf, | ||
HttpJson, | ||
} | ||
|
||
impl OtlpProtocol { | ||
/// Returns the protocol to be used for exporting traces as defined by the environment. | ||
pub(crate) fn traces_protocol_from_env() -> Self { | ||
let trace_protocol = std::env::var("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"); | ||
let general_protocol = std::env::var("OTEL_EXPORTER_OTLP_PROTOCOL"); | ||
let protocol = trace_protocol.unwrap_or(general_protocol.unwrap_or_default()); | ||
|
||
match protocol.as_str() { | ||
"grpc" => Self::Grpc, | ||
"http/protobuf" => Self::HttpProtobuf, | ||
"http/json" => Self::HttpJson, | ||
_ => Self::HttpProtobuf, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.