Skip to content

Feature request: enable tracing only when running on AWS Lambda #147

Closed
@dreamorosi

Description

@dreamorosi

Description of the feature request

Customers have raised a pain point around the Tracer utility throwing errors when when not running inside the Lambda execution environment. While both the Tracer and the underlying aws-x-ray packages provide ways to both change missing context strategy and disable tracing altogether, it would make sense to have Tracer to be enabled by default only when running inside a Lambda function and disabled elsewhere instead of the current behaviour that sees the utility always being enabled by default unless explicitly disabled.

Problem statement

Tracer throws an error when trying to interact with a segment outside of a context and/or without the existence of a root segment (aka facade). Customers have to explicitly disable the Tracer utility when running outside of Lambda (i.e. testing, CI, etc.) which can be cumbersome.

Summary of the feature

  • Change wording/names of the parameter and variable used to enable/disable tracing to avoid double negation (i.e. currently reading like tracing disabled, change to tracing enabled).
  • Add logic to detect whether Tracer is being initialised in a Lambda function or not which would check the existence of one between AWS_LAMBDA_FUNCTION_NAME or AWS_EXECUTION_ENV environment variables that are present by default in Lambda.
  • Change protected property Tracer.tracingDisabled to Tracer.tracingEnabled.
  • Change all conditional behaviour and references related to Tracer.tracingDisabled to account for change.
  • Update all unit tests.

Code examples

  • Current environment variable used to disable tracing is POWERTOOLS_TRACE_DISABLED, would change to POWERTOOLS_TRACE_ENABLED.
  • Currently, to disable the tracer Customers have to do this const tracer: Tracer = new Tracer({ disabled: true });, it would change to const tracer: Tracer = new Tracer({ enabled: true });

Benefits for you and the wider AWS community

Better Developer Experience, less boilerplate code (-1 extra line) needed to instrument tests.

Describe alternatives you've considered

Clearer documentation around how to either disable tracing and/or changing X-Ray underlying SDK behaviour to ignore missing segments/context.

Additional context

Related issues, RFCs

#515
#572

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedfeature-requestThis item refers to a feature request for an existing or new utilitytracerThis item relates to the Tracer Utility

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions