Description
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 totracing enabled
). - Add logic to detect whether
Tracer
is being initialised in a Lambda function or not which would check the existence of one betweenAWS_LAMBDA_FUNCTION_NAME
orAWS_EXECUTION_ENV
environment variables that are present by default in Lambda. - Change protected property
Tracer.tracingDisabled
toTracer.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 toPOWERTOOLS_TRACE_ENABLED
. - Currently, to disable the tracer Customers have to do this
const tracer: Tracer = new Tracer({ disabled: true });
, it would change toconst 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