Skip to content

feat: skip invocations from warmup plugin #320

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def my_lambda(event, context):
* `LUMIGO_DOMAINS_SCRUBBER=[".*secret.*"]` - Prevents Lumigo from collecting both request and response details from a list of domains. This accepts a comma-separated list of regular expressions that is JSON-formatted. By default, the tracer uses `["secretsmanager\..*\.amazonaws\.com", "ssm\..*\.amazonaws\.com", "kms\..*\.amazonaws\.com"]`. **Note** - These defaults are overridden when you define a different list of regular expressions.
* `LUMIGO_PROPAGATE_W3C=TRUE` - Add W3C TraceContext headers to outgoing HTTP requests. This enables uninterrupted transactions with applications traced with OpenTelemetry.
* `LUMIGO_SWITCH_OFF=TRUE` - In the event a critical issue arises, this turns off all actions that Lumigo takes in response to your code. This happens without a deployment, and is picked up on the next function run once the environment variable is present.
* `SKIP_WARMUP_INVOCATIONS=TRUE` - Prevents Lumigo from sending data during invocations from the serverless framework warmup plugin.

### Step Functions

Expand Down
13 changes: 13 additions & 0 deletions src/lumigo_tracer/lambda_tracer/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
config,
is_aws_environment,
is_kill_switch_on,
is_skip_warmup_on,
lumigo_safe_execute,
)

Expand All @@ -23,6 +24,15 @@ def _is_context_already_wrapped(*args) -> bool: # type: ignore[no-untyped-def]
return len(args) >= 2 and hasattr(args[1], CONTEXT_WRAPPED_BY_LUMIGO_KEY)


def is_warmup_invocation(*args) -> bool: # type: ignore[no-untyped-def]
"""
This function is here in order to detect the serverless framework warmup plugin invocations.
"""
if len(args) > 0 and args[0] == "warmup":
return True
return False


def _add_wrap_flag_to_context(*args): # type: ignore[no-untyped-def]
"""
This function is here in order to validate that we didn't already wrap this invocation
Expand All @@ -42,6 +52,9 @@ def _lumigo_tracer(func): # type: ignore[no-untyped-def]
def lambda_wrapper(*args, **kwargs): # type: ignore[no-untyped-def]
if _is_context_already_wrapped(*args):
return func(*args, **kwargs)
if is_skip_warmup_on() and is_warmup_invocation(*args):
get_logger().info("skipping warmup invocation")
return func(*args, **kwargs)
_add_wrap_flag_to_context(*args)
executed = False
ret_val = None
Expand Down
5 changes: 5 additions & 0 deletions src/lumigo_tracer/lumigo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
LUMIGO_TOKEN_KEY = "LUMIGO_TRACER_TOKEN"
LUMIGO_USE_TRACER_EXTENSION = "LUMIGO_USE_TRACER_EXTENSION"
KILL_SWITCH = "LUMIGO_SWITCH_OFF"
SKIP_WARMUP_INVOCATIONS = "SKIP_WARMUP_INVOCATIONS"
EDGE_KINESIS_STREAM_NAME = "prod_trc-inges-edge_edge-kinesis-stream"
STACKTRACE_LINE_TO_DROP = "lumigo_tracer/lambda_tracer/tracer.py"
Container = TypeVar("Container", dict, list) # type: ignore[type-arg,type-arg]
Expand Down Expand Up @@ -353,6 +354,10 @@ def is_kill_switch_on(): # type: ignore[no-untyped-def]
return str(os.environ.get(KILL_SWITCH, "")).lower() == "true"


def is_skip_warmup_on(): # type: ignore[no-untyped-def]
return str(os.environ.get(SKIP_WARMUP_INVOCATIONS, "")).lower() == "true"


def get_size_upper_bound() -> int:
return CoreConfiguration.get_max_entry_size(True)

Expand Down