google-cloud-trace will allow you to connect to the Stackdriver Trace API and access all its methods. In order to achieve this, you need to set up authentication as well as install the library locally.
Install this library in a virtualenv using pip. virtualenv is a tool to create isolated Python environments. The basic problem it addresses is one of dependencies and versions, and indirectly permissions.
With virtualenv, it's possible to install this library without needing system install permissions, and without clashing with the installed system dependencies.
pip install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install google-cloud-tracepip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install google-cloud-traceTo authenticate all your API calls, first install and setup the Google Cloud SDK. Once done, you can then run the following command in your terminal:
$ gcloud beta auth application-default loginor
$ gcloud auth loginPlease see gcloud beta auth application-default login document for the difference between these commands.
At this point you are all set to continue.
from google.cloud.trace import client
client = client.Client(project_id='your_project_id')
# Patch traces, traces should be a dict
client.patch_traces(traces=traces)
# Get trace
client.get_trace(trace_id='your_trace_id')
# List traces
traces = client.list_traces()
for trace in traces:
print(trace)