Trace, Profiling not available for Cloud Functions ?

Im trying to implement observability on GCP, particularly on Cloud Functions.

Facing issues in regards to have tracing to see my request flows and find issues in a request when using GCP Cloud Functions. Have two functions with F1 receiving a request which triggers F2 five times. All triggers well but each function gets its own trace ID and therefore the TraceAPI doesn't show them as single request.

Tried with this lab : https://codelabs.developers.google.com/codelabs/cloud-function-logs-traces?continue=https%3A%2F%2Fde...

Similar lab for Spring Boot app worked in propagating the traces : https://codelabs.developers.google.com/codelabs/cloud-spring-cloud-gcp-trace#0

---

Has GCP Functions changed in how trace ID is propagated and is there a working sample code I can access ?

--- 

Also don't see profiling as available for cloud functions ? Is that so ? I could only find articles from 2018 saying its not yet available but no official docs state its current state.

---

Let me know if I need to add more data on what I tried to get better help. Hoping to move forward with this or get some definitive answers.

0 5 612
5 REPLIES 5

Hello @bharathyesTC 

Welcome to the Google Cloud Community!

Looking into the Cloud Trace API, It lets you send latency data to, and retrieve from Cloud Trace. It seems that the Cloud Trace API cannot be used with Cloud Functions. Cloud Trace API is used for applications you run locally like the following environments:

  • Compute Engine
  • GKE
  • App Engine flexible/standard environment
  • Cloud Run
  • Non-Google Cloud Environments

That is why Cloud functions use Stackdriver Logging and Stackdriver Trace and see the logs as a whole. 

You can also contact Google Cloud Support to further look into your case. Let me know if it helped, thanks!

hi @Marramirez 

The issue I am facing is with regards to the Cloud Function themselves. Running locally the traceID is properly propagated between functions. But when the same is deployed and tested, each function gets their own traceID, ie., not being propagated.

Also the same is getting pushed to the TraceAPI but since each has its own traceID they show as separate calls. THIS is my main issue that I am currently trying to solve.

My end goal is to get trace ID propagate between:

"Cloud Function to a Spring app on Cloud Run and back, and then to another Cloud Function triggered via PubSub."

PS: Are stackdriver trace the same as Cloud trace ? The distinction between them is not clear to me. 

You must propagate trace headers in your application code, it is not done automatically. If you are looking to have everything instrumented between using http and pubsub, you will need to use open telemetry SDK in your app. Then application will get trace Id and parent span, and create spans inside it, it then will also add current span and the same I'd to outgoing http requests and messages. 

I personally ended up having custom propagation for pubsub as the one included in official pubsub package was not good enough for me, so I just store trace and span id' as message attributes, and upon reading message from pubsub, first look into attributes, and continue distributed trace if it was present. Hope it helps.

PS Yes, stackdriver was renamed into operations suite , so they are same, but stackdriver is deprecated name.

It looks like this thread is more than a half-year old. If it is still relevant there is a documentation page about distributed tracing in Cloud Functions. Unfortunately it does not provide code samples.

As described in the documentation, for distributed tracing you will need to implement your own tracing solution. It is true also for the use cases when the function represents a span in an transaction that is initiated outside of the function.