Skip to content

Instantly share code, notes, and snippets.

@mainroach
Created May 31, 2017 14:14
Show Gist options
  • Save mainroach/178b2f9b73ccb228ad63c1f88fa27033 to your computer and use it in GitHub Desktop.
Save mainroach/178b2f9b73ccb228ad63c1f88fa27033 to your computer and use it in GitHub Desktop.
from cloud_trace_gae import Trace
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
TContext = "NNNN/NNNN;xxxxx"
if 'X-Cloud-Trace-Context' in self.request.headers:
TContext=self.request.headers.get('X-Cloud-Trace-Context')
logging.info(TContext)
# Let's just trace some stuff
with TraceContext(TContext) as root:
time.sleep(0.1)
with root.span("slow") as spn:
time.sleep(2)
with root.span("my slow") as spn:
time.sleep(2)
with root.span("penut butter") as spn:
time.sleep(2)
@edwardfung123
Copy link

I got the same GAE performance problem as you described in medium and youtube. I think the indentation is wrong.

Should it be?

from cloud_trace_gae import Trace
import webapp2

class MainPage(webapp2.RequestHandler):
  def get(self):
    TContext = "NNNN/NNNN;xxxxx"
    if 'X-Cloud-Trace-Context' in self.request.headers:
      TContext=self.request.headers.get('X-Cloud-Trace-Context')
      logging.info(TContext)
 
    # Let's just trace some stuff
    with TraceContext(TContext) as root:
      time.sleep(0.1)
      with root.span("slow") as spn:
        time.sleep(2)
      with root.span("my slow") as spn:
        time.sleep(2)
      with root.span("penut butter") as spn:
        time.sleep(2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment