2

Any record logged from a GCP Cloud Function contains a labels.execution_id, e.g.:

{
  "textPayload": "Function execution started",
  "insertId": "12mylqhfm6hy8i",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "function_name": "redacted",
      "region": "europe-west2",
      "project_id": "redacted"
    }
  },
  "timestamp": "2022-09-26T10:57:26.917823762Z",
  "severity": "DEBUG",
  "labels": {
    "execution_id": "1l1qb00ft6kv"
  },
  "logName": "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
  "trace": "projects/redacted/traces/d2f793cf6e2fb149a8ce8dc6fd0498b4",
  "receiveTimestamp": "2022-09-26T10:57:26.920210899Z"
}

This is very useful for correlating all logs from a single invocation of the cloud function because it can be filtered upon in Logs Explorer:

labels.execution_id="1l1qb00ft6kv" 

I see no equivalent for Cloud Run though. Cloud Run logs do have labels.instance_id but my understanding is that that pertains to the Cloud Run app instance so will be the same for all invocations on that instance. Hence its not the same as Cloud Functions' labels.execution_id.

Does Cloud Run have an equivalent of Cloud Functions' execution_id or would I have to roll my own? If the latter, does anyone have any strategies for doing so?

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
jamiet
  • 10,501
  • 14
  • 80
  • 159

1 Answers1

2

No there isn't an execution ID, only the instanceID. To have that, you can use instrumentation tools, like Open Telemetry as mentioned by guillaume at stackoverflow question, you can refer this video. You can also customize the app logs with a custom/random execution ID (similar of what OT does).

Also Have a look at this link1 & link2 which might help

Sathi Aiswarya
  • 2,068
  • 2
  • 11