Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make root level tracing span (TracingLayer) optional #911

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lambda-runtime-api-client/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const DEFAULT_LOG_LEVEL: &str = "INFO";
/// if they're configured for your function.
///
/// This subscriber sets the logging level based on environment variables:
/// - if `AWS_LAMBDA_LOG_LEVEL` is set, it takes predecence over any other environment variables.
/// - if `AWS_LAMBDA_LOG_LEVEL` is set, it takes precedence over any other environment variables.
/// - if `AWS_LAMBDA_LOG_LEVEL` is not set, check if `RUST_LOG` is set.
/// - if none of those two variables are set, use `INFO` as the logging level.
///
Expand All @@ -44,7 +44,7 @@ pub fn init_default_subscriber() {
.from_env_lossy(),
);

if log_format.eq_ignore_ascii_case("json") {
if log_format.to_lowercase().contains("json") {
collector.json().init()
} else {
collector.init()
Expand Down
8 changes: 8 additions & 0 deletions lambda-runtime/src/layers/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ impl TracingLayer {
pub fn new() -> Self {
Self::default()
}

/// Returns true if the tracing span provided by this service should be included in the log output.
/// The span is enabled by default,
/// but can be disabled by adding `no-span` to the `AWS_LAMBDA_LOG_FORMAT` environment variable.
/// E.g. AWS_LAMBDA_LOG_FORMAT=no-span or =json,no-span.
pub fn is_enabled() -> bool {
!matches! (std::env::var("AWS_LAMBDA_LOG_FORMAT") , Ok(v) if v.to_lowercase().contains("no-span"))
}
}

impl<S> Layer<S> for TracingLayer {
Expand Down
9 changes: 7 additions & 2 deletions lambda-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ where
D: Into<bytes::Bytes> + Send,
E: Into<Error> + Send + Debug,
{
let runtime = Runtime::new(handler).layer(layers::TracingLayer::new());
runtime.run().await
if layers::TracingLayer::is_enabled() {
let runtime = Runtime::new(handler).layer(layers::TracingLayer::new());
runtime.run().await
} else {
let runtime = Runtime::new(handler);
runtime.run().await
}
}