Search code examples
google-cloud-functionsgoogle-cloud-rungoogle-cloud-logging

Execution ID on Google Cloud Run


I am wondering if there exists an execution id into Cloud Run as the one into Google Cloud Functions?

An ID that identifies each invocation separately, it's very useful to use the "Show matching entries" in Cloud Logging to get all logs related to an execution.

I understand the execution process is different, Cloud Run allows concurrency, but is there a workaround to assign each log to a certain execution?

My final need is to group at the same line the request and the response. Because, as for now, I am printing them separately and if a few requests arrive at the same time, I can't see what response corresponds to what request...

Thank you for your attention!


Solution

  • Open Telemetry looks like a great solution, but the learning and manipulation time isn't negligible,

    I'm going with a custom id created in before_request, stored in Flask g and called at every print().

    @app.before_request
    def before_request_func():
        
        execution_id = uuid.uuid4()
    
        g.execution_id = execution_id