I have a microservice developed using FastAPI. We have implemented Zipkin tracing across all of our microservices. My microservice uses multiprocessing to process an iterable in parallel. If I create a span, then call another function which creates another span, I am able to see both the parent span and it's child spans in the trace when not using multiprocessing. However, I only see the parent span when using multiprocessing.
Here is a toy example to simulate both scenarios:
from multiprocessing import Pool
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from starlette_zipkin import ZipkinMiddleware, trace
app = FastAPI()
app.add_middleware(ZipkinMiddleware)
@app.get("/test")
def test():
with trace("test"):
for i in range(10):
function(i)
return JSONResponse("Done")
@app.get("/test_mp")
def test_mp():
with trace("test_mp"):
with Pool() as pool:
pool.map(function, list(range(10)))
return JSONResponse("Done")
def function(num: int):
with trace(f"in_function_{num}"):
print(num**2)
When I call /test
, the trace looks like this:
But when I call /test_mp
the trace only looks like this:
Is it possible to do tracing across different processes? Or does this break the idea of tracing?