2
votes

I'm comparing different tracing backend using OpenCensus. I already have the simple OpenCensus.io python samples running fine using Zipkin and Azure Monitor.

Now I'm trying to test using GCP's Stackdriver...

I have set up the test code from Opencensus https://opencensus.io/exporters/supported-exporters/python/stackdriver/ as follows:

#!/usr/bin/env python

import os

from opencensus.common.transports.async_ import AsyncTransport
from opencensus.ext.stackdriver.trace_exporter import StackdriverExporter
from opencensus.trace.tracer import Tracer

def main():
    sde = StackdriverExporter(
        project_id=os.environ.get("GCP_PROJECT_ID"),
        transport=AsyncTransport)

    tracer = Tracer(exporter=sde)
    with tracer.span(name="doingWork") as span:
        for i in range(10):
            pass

if __name__ == "__main__":
    main()

I have set the environment variable for GCP_PROJECT_ID and also have my key file path for my service account JSON file set in GOOGLE_APPLICATION_CREDENTIALS.

The service account has the "Cloud trace agent" role.

My code runs through with no errors but I can't see any info appearing in the GCP console under traces or in the monitoring dashboard.

Am I missing something?

Environment notes: I'm testing this from my local Windows machine using Python 3.7.2

1

1 Answers

1
votes

I was able to setup OpenCensus in GCP (in an instance on the project) by following the steps mentioned here.

To set it up quickly, here are the commands I ran in a brand new Ubuntu instance

sudo apt-get install python3
sudo apt install python3-pip
wget https://raw.githubusercontent.com/GoogleCloudPlatform/python-docs-samples/master/opencensus/requirements.txt
pip3 install -r requirements.txt
wget https://raw.githubusercontent.com/GoogleCloudPlatform/python-docs-samples/master/opencensus/metrics_quickstart.py
python3 metrics_quickstart.py