A couple minor thoughts on logging #672
Replies: 5 comments 5 replies
-
Thanks a lot for the feedback @BMorinDrifter! I'm leaving some comments below
I agree with you. That feature should be removed from all our examples (feel free to open a PR). For most people following tutorials, we recommend starting projects with
I'm not aware that any of those options improve cold start times. I'll appreciate it if you shared where you found that information. However, they do reduce the binary size. For most people, we recommend using
I agree with you that the default log might not need the xray id. Do you enable the tracing option when you create or update the lambda function? It might make sense to not add the xray id if that option is not enabled, there is an environment variable for it. We'd have to check how to make a change like this because I know some people that use that xray id, so it's important to try not breaking backwards compatibility. |
Beta Was this translation helpful? Give feedback.
-
@calavera , the amount of noise in the logs feels counter-productive. Can we start a discussion to make that entire tracing span optional / configurable / overwritable? Not sure what is possible and would like to hear your opinion before investing any more time into this. |
Beta Was this translation helpful? Give feedback.
-
Well once nice thing about tracing-subscriber is that you can provide your own logic to print the logs if you don't like the default. There is nothing stopping you from changing it, you don't even need to change anything in this repo. I'm open to improvements in form of Pull Requests. |
Beta Was this translation helpful? Give feedback.
-
@calavera , after a bit of experimenting, I figured that the easiest way to remove the span fields is to init a different subscriber within the handler, e.g. pub(crate) async fn my_handler(event: LambdaEvent<Request>) -> Result<Response, Error> {
info!("With global default provider"); // prints an extended message, incl x-trace-id
// init a local subscriber
let sub = tracing_subscriber::fmt().without_time().finish();
let _guard = tracing::subscriber::set_default(sub);
let command = event.payload.command;
info!("With the local provider"); // prints short messages, no span info from now on
info!("Command received: {}", command);
Err(Error::from("Error"))
} // the local subscriber is dropped here, back to printing x-trace-id it produces a log like this
where 1 and 3 were logged by the global default subscriber with the span info. Shall I mention this in the logging section of the ReadMe or is there a better way of achieving the same result? |
Beta Was this translation helpful? Give feedback.
-
@calavera , I tried the custom formatter approach, but it felt like a crutch for several reasons:
No fields
Alternative solutionIt seems that not adding the span in the first place is a more flexible and easier solution. See my draft PR #911 for what it may look like. Sample output:
|
Beta Was this translation helpful? Give feedback.
-
Minor things things I've run into since I've started moving some parts of our serverless game service stack from python to rust.
ANSI
The examples do this:
However if we instead remove the ansi feature and the corresponding rust code
As far as I can tell, I get the same output and my bootstrap.zip file is slightly smaller when I omit the ansi feature. Perhaps this is something that changed with newer versions of the crate?
boostrap.zip Optimization
On a related note, should this be part of the .toml file for the examples as well? These settings seem to be used by multiple projects to reduce cold start time. Seems like it should be better communicated as minimal cold start times are a selling point of the lambda runtime.
Log Signal vs Noise
If I take the basic-lambda sample and add a single log entry to it:
I get this output:
Compare this to what I get from a comparable Python example:
You probably had to scroll right to see the text in the Rust example ;-) mostly because of the x-ray trace id, but the verbose span name of
Lambda runtime invoke
doesn't help either. When I started experimenting with rust lambda functions, I spent an hour trying to figure out "how do I turn that off".Now I'm a little deeper under the hood on this, I found the root library code:
Outside of the initial developer experience this is totally the right thing to do. However it is a little frustrating not to have any agency to use a shorter span name, a different verbosity level, or opt out of requestId and/or xrayTraceId without forking the runtime.
I'm unsure what the best path forward would be from here. A few takes:
Beta Was this translation helpful? Give feedback.
All reactions