Skip to content
Merged
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
7 changes: 7 additions & 0 deletions src/lumigo_tracer/lumigo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from contextlib import contextmanager
from base64 import b64encode
import inspect
import traceback

try:
import botocore
Expand Down Expand Up @@ -66,6 +67,7 @@
ERROR_SIZE_LIMIT_MULTIPLIER = 2
CHINA_REGION = "cn-northwest-1"
EDGE_KINESIS_STREAM_NAME = "prod_trc-inges-edge_edge-kinesis-stream"
STACKTRACE_LINE_TO_DROP = "lumigo_tracer/tracer.py"
Container = TypeVar("Container", dict, list)

_logger: Dict[str, logging.Logger] = {}
Expand Down Expand Up @@ -701,3 +703,8 @@ def is_aws_arn(string_to_validate: Optional[str]) -> bool:

def is_provision_concurrency_initialization() -> bool:
return os.environ.get("AWS_LAMBDA_INITIALIZATION_TYPE") == "provisioned-concurrency"


def get_stacktrace(exception: Exception) -> str:
original_traceback = traceback.format_tb(exception.__traceback__)
return "".join(filter(lambda line: STACKTRACE_LINE_TO_DROP not in line, original_traceback))
4 changes: 2 additions & 2 deletions src/lumigo_tracer/spans_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import time
import uuid
import signal
import traceback
from typing import List, Dict, Optional, Callable, Set

from lumigo_tracer.event.event_dumper import EventDumper
Expand All @@ -24,6 +23,7 @@
get_current_ms_time,
get_region,
is_provision_concurrency_initialization,
get_stacktrace,
)
from lumigo_tracer import lumigo_utils
from lumigo_tracer.parsing_utils import parse_trace_id, safe_split_get, recursive_json_join
Expand Down Expand Up @@ -202,7 +202,7 @@ def add_exception_event(
self.function_span["error"] = self._create_exception_event(
exc_type=exception.__class__.__name__,
message=message,
stacktrace=traceback.format_exc(),
stacktrace=get_stacktrace(exception),
frames=format_frames(frames_infos) if Configuration.verbose else [],
)

Expand Down
24 changes: 24 additions & 0 deletions src/test/unit/test_tracer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import json
import re
import traceback
from decimal import Decimal
import http.client
import os
Expand Down Expand Up @@ -439,3 +441,25 @@ def lambda_test_function(event, context):
aws_secret_access_key=secret_access_key,
config=ANY,
)


def test_lumigo_tracer_doesnt_change_exception(context):
@lumigo_tracer(token="123")
def wrapped(event, context):
raise Exception("Inner exception")

with pytest.raises(Exception):
wrapped({}, context)

def wrapped(event, context):
raise Exception("Inner exception")

with pytest.raises(Exception) as e:
wrapped({}, context)

stacktrace = SpansContainer.get_span().function_span["error"]["stacktrace"]
assert "lumigo_tracer/tracer.py" not in stacktrace
line_dropper = re.compile(r"\d{3}")
from_lumigo = line_dropper.sub("-", stacktrace)
original = line_dropper.sub("-", traceback.format_tb(e.value.__traceback__)[1])
assert from_lumigo == original