6969)
7070from langtrace_python_sdk .utils .langtrace_sampler import LangtraceSampler
7171import sentry_sdk
72+ from sentry_sdk .types import Event , Hint
7273
7374
7475def 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+
198216def init_instrumentations (
199217 disable_instrumentations : Optional [DisableInstrumentations ],
200218 all_instrumentations : dict ,
0 commit comments