1

I have a couple of Cloud Functions that make remote calls out to a 3rd party API and I would like to be able to gather latency metrics in Cloud Trace for those calls.

I'm trying to find a barebones working piece of example code that I can build off of. Only one I found is at https://medium.com/faun/tracing-python-cloud-functions-a17545586359

It is essentially.

import requests
from opencensus.trace import tracer as tracer_module
from opencensus.trace.exporters import stackdriver_exporter
from opencensus.trace.exporters.transports.background_thread \
    import BackgroundThreadTransport

PROJECT_ID = 'test-trace'
# instantiate trace exporter
exporter = stackdriver_exporter.StackdriverExporter(project_id=PROJECT_ID, transport=BackgroundThreadTransport)

def main_fun(data, context):
    tracer = tracer_module.Tracer(exporter=exporter)

    with tracer.span(name='get_token'):
        print('Getting Token')
        authtoken = get_token(email,password)
        print('Got Token')

def get_token(email,password):
    # Make some request out to an API and get a Token
    return accesstoken

There are no errors and everything works as intended, minus a trace not showing up in Cloud Trace or Stackdriver.

Am I doing something wrong here? Does anyone have some simple code that may work for Cloud Trace within a Cloud Function

Michin
  • 23
  • 4
  • As far as I know Cloud Functions are visible automatically in the trace and the article is just how to add more details.... Is it indeed nothing visible in the trace list? – vitooh Aug 14 '20 at 13:53
  • Correct, the Cloud Function as a whole is visible in Cloud Trace, but the detail around those specific detailed calls out to remote APIs are not visible. – Michin Aug 14 '20 at 21:50

0 Answers0