Esempio n. 1
0
def main():
    extension_id = register()

    lambda_service = LambdaService(extension_id)
    if is_kill_switch_on() or (os.environ.get(STOP_EXTENSION_KEY, "").lower() == "true"):
        start_empty_extension_loop(lambda_service)
    else:
        start_extension_loop(lambda_service)
Esempio n. 2
0
def _lumigo_tracer(func):
    if is_kill_switch_on():
        return func
    wrap()

    @wraps(func)
    def lambda_wrapper(*args, **kwargs):
        if _is_context_already_wrapped(*args):
            return func(*args, **kwargs)
        _add_wrap_flag_to_context(*args)
        executed = False
        ret_val = None
        local_print = print
        local_logging_format = logging.Formatter.format
        try:
            if Configuration.enhanced_print:
                _enhance_output(args, local_print, local_logging_format)
            SpansContainer.create_span(*args, is_new_invocation=True)
            with lumigo_safe_execute("auto tag"):
                AutoTagEvent.auto_tag_event(args[0])
            SpansContainer.get_span().start(*args)
            try:
                executed = True
                ret_val = func(*args, **kwargs)
            except Exception as e:
                with lumigo_safe_execute("Customer's exception"):
                    SpansContainer.get_span().add_exception_event(
                        e, inspect.trace())
                raise
            finally:
                SpansContainer.get_span().end(ret_val, *args)
                if Configuration.enhanced_print:
                    builtins.print = local_print
                    logging.Formatter.format = local_logging_format
            return ret_val
        except Exception:
            # The case where our wrapping raised an exception
            if not executed:
                TimeoutMechanism.stop()
                get_logger().exception("exception in the wrapper",
                                       exc_info=True)
                return func(*args, **kwargs)
            else:
                raise

    return lambda_wrapper
Esempio n. 3
0
def test_is_kill_switch_on(monkeypatch, env, expected):
    monkeypatch.setenv(KILL_SWITCH, env)
    assert is_kill_switch_on() == expected