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
18 changes: 18 additions & 0 deletions src/langtrace_python_sdk/langtrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
)
from langtrace_python_sdk.utils.langtrace_sampler import LangtraceSampler
import sentry_sdk
from sentry_sdk.types import Event, Hint


def init(
Expand Down Expand Up @@ -177,6 +178,7 @@ def init(
dsn=SENTRY_DSN,
traces_sample_rate=1.0,
profiles_sample_rate=1.0,
before_send=before_send,
)
sdk_options = {
"service_name": os.environ.get("OTEL_SERVICE_NAME")
Expand All @@ -195,6 +197,22 @@ def init(
sentry_sdk.set_context("sdk_init_options", sdk_options)


def before_send(event: Event, hint: Hint):
# Check if there's an exception and stacktrace in the event
if "exception" in event:
exception = event["exception"]["values"][0]
stacktrace = exception.get("stacktrace", {})
frames = stacktrace.get("frames", [])
if frames:
last_frame = frames[-1]
absolute_path = last_frame.get("abs_path") # Absolute path
# Check if the error is from the SDK
if "langtrace-python-sdk" in absolute_path:
return event

return None


def init_instrumentations(
disable_instrumentations: Optional[DisableInstrumentations],
all_instrumentations: dict,
Expand Down
2 changes: 1 addition & 1 deletion src/langtrace_python_sdk/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.3.19"
__version__ = "2.3.20"