Skip to content

Instantly share code, notes, and snippets.

@sanealytics
Created June 20, 2020 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanealytics/b70f1cd89dc3caf3e8e543f460fefeaf to your computer and use it in GitHub Desktop.
Save sanealytics/b70f1cd89dc3caf3e8e543f460fefeaf to your computer and use it in GitHub Desktop.
Getting a service trace id
from requests import post
import json
GET_TID_URI='https://XXXX/get_service_trace_id'
TID_SERVICE_NAME='my_service'
TID_SERVICE_VERSION='1.0' # Automate this in CI/CD and read it in
TID_SERVICE_INSTANCE='default' # Get from Google environment variables
# For example
# TID_SERVICE_INSTANCE=f'{request.headers["X-Appengine-Queuename"]}-{request.headers["X-Appengine-Taskname"]}'
headers = {'content-type': 'application/json'}
data = {
'service': TID_SERVICE_NAME,
'instance': TID_SERVICE_INSTANCE,
'version': TID_SERVICE_VERSION,
'metadata': json.dumps({'prev_tids': prev_tids}) # A list of previous tids
}
r = post(GET_TID_URI, data=json.dumps(data), headers=headers)
assert(r.status_code == 200)
tid = r.json().get('tid')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment