Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make root level tracing span (TracingLayer) optional #911

Closed
wants to merge 2 commits into from

Conversation

rimutaka
Copy link
Contributor

📬 A demo implementation for the log clutter issue discussed in #672.
It needs more work (docs, tests, better env var parsing)

✍️ Description of changes:

Reuse AWS_LAMBDA_LOG_FORMAT to specify if the root span should not be created.
E.g. AWS_LAMBDA_LOG_FORMAT=no-span or AWS_LAMBDA_LOG_FORMAT=json,no-span

The TracingLayer is added by default and not added if AWS_LAMBDA_LOG_FORMAT contains no-span.

Impact

  1. the change is backward compatible
  2. nothing changes for existing implementations
  3. minimal performance penalty for reading an env var
  4. no code changes are needed to change the log format

This last point allows using different log formats in different environments without code changes.

Examples

Including the root span

 INFO Lambda runtime invoke{requestId="local-request-id" xrayTraceId="Root=0-00000000-000000000000000000000000;Parent=0000000000000000;Sampled=0;Lineage=00000000:0"}: With global default provider
 INFO Lambda runtime invoke{requestId="local-request-id" xrayTraceId="Root=0-00000000-000000000000000000000000;Parent=0000000000000000;Sampled=0;Lineage=00000000:0"}: Command received: echo
ERROR Lambda runtime invoke{requestId="local-request-id" xrayTraceId="Root=0-00000000-000000000000000000000000;Parent=0000000000000000;Sampled=0;Lineage=00000000:0"}: "Error"

No root span (the main goal of this PR)

 INFO With global default provider
 INFO Command received: echo
ERROR "Error"

Root span + JSON

{"level":"INFO","fields":{"message":"With global default provider"},"span":{"requestId":"local-request-id","xrayTraceId":"Root=0-00000000-000000000000000000000000;Parent=0000000000000000;Sampled=0;Lineage=00000000:0","name":"Lambda runtime invoke"},"spans":[{"requestId":"local-request-id","xrayTraceId":"Root=0-00000000-000000000000000000000000;Parent=0000000000000000;Sampled=0;Lineage=00000000:0","name":"Lambda runtime invoke"}]}
{"level":"INFO","fields":{"message":"Command received: echo"},"span":{"requestId":"local-request-id","xrayTraceId":"Root=0-00000000-000000000000000000000000;Parent=0000000000000000;Sampled=0;Lineage=00000000:0","name":"Lambda runtime invoke"},"spans":[{"requestId":"local-request-id","xrayTraceId":"Root=0-00000000-000000000000000000000000;Parent=0000000000000000;Sampled=0;Lineage=00000000:0","name":"Lambda runtime invoke"}]}
{"level":"ERROR","fields":{"message":"\"Error\""},"span":{"requestId":"local-request-id","xrayTraceId":"Root=0-00000000-000000000000000000000000;Parent=0000000000000000;Sampled=0;Lineage=00000000:0","name":"Lambda runtime invoke"},"spans":[{"requestId":"local-request-id","xrayTraceId":"Root=0-00000000-000000000000000000000000;Parent=0000000000000000;Sampled=0;Lineage=00000000:0","name":"Lambda runtime invoke"}]}

No root span + JSON

{"level":"INFO","fields":{"message":"With global default provider"}}
{"level":"INFO","fields":{"message":"Command received: echo"}}
{"level":"ERROR","fields":{"message":"\"Error\""}}

🔏 By submitting this pull request

  • I confirm that I've ran cargo +nightly fmt.
  • I confirm that I've ran cargo clippy --fix.
  • I confirm that I've made a best effort attempt to update all relevant documentation.
  • I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@calavera calavera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary. You can just initialize the runtime in your code without adding the layer:

async fn main() {
  ...
  let runtime = Runtime::new(handler);
  runtime.run().await
}

@rimutaka
Copy link
Contributor Author

@calavera , thank you. It is very embarrassing how I missed it. The solution was hiding in the plain sight. Sorry for wasting so much of your time on this.

@rimutaka rimutaka closed this Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants