Skip to content

Commit 5715734

Browse files
authored
Fix memory leak by not piling up breadcrumbs forever in Spark workers. (#4167)
We now clear all existing breadcrumbs when a job is started. If an error happens in a job, only breadcrumbs created in this job will be shown. Fixes #1245.
1 parent 2579cb2 commit 5715734

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

sentry_sdk/integrations/spark/spark_driver.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ def _set_app_properties():
3131

3232
spark_context = SparkContext._active_spark_context
3333
if spark_context:
34-
spark_context.setLocalProperty("sentry_app_name", spark_context.appName)
3534
spark_context.setLocalProperty(
36-
"sentry_application_id", spark_context.applicationId
35+
"sentry_app_name",
36+
spark_context.appName,
37+
)
38+
spark_context.setLocalProperty(
39+
"sentry_application_id",
40+
spark_context.applicationId,
3741
)
3842

3943

@@ -231,12 +235,14 @@ def _add_breadcrumb(
231235
data=None, # type: Optional[dict[str, Any]]
232236
):
233237
# type: (...) -> None
234-
sentry_sdk.get_global_scope().add_breadcrumb(
238+
sentry_sdk.get_isolation_scope().add_breadcrumb(
235239
level=level, message=message, data=data
236240
)
237241

238242
def onJobStart(self, jobStart): # noqa: N802,N803
239243
# type: (Any) -> None
244+
sentry_sdk.get_isolation_scope().clear_breadcrumbs()
245+
240246
message = "Job {} Started".format(jobStart.jobId())
241247
self._add_breadcrumb(level="info", message=message)
242248
_set_app_properties()

0 commit comments

Comments
 (0)