How to Maintain Trace Association in Parallel Python Processes
RunLLM I have the following python code: def play_round(self): with tracer.start_as_current_span("play_round") as span: span.set_attribute(SpanAttributes.INPUT_VALUE, self.game_state.model_dump_json()) span.set_attribute(SpanAttributes.OPENINFERENCE_SPAN_KIND, OpenInferenceSpanKindValues.CHAIN.value) pairs = self.create_donor_recipient_pairs() span.set_attribute(SpanAttributes.OUTPUT_VALUE, json.dumps([f"{donor.name} -> {recipient.name}" for donor, recipient in pairs])) # TODO: can be parallelized but need to keep wallets static untill the end with ThreadPoolExecutor() as executor: futures = [ executor.submit(donor.setup_donation, recipient, self.game_state, self.players) for donor, recipient in pairs ] # Wait for all donations to complete results = [future.result() for future in futures] for result in results: donor = self.find_player(result.donor_name) recipient = self.find_player(result.recipient_name) donor.execute_donation(recipient, self.game_state, result) self.game_state.round += 1 When I execute this the traces within setup_donation are no longer assiciated to the parent play_round and instead become independent, how can I prevent this, note that before I added parallelization of processes things there were spans inside play_round.
