Created
June 20, 2020 16:31
-
-
Save sanealytics/b70f1cd89dc3caf3e8e543f460fefeaf to your computer and use it in GitHub Desktop.
Getting a service trace id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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