Skip to content

Commit 847b060

Browse files
authored
make tracing init consistent across examples (#609)
1 parent 23b665f commit 847b060

File tree

42 files changed

+155
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+155
-44
lines changed

examples/advanced-sqs-partial-batch-failures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ lambda_runtime = "0.7"
1313
tokio = { version = "1", features = ["macros"] }
1414
futures = "0.3"
1515
tracing = { version = "0.1", features = ["log"] }
16-
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
16+
tracing-subscriber = { version = "0.3", default-features = false, features = ["ansi", "fmt"] }

examples/advanced-sqs-partial-batch-failures/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ async fn data_handler(data: Data) -> Result<(), Error> {
2828
/// Main function for the lambda executable.
2929
#[tokio::main]
3030
async fn main() -> Result<(), Error> {
31+
// required to enable CloudWatch error logging by the runtime
3132
tracing_subscriber::fmt()
3233
.with_max_level(tracing::Level::INFO)
3334
// disable printing the name of the module in every log line.
3435
.with_target(false)
36+
// this needs to be set to false, otherwise ANSI color codes will
37+
// show up in a confusing manner in CloudWatch logs.
38+
.with_ansi(false)
3539
// disabling time is handy because CloudWatch will add the ingestion time.
3640
.without_time()
3741
.init();

examples/basic-error-handling/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ serde_json = "1.0.81"
1717
simple-error = "0.2.3"
1818
tokio = { version = "1", features = ["macros"] }
1919
tracing = { version = "0.1", features = ["log"] }
20-
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
20+
tracing-subscriber = { version = "0.3", default-features = false, features = ["ansi", "fmt"] }
2121

2222

examples/basic-error-handling/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ impl std::fmt::Display for CustomError {
4949

5050
#[tokio::main]
5151
async fn main() -> Result<(), Error> {
52-
// The runtime logging can be enabled here by initializing `tracing` with `tracing-subscriber`
53-
// While `tracing` is used internally, `log` can be used as well if preferred.
52+
// required to enable CloudWatch error logging by the runtime
5453
tracing_subscriber::fmt()
5554
.with_max_level(tracing::Level::INFO)
55+
// disable printing the name of the module in every log line.
56+
.with_target(false)
57+
// this needs to be set to false, otherwise ANSI color codes will
58+
// show up in a confusing manner in CloudWatch logs.
59+
.with_ansi(false)
5660
// disabling time is handy because CloudWatch will add the ingestion time.
5761
.without_time()
5862
.init();

examples/basic-lambda/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ lambda_runtime = { path = "../../lambda-runtime" }
1515
serde = "1.0.136"
1616
tokio = { version = "1", features = ["macros"] }
1717
tracing = { version = "0.1", features = ["log"] }
18-
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
18+
tracing-subscriber = { version = "0.3", default-features = false, features = ["ansi", "fmt"] }

examples/basic-lambda/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ struct Response {
2424

2525
#[tokio::main]
2626
async fn main() -> Result<(), Error> {
27+
// required to enable CloudWatch error logging by the runtime
2728
tracing_subscriber::fmt()
2829
.with_max_level(tracing::Level::INFO)
30+
// disable printing the name of the module in every log line.
31+
.with_target(false)
32+
// this needs to be set to false, otherwise ANSI color codes will
33+
// show up in a confusing manner in CloudWatch logs.
34+
.with_ansi(false)
2935
// disabling time is handy because CloudWatch will add the ingestion time.
3036
.without_time()
3137
.init();

examples/basic-shared-resource/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ lambda_runtime = { path = "../../lambda-runtime" }
1515
serde = "1.0.136"
1616
tokio = { version = "1", features = ["macros"] }
1717
tracing = { version = "0.1", features = ["log"] }
18-
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
18+
tracing-subscriber = { version = "0.3", default-features = false, features = ["ansi", "fmt"] }
1919

2020

examples/basic-shared-resource/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ async fn main() -> Result<(), Error> {
4747
// required to enable CloudWatch error logging by the runtime
4848
tracing_subscriber::fmt()
4949
.with_max_level(tracing::Level::INFO)
50+
// disable printing the name of the module in every log line.
51+
.with_target(false)
52+
// this needs to be set to false, otherwise ANSI color codes will
53+
// show up in a confusing manner in CloudWatch logs.
54+
.with_ansi(false)
5055
// disabling time is handy because CloudWatch will add the ingestion time.
5156
.without_time()
5257
.init();

examples/basic-sqs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ lambda_runtime = { path = "../../lambda-runtime" }
2020
serde = "1.0.136"
2121
tokio = { version = "1", features = ["macros"] }
2222
tracing = { version = "0.1", features = ["log"] }
23-
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
23+
tracing-subscriber = { version = "0.3", default-features = false, features = ["ansi", "fmt"] }

examples/basic-sqs/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ async fn function_handler(event: LambdaEvent<SqsEventObj<Data>>) -> Result<(), E
2020

2121
#[tokio::main]
2222
async fn main() -> Result<(), Error> {
23+
// required to enable CloudWatch error logging by the runtime
2324
tracing_subscriber::fmt()
2425
.with_max_level(tracing::Level::INFO)
2526
// disable printing the name of the module in every log line.
2627
.with_target(false)
28+
// this needs to be set to false, otherwise ANSI color codes will
29+
// show up in a confusing manner in CloudWatch logs.
30+
.with_ansi(false)
2731
// disabling time is handy because CloudWatch will add the ingestion time.
2832
.without_time()
2933
.init();

0 commit comments

Comments
 (0)