This file contains 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 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 |
This file contains 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 googleapiclient import discovery | |
from oauth2client.client import GoogleCredentials | |
class TraceContext(object): | |
def write(self): | |
# Build our JSON blob | |
# …... | |
This file contains 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
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] |
This file contains 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
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') |
This file contains 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
# to import the libraries. | |
import os | |
from google.appengine.api import app_identity | |
… | |
projectId = app_identity.get_application_id() |
This file contains 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
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: |
This file contains 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
# create a thread-local global context | |
_trace_context = threading.local() | |
##=============================================================== | |
class TraceContext(object): | |
def __enter__(self): | |
self.start() | |
return self |
This file contains 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
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): |
This file contains 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
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" |
This file contains 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
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
import scipy.ndimage | |
import scipy.signal |
NewerOlder