Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mainroach
Created May 31, 2017 14:13
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 mainroach/61f2f8d16e3ee76b89fabcd1b4f0e2c1 to your computer and use it in GitHub Desktop.
Save mainroach/61f2f8d16e3ee76b89fabcd1b4f0e2c1 to your computer and use it in GitHub Desktop.
class TraceContext(object):
def write(self):
# Breakup our given cloud tracing context so we can get the flags out of it
trace_id, root_span_id = self.cloud_trace_context.split(';')[0].split('/')
# Grab our spans object as a json blob
spans = [s.json() for s in _trace_context.spans]
#catch
if len(spans)==0:
spans.append({"spanId":16384})
for s in spans:
s['parentSpanId'] = root_span_id
traces_body = {
'projectId': projectId,
'traceId': trace_id,
'spans': spans
}
body={
"traces":[traces_body]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment