Created
          June 20, 2020 16:31 
        
      - 
      
- 
        Save sanealytics/b70f1cd89dc3caf3e8e543f460fefeaf to your computer and use it in GitHub Desktop. 
Revisions
- 
        sanealytics created this gist Jun 20, 2020 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ 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')