Skip to content

Commit a98672d

Browse files
authored
Merge pull request #360 from Scale3-Labs/development
filter sentry events to report only langtrace errors
2 parents 0201e30 + 587135a commit a98672d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/langtrace_python_sdk/langtrace.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
)
7070
from langtrace_python_sdk.utils.langtrace_sampler import LangtraceSampler
7171
import sentry_sdk
72+
from sentry_sdk.types import Event, Hint
7273

7374

7475
def init(
@@ -177,6 +178,7 @@ def init(
177178
dsn=SENTRY_DSN,
178179
traces_sample_rate=1.0,
179180
profiles_sample_rate=1.0,
181+
before_send=before_send,
180182
)
181183
sdk_options = {
182184
"service_name": os.environ.get("OTEL_SERVICE_NAME")
@@ -195,6 +197,22 @@ def init(
195197
sentry_sdk.set_context("sdk_init_options", sdk_options)
196198

197199

200+
def before_send(event: Event, hint: Hint):
201+
# Check if there's an exception and stacktrace in the event
202+
if "exception" in event:
203+
exception = event["exception"]["values"][0]
204+
stacktrace = exception.get("stacktrace", {})
205+
frames = stacktrace.get("frames", [])
206+
if frames:
207+
last_frame = frames[-1]
208+
absolute_path = last_frame.get("abs_path") # Absolute path
209+
# Check if the error is from the SDK
210+
if "langtrace-python-sdk" in absolute_path:
211+
return event
212+
213+
return None
214+
215+
198216
def init_instrumentations(
199217
disable_instrumentations: Optional[DisableInstrumentations],
200218
all_instrumentations: dict,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.3.19"
1+
__version__ = "2.3.20"

0 commit comments

Comments
 (0)