Skip to content

Instantly share code, notes, and snippets.

Colt McAnlis mainroach

Block or report user

Report or block mainroach

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gcpa0124-008.py
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
View gcpa0124-007.py
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
class TraceContext(object):
def write(self):
# Build our JSON blob
# …...
View gcpa0124-006.py
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]
View gcpa0124-005.py
class MainHandler(webapp2.RequestHandler):
def get(self):
# When on dev-server, this value isn't there. So we have to catch that.
TContext = "NNNN/NNNN;xxxxx"
if 'X-Cloud-Trace-Context' in self.request.headers:
TContext=self.request.headers.get('X-Cloud-Trace-Context')
View gcpa0124-004.py
# to import the libraries.
import os
from google.appengine.api import app_identity
projectId = app_identity.get_application_id()
View gcpa0124-003.py
class MainHandler(webapp2.RequestHandler):
def get(self):
# Let's just trace some stuff
with TraceContext() 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:
View gcpa0124-002.py
# create a thread-local global context
_trace_context = threading.local()
##===============================================================
class TraceContext(object):
def __enter__(self):
self.start()
return self
View gcpa0124-001.py
class Span(object):
def __init__(self, name, kind='SPAN_KIND_UNSPECIFIED'):
self.id = str(random.getrandbits(64))
self.name = name
self.kind = kind
def start(self):
View gcpa008-001.sh
apt-get update
# Install tornado (and pip, which is needed)
apt-get install -y python-pip
pip install tornado
pip install futures
# Grab our specific scripts for the Service
sudo mkdir "/home/myservice/scripts/"
gsutil cp "gs://xxxxxxxxxxxxxx/myservice/service.py" "/home/myservice/scripts/service.py"
View gcpa006-001.py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import scipy.ndimage
import scipy.signal
You can’t perform that action at this time.