Skip to content

Commit e042103

Browse files
authored
Fix invoke span by specifying a minimum version of tracing (#585)
Some versions of tracing don't implement the tracing::Value trait for &std::string::String, and the runtime doesn't compile with them. By setting a minimum required version, we guarantee that the runtime compiles. Signed-off-by: David Calavera <[email protected]> Signed-off-by: David Calavera <[email protected]>
1 parent 381ac09 commit e042103

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

.rustfmt.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
edition = "2018"
1+
edition = "2021"
22
# imports_granularity is unstable
33
# # https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#merge_imports
44
# imports_granularity = "Crate"
55
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#max_width
6-
max_width = 120
6+
max_width = 120

lambda-runtime/Cargo.toml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@ default = ["simulated"]
1818
simulated = []
1919

2020
[dependencies]
21-
tokio = { version = "1.0", features = ["macros", "io-util", "sync", "rt-multi-thread"] }
21+
tokio = { version = "1.0", features = [
22+
"macros",
23+
"io-util",
24+
"sync",
25+
"rt-multi-thread",
26+
] }
2227
# Hyper requires the `server` feature to work on nightly
23-
hyper = { version = "0.14.20", features = ["http1", "client", "stream", "server"] }
28+
hyper = { version = "0.14.20", features = [
29+
"http1",
30+
"client",
31+
"stream",
32+
"server",
33+
] }
2434
futures = "0.3"
2535
serde = { version = "1", features = ["derive"] }
2636
serde_json = "^1"
2737
bytes = "1.0"
2838
http = "0.2"
2939
async-stream = "0.3"
30-
tracing = { version = "0.1", features = ["log"] }
40+
tracing = { version = "0.1.37", features = ["log"] }
3141
tower = { version = "0.4", features = ["util"] }
3242
tokio-stream = "0.1.2"
3343
lambda_runtime_api_client = { version = "0.7", path = "../lambda-runtime-api-client" }

lambda-runtime/src/lib.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,15 @@ where
124124
let ctx: Context = ctx.with_config(config);
125125
let request_id = &ctx.request_id.clone();
126126

127-
let xray_trace_id = &ctx.xray_trace_id.clone();
128-
match xray_trace_id {
129-
Some(trace_id) => env::set_var("_X_AMZN_TRACE_ID", trace_id),
130-
None => env::remove_var("_X_AMZN_TRACE_ID"),
131-
}
132-
let request_span = match xray_trace_id {
133-
Some(trace_id) => tracing::span!(
134-
tracing::Level::INFO,
135-
"Lambda runtime invoke",
136-
requestId = request_id,
137-
xrayTraceId = trace_id
138-
),
139-
None => tracing::span!(tracing::Level::INFO, "Lambda runtime invoke", requestId = request_id),
127+
let request_span = match &ctx.xray_trace_id {
128+
Some(trace_id) => {
129+
env::set_var("_X_AMZN_TRACE_ID", trace_id);
130+
tracing::info_span!("Lambda runtime invoke", requestId = request_id, xrayTraceId = trace_id)
131+
}
132+
None => {
133+
env::remove_var("_X_AMZN_TRACE_ID");
134+
tracing::info_span!("Lambda runtime invoke", requestId = request_id)
135+
}
140136
};
141137

142138
// Group the handling in one future and instrument it with the span

0 commit comments

Comments
 (0)