Skip to content

Commit 1e0a2eb

Browse files
fix: add logfire.force_flush to all Modal functions to ensure spans are sent
1 parent 9186bad commit 1e0a2eb

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/policyengine_api/agent_sandbox.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def configure_logfire(traceparent: str | None = None):
2626

2727
token = os.environ.get("LOGFIRE_TOKEN", "")
2828
if not token:
29-
print("[LOGFIRE] No LOGFIRE_TOKEN found, skipping configuration")
3029
return
31-
print(f"[LOGFIRE] Configuring with token prefix: {token[:10]}...")
3230

3331
logfire.configure(
3432
service_name="policyengine-agent",

src/policyengine_api/modal_app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ def simulate_household_uk(
272272
)
273273
session.commit()
274274
raise
275+
finally:
276+
logfire.force_flush()
275277

276278

277279
@app.function(
@@ -409,6 +411,8 @@ def simulate_household_us(
409411
)
410412
session.commit()
411413
raise
414+
finally:
415+
logfire.force_flush()
412416

413417

414418
@app.function(
@@ -525,6 +529,8 @@ def simulate_economy_uk(simulation_id: str, traceparent: str | None = None) -> N
525529
except Exception as db_error:
526530
logfire.error("Failed to update DB", error=str(db_error))
527531
raise
532+
finally:
533+
logfire.force_flush()
528534

529535

530536
@app.function(
@@ -641,6 +647,8 @@ def simulate_economy_us(simulation_id: str, traceparent: str | None = None) -> N
641647
except Exception as db_error:
642648
logfire.error("Failed to update DB", error=str(db_error))
643649
raise
650+
finally:
651+
logfire.force_flush()
644652

645653

646654
@app.function(
@@ -873,6 +881,8 @@ def economy_comparison_uk(job_id: str, traceparent: str | None = None) -> None:
873881
except Exception as db_error:
874882
logfire.error("Failed to update DB", error=str(db_error))
875883
raise
884+
finally:
885+
logfire.force_flush()
876886

877887

878888
@app.function(
@@ -1094,6 +1104,8 @@ def economy_comparison_us(job_id: str, traceparent: str | None = None) -> None:
10941104
except Exception as db_error:
10951105
logfire.error("Failed to update DB", error=str(db_error))
10961106
raise
1107+
finally:
1108+
logfire.force_flush()
10971109

10981110

10991111
def _get_pe_policy_uk(policy_id, model_version, session):

0 commit comments

Comments
 (0)