@@ -78,7 +78,7 @@ def configure_logfire(service_name: str, traceparent: str | None = None):
7878
7979 token = os .environ .get ("LOGFIRE_TOKEN" , "" )
8080 if not token :
81- return None
81+ return
8282
8383 logfire .configure (
8484 service_name = service_name ,
@@ -89,15 +89,14 @@ def configure_logfire(service_name: str, traceparent: str | None = None):
8989
9090 # If traceparent provided, attach to the current context
9191 if traceparent :
92+ from opentelemetry import context
9293 from opentelemetry .trace .propagation .tracecontext import (
9394 TraceContextTextMapPropagator ,
9495 )
9596
9697 propagator = TraceContextTextMapPropagator ()
9798 ctx = propagator .extract (carrier = {"traceparent" : traceparent })
98- return ctx
99-
100- return None
99+ context .attach (ctx )
101100
102101
103102def get_database_url () -> str :
@@ -167,9 +166,9 @@ def simulate_household_uk(
167166 import logfire
168167 from sqlmodel import Session , create_engine
169168
170- ctx = configure_logfire ("policyengine-modal-uk" , traceparent )
169+ configure_logfire ("policyengine-modal-uk" , traceparent )
171170
172- with logfire .span ("simulate_household_uk" , job_id = job_id , _context = ctx ):
171+ with logfire .span ("simulate_household_uk" , job_id = job_id ):
173172 logfire .info ("Starting UK household calculation" , job_id = job_id )
174173
175174 database_url = get_database_url ()
@@ -298,9 +297,9 @@ def simulate_household_us(
298297 import logfire
299298 from sqlmodel import Session , create_engine
300299
301- ctx = configure_logfire ("policyengine-modal-us" , traceparent )
300+ configure_logfire ("policyengine-modal-us" , traceparent )
302301
303- with logfire .span ("simulate_household_us" , job_id = job_id , _context = ctx ):
302+ with logfire .span ("simulate_household_us" , job_id = job_id ):
304303 logfire .info ("Starting US household calculation" , job_id = job_id )
305304
306305 database_url = get_database_url ()
@@ -424,9 +423,9 @@ def simulate_economy_uk(simulation_id: str, traceparent: str | None = None) -> N
424423 import logfire
425424 from sqlmodel import Session , create_engine
426425
427- ctx = configure_logfire ("policyengine-modal-uk" , traceparent )
426+ configure_logfire ("policyengine-modal-uk" , traceparent )
428427
429- with logfire .span ("simulate_economy_uk" , simulation_id = simulation_id , _context = ctx ):
428+ with logfire .span ("simulate_economy_uk" , simulation_id = simulation_id ):
430429 logfire .info ("Starting UK economy simulation" , simulation_id = simulation_id )
431430
432431 database_url = get_database_url ()
@@ -540,9 +539,9 @@ def simulate_economy_us(simulation_id: str, traceparent: str | None = None) -> N
540539 import logfire
541540 from sqlmodel import Session , create_engine
542541
543- ctx = configure_logfire ("policyengine-modal-us" , traceparent )
542+ configure_logfire ("policyengine-modal-us" , traceparent )
544543
545- with logfire .span ("simulate_economy_us" , simulation_id = simulation_id , _context = ctx ):
544+ with logfire .span ("simulate_economy_us" , simulation_id = simulation_id ):
546545 logfire .info ("Starting US economy simulation" , simulation_id = simulation_id )
547546
548547 database_url = get_database_url ()
@@ -656,9 +655,9 @@ def economy_comparison_uk(job_id: str, traceparent: str | None = None) -> None:
656655 import logfire
657656 from sqlmodel import Session , create_engine
658657
659- ctx = configure_logfire ("policyengine-modal-uk" , traceparent )
658+ configure_logfire ("policyengine-modal-uk" , traceparent )
660659
661- with logfire .span ("economy_comparison_uk" , job_id = job_id , _context = ctx ):
660+ with logfire .span ("economy_comparison_uk" , job_id = job_id ):
662661 logfire .info ("Starting UK economy comparison" , job_id = job_id )
663662
664663 database_url = get_database_url ()
@@ -888,9 +887,9 @@ def economy_comparison_us(job_id: str, traceparent: str | None = None) -> None:
888887 import logfire
889888 from sqlmodel import Session , create_engine
890889
891- ctx = configure_logfire ("policyengine-modal-us" , traceparent )
890+ configure_logfire ("policyengine-modal-us" , traceparent )
892891
893- with logfire .span ("economy_comparison_us" , job_id = job_id , _context = ctx ):
892+ with logfire .span ("economy_comparison_us" , job_id = job_id ):
894893 logfire .info ("Starting US economy comparison" , job_id = job_id )
895894
896895 database_url = get_database_url ()
0 commit comments