Skip to content

Commit 60554fc

Browse files
committed
make tracing init consistent across examples
this just copies the code across examples so that we're initializing the tracing subscriber in a consistent way. we want to set a max level, disable printing the name of the module every time, disable ANSI color codes (because CloudWatch prints them in a non-readable way), and disable logging the time at this layer because CloudWatch is going to add the ingestion time itself.
1 parent 23b665f commit 60554fc

File tree

21 files changed

+132
-23
lines changed

21 files changed

+132
-23
lines changed

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/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/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/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/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();

examples/extension-basic/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ async fn my_extension(event: LambdaEvent) -> Result<(), Error> {
1414

1515
#[tokio::main]
1616
async fn main() -> Result<(), Error> {
17-
// The runtime logging can be enabled here by initializing `tracing` with `tracing-subscriber`
18-
// While `tracing` is used internally, `log` can be used as well if preferred.
17+
// required to enable CloudWatch error logging by the runtime
1918
tracing_subscriber::fmt()
2019
.with_max_level(tracing::Level::INFO)
20+
// disable printing the name of the module in every log line.
21+
.with_target(false)
22+
// this needs to be set to false, otherwise ANSI color codes will
23+
// show up in a confusing manner in CloudWatch logs.
24+
.with_ansi(false)
2125
// disabling time is handy because CloudWatch will add the ingestion time.
2226
.without_time()
2327
.init();

examples/extension-combined/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ async fn my_log_processor(logs: Vec<LambdaLog>) -> Result<(), Error> {
2929

3030
#[tokio::main]
3131
async fn main() -> Result<(), Error> {
32-
// The runtime logging can be enabled here by initializing `tracing` with `tracing-subscriber`
33-
// While `tracing` is used internally, `log` can be used as well if preferred.
32+
// required to enable CloudWatch error logging by the runtime
3433
tracing_subscriber::fmt()
3534
.with_max_level(tracing::Level::INFO)
35+
// disable printing the name of the module in every log line.
36+
.with_target(false)
37+
// this needs to be set to false, otherwise ANSI color codes will
38+
// show up in a confusing manner in CloudWatch logs.
39+
.with_ansi(false)
3640
// disabling time is handy because CloudWatch will add the ingestion time.
3741
.without_time()
3842
.init();

examples/extension-custom-events/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ async fn my_extension(event: LambdaEvent) -> Result<(), Error> {
1616

1717
#[tokio::main]
1818
async fn main() -> Result<(), Error> {
19-
// The runtime logging can be enabled here by initializing `tracing` with `tracing-subscriber`
20-
// While `tracing` is used internally, `log` can be used as well if preferred.
19+
// required to enable CloudWatch error logging by the runtime
2120
tracing_subscriber::fmt()
2221
.with_max_level(tracing::Level::INFO)
22+
// disable printing the name of the module in every log line.
23+
.with_target(false)
24+
// this needs to be set to false, otherwise ANSI color codes will
25+
// show up in a confusing manner in CloudWatch logs.
26+
.with_ansi(false)
2327
// disabling time is handy because CloudWatch will add the ingestion time.
2428
.without_time()
2529
.init();

examples/extension-custom-service/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ impl Service<LambdaEvent> for MyExtension {
3333

3434
#[tokio::main]
3535
async fn main() -> Result<(), Error> {
36-
// The runtime logging can be enabled here by initializing `tracing` with `tracing-subscriber`
37-
// While `tracing` is used internally, `log` can be used as well if preferred.
36+
// required to enable CloudWatch error logging by the runtime
3837
tracing_subscriber::fmt()
3938
.with_max_level(tracing::Level::INFO)
39+
// disable printing the name of the module in every log line.
40+
.with_target(false)
41+
// this needs to be set to false, otherwise ANSI color codes will
42+
// show up in a confusing manner in CloudWatch logs.
43+
.with_ansi(false)
4044
// disabling time is handy because CloudWatch will add the ingestion time.
4145
.without_time()
4246
.init();

examples/extension-logs-basic/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ async fn handler(logs: Vec<LambdaLog>) -> Result<(), Error> {
1515

1616
#[tokio::main]
1717
async fn main() -> Result<(), Error> {
18-
// The runtime logging can be enabled here by initializing `tracing` with `tracing-subscriber`
19-
// While `tracing` is used internally, `log` can be used as well if preferred.
18+
// required to enable CloudWatch error logging by the runtime
2019
tracing_subscriber::fmt()
2120
.with_max_level(tracing::Level::INFO)
21+
// disable printing the name of the module in every log line.
22+
.with_target(false)
23+
// this needs to be set to false, otherwise ANSI color codes will
24+
// show up in a confusing manner in CloudWatch logs.
25+
.with_ansi(false)
2226
// disabling time is handy because CloudWatch will add the ingestion time.
2327
.without_time()
2428
.init();

0 commit comments

Comments
 (0)