Skip to content

Commit 9117f85

Browse files
committed
Test implementation of optional tracing span
1 parent e8761da commit 9117f85

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

lambda-runtime-api-client/src/tracing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const DEFAULT_LOG_LEVEL: &str = "INFO";
2323
/// if they're configured for your function.
2424
///
2525
/// This subscriber sets the logging level based on environment variables:
26-
/// - if `AWS_LAMBDA_LOG_LEVEL` is set, it takes predecence over any other environment variables.
26+
/// - if `AWS_LAMBDA_LOG_LEVEL` is set, it takes precedence over any other environment variables.
2727
/// - if `AWS_LAMBDA_LOG_LEVEL` is not set, check if `RUST_LOG` is set.
2828
/// - if none of those two variables are set, use `INFO` as the logging level.
2929
///
@@ -44,7 +44,7 @@ pub fn init_default_subscriber() {
4444
.from_env_lossy(),
4545
);
4646

47-
if log_format.eq_ignore_ascii_case("json") {
47+
if log_format.to_lowercase().contains("json") {
4848
collector.json().init()
4949
} else {
5050
collector.init()

lambda-runtime/src/layers/trace.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ impl TracingLayer {
1414
pub fn new() -> Self {
1515
Self::default()
1616
}
17+
18+
/// Returns true if the tracing span provided by this service should be included in the log output.
19+
/// The span is enabled by default,
20+
/// but can be disabled by adding `no-span` to the `AWS_LAMBDA_LOG_FORMAT` environment variable.
21+
/// E.g. AWS_LAMBDA_LOG_FORMAT=no-span or =json,no-span.
22+
pub fn is_enabled() -> bool {
23+
!matches! (std::env::var("AWS_LAMBDA_LOG_FORMAT") , Ok(v) if v.to_lowercase().contains("no-span"))
24+
}
1725
}
1826

1927
impl<S> Layer<S> for TracingLayer {

lambda-runtime/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ where
120120
D: Into<bytes::Bytes> + Send,
121121
E: Into<Error> + Send + Debug,
122122
{
123-
let runtime = Runtime::new(handler).layer(layers::TracingLayer::new());
124-
runtime.run().await
123+
if layers::TracingLayer::is_enabled() {
124+
let runtime = Runtime::new(handler).layer(layers::TracingLayer::new());
125+
runtime.run().await
126+
} else {
127+
let runtime = Runtime::new(handler);
128+
runtime.run().await
129+
}
125130
}

0 commit comments

Comments
 (0)