APM + Flask + Multiprocessing = No Spans


(Lukas Nagel) #1

I am trying to capture some spans in my Python Flask app using the decorator:
@elasticapm.capture_span()

This works perfectly, until I execute a couple of functions in parallel using python's multiprocessing module. These spans are then never captured (the spans set in the main process are still captured). Within these functions, I am also not able to send an error or message (apm.capture_message()).

I use multiprocessing.Process and multiprocessing.Pipe to parallelize the execution of a list of functions.

I would love for each of these functions to be captured as individual spans within the request transaction.

Does anyone have experience with capturing parallel spans using Flask and Elastic APM?


(Benjamin Wohlwend @ APM) #2

Hi @nagellack

unfortunately, this is not something we currently support. The information about ongoing transactions/spans is stored in a thread local (on Python 3.7 it's in a contextvar variable, but that amounts to to more or less the same thing in this case).

I will look into ways to achieve this, but it's a non-trivial problem and I can't say when we might support this use case.


(Lukas Nagel) #3

Hey - Thanks for the response.

I look forward to it - possibly - being supported!