Exemple #1
0
def enable_cloud_debugger():
    """https://cloud.google.com/debugger/docs/setup/python?hl=en_GB&_ga=2.68834001.-1991847693.1585366893"""
    try:
        import googleclouddebugger
        googleclouddebugger.enable()
    except ImportError:
        pass
def gcp_support() -> dict:
    try:
        import googleclouddebugger

        googleclouddebugger.enable()
    except ImportError as e:
        logging.error(
            f'Unable to import and enable stackdriver debugger: {str(e)}')
        pass

    try:
        db = firestore.Client()
        api_keys_ref = db.collection(u'api_keys').document(
            u'gvRhG4XnOHccmty4UoBU')
        doc = api_keys_ref.get()
        api_keys = doc.to_dict()
        logging.info('API Keys successfully retrieved.')
        return api_keys
    except NotFound as e:
        api_keys = {'twilio_sid': 'TWILIO_SID_NOT_FOUND'}
        logging.error(
            f'The API keys could not be retrieved from Firestore: {str(e)}')
        return api_keys
    except Exception as e:
        api_keys = {'twilio_sid': 'TWILIO_SID_NOT_FOUND'}
        logging.error(
            f'Firestore client failed to init. The fact sender service will run in local only mode: {str(e)}'
        )
        return api_keys
Exemple #3
0
def _setup_cloud_debugger():
    try:
        import googleclouddebugger
        googleclouddebugger.enable(
            breakpoint_enable_canary=True
        )
    except DefaultCredentialsError as error:
        logger.error(str(error))
Exemple #4
0
def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'newsApp.settings')
    try:
        import googleclouddebugger
        googleclouddebugger.enable(
            breakpoint_enable_canary=True
        )
    except ImportError:
        pass
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)
Exemple #5
0
def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?") from exc
    execute_from_command_line(sys.argv)

    # Attach the Python Cloud debugger (only the main server process).
    if os.environ.get('RUN_MAIN') or '--noreload' in sys.argv:
        try:
            import googleclouddebugger
            googleclouddebugger.enable(module='[mainpage]', version='[1.0]')
        except ImportError:
            pass
Exemple #6
0
def hello_world(request):
    """Responds to any HTTP request.
    Args:
        request (flask.Request): HTTP request object.
    Returns:
        The response text or any set of values that can be turned into a
        Response object using
        `make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
    """
    try:
        import googleclouddebugger

        googleclouddebugger.enable()
    except ImportError:
        pass

    request_json = request.get_json()
    a = 3 / 0
    if request.args and 'message' in request.args:
        return request.args.get('message')
    elif request_json and 'message' in request_json:
        return request_json['message']
    else:
        return f'Hello World!'
Exemple #7
0
try:
    import googleclouddebugger
    googleclouddebugger.enable(
        module='listings',
        version='0.0.1',
        service_account_json_file='../litvinenko-test-95b1a12d7810.json')
except ImportError:
    pass

from flask import Flask
from pymongo import MongoClient
import pprint

app = Flask(__name__)
client = MongoClient('listings-db')
db = client.listings


@app.route('/')
def hello_world():
    return "Hello from listings service!\n"


@app.route('/listings')
def listings_get():
    return pprint.pformat(list(db.listings.find()))


@app.route('/listings/create/<title>')
def listings_create(title):
    result = db.listings.insert_one({'name': title})
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from quiz import app

# TODO: Add the following statement to import and start
# Stackdriver debug-agent
# The start(...) method takes an 'options' object that you 
# can use to configure the Stackdriver Debugger agent.
# You will need to pass through an object with an 
# allowExpressions Boolean property set to true.

try:
  import googleclouddebugger
  googleclouddebugger.enable(
      enable_service_account_auth=True,
      project_id='my-gcp-project-id',
      project_number='123456789',
      service_account_json_file='/opt/cdbg/gcp-svc.json')
except ImportError:
  pass

# END TODO

app.run(debug=True, port=8080)
Exemple #9
0
try:
    import googleclouddebugger

    googleclouddebugger.enable(
        module='listings',
        version='0.0.1',
        service_account_json_file='/etc/app/secrets/gcp-service-account.json'
    )
except BaseException as e:
    print('ERROR!!!!!!!!', e)

from flask import Flask, abort
from pymongo import MongoClient
from bson import ObjectId
import pprint
import sys
import os

from celery import Celery

sys.path.append('/etc/app/config')

app = Flask(__name__)
client = MongoClient('listings-db')
db = client.listings

celery = Celery('tasks',
                broker=os.getenv('CELERY_BROKER_URL'),
                result=os.getenv('CELERY_RESULT_BACKEND'))
celery.conf.task_default_queue = 'megaphone'
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
try:
  import googleclouddebugger
  googleclouddebugger.enable(
    breakpoint_enable_canary=False
  )
import firestore
from flask import current_app, flash, Flask, Markup, redirect, render_template
from flask import request, url_for
from google.cloud import error_reporting
import google.cloud.logging
import storage


# [START upload_image_file]
def upload_image_file(img):
    """
    Upload the user-uploaded file to Google Cloud Storage and retrieve its
    publicly-accessible URL.
    """
Exemple #11
0
try:
    import google.auth.exceptions
    try:
        import googleclouddebugger
        googleclouddebugger.enable(module='notif-app-icons')
    except (ImportError, google.auth.exceptions.DefaultCredentialsError):
        print("Couldn't start cloud debugger")
except ImportError:
    print("Couldn't import google exceptions")

import json
from os import environ

import beeline
from beeline.middleware.flask import HoneyMiddleware
from flask import Flask, request, jsonify

app = Flask(__name__)

if environ.get('HONEYCOMB_KEY'):
    beeline.init(writekey=environ['HONEYCOMB_KEY'],
                 dataset='rws',
                 service_name='lp')
    HoneyMiddleware(app, db_events=True)

with open('language_packs.json') as f:
    languages = json.load(f)['languages']


def urlify(pack):
    return {**pack, 'file': f"https://binaries.rebble.io/lp/{pack['file']}"}
Exemple #12
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from quiz import app

# TODO: Add the following statement to import and start
# Stackdriver debug-agent
# The start(...) method takes an 'options' object that you
# can use to configure the Stackdriver Debugger agent.
# You will need to pass through an object with an
# allowExpressions Boolean property set to true.

try:
    import googleclouddebugger
    googleclouddebugger.enable(
        enable_service_account_auth=True,
        project_id='my-gcp-project-id',
        project_number='123456789',
        service_account_json_file='/opt/cdbg/gcp-svc.json')
except ImportError:
    pass

# END TODO

app.run(debug=True, port=8080)
    logger.info("initializing recommendationservice")

    # OpenTelemetry Tracing
    # TracerProvider provides global state and access to tracers.
    trace.set_tracer_provider(TracerProvider())

    # Export traces to Google Cloud Trace
    # When running on GCP, the exporter handles authentication
    # using automatically default application credentials.
    # When running locally, credentials may need to be set explicitly.
    cloud_trace_exporter = CloudTraceSpanExporter()
    trace.get_tracer_provider().add_span_processor(
        SimpleExportSpanProcessor(cloud_trace_exporter))

    try:
        googleclouddebugger.enable(module='recommendationservice', )
    except (Exception, err):
        logger.error("could not enable debugger")
        logger.error(traceback.print_exc())
        pass

    port = os.environ.get('PORT', "8080")
    catalog_addr = os.environ.get('PRODUCT_CATALOG_SERVICE_ADDR', '')
    if catalog_addr == "":
        raise Exception(
            'PRODUCT_CATALOG_SERVICE_ADDR environment variable not set')
    logger.info("product catalog address: " + catalog_addr)

    # Create the gRPC client channel to ProductCatalog (server).
    channel = grpc.insecure_channel(catalog_addr)
Exemple #14
0
try:
    import google.auth.exceptions
    try:
        import googleclouddebugger
        googleclouddebugger.enable(module='appstore-api')
    except (ImportError, google.auth.exceptions.DefaultCredentialsError):
        print("Couldn't start cloud debugger")
except ImportError:
    print("Couldn't import google exceptions")

from flask import Flask, jsonify, request
from werkzeug.middleware.proxy_fix import ProxyFix
from rws_common import honeycomb

from .settings import config

from .models import init_app as init_models
from .api import init_app as init_api
from .dev_portal_api import init_app as init_dev_portal_api
from .developer_portal_api import init_app as init_developer_portal_api
from .commands import init_app as init_commands
from .utils import init_app as init_utils
from .locker import locker

app = Flask(__name__)
app.config.update(**config)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)

honeycomb.init(app, 'appstore-api')
honeycomb.sample_routes['api.locker'] = 10
honeycomb.debug_tokens['wDvxMgcf'] = True # andrusca
Exemple #15
0
import logging
log = logging.getLogger()
try:
    import googleclouddebugger
    googleclouddebugger.enable(module='gcf-demo', version='1')
except ImportError:
    log.exception()

from google.cloud import error_reporting
client = error_reporting.Client()


def hello_world(request):
    """Responds to any HTTP request.
    Args:
        request (flask.Request): HTTP request object.
    Returns:
        The response text or any set of values that can be turned into a
        Response object using
        `make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
    """
    try:
        request_json = request.get_json()
        if request.args and 'message' in request.args:
            raise Exception('intentional error!')
            message = request.args.get('message')
        elif request_json and 'message' in request_json:
            message = request_json['message']
        else:
            message = f'Hello World!'
    'STORAGE_BUCKETS_FILE', 'storageBucketsBackendServiceKey.json'
)
STATICFILES_STORAGE = 'utils.classes.GoogleStaticFilesStorage'  # static
DEFAULT_FILE_STORAGE = 'utils.classes.GoogleMediaFilesStorage'  # media
GS_AUTO_CREATE_BUCKET = True
GS_DEFAULT_ACL = 'publicRead'
GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
    f'/usr/src/app/{SB_SA_FILE}'
)
GS_BUCKET_NAME = os.environ.get('GS_BUCKET_NAME')

try:
    import googleclouddebugger

    googleclouddebugger.enable(
        module='django', version=os.environ.get('ENV', 'master')
    )
    print('worked debugger on try')
    # Will work upon GKE deployment
except ImportError:
    print('cloud debugger execption')

# with open('/usr/src/app/django_email.json') as data_file:  # required for error notification
#     data = json.load(data_file)
#     EMAIL_HOST = data['EMAIL_HOST']
#     EMAIL_HOST_USER = data['EMAIL_HOST_USER']
#     SERVER_EMAIL = EMAIL_HOST_USER
#     EMAIL_HOST_PASSWORD = data['EMAIL_HOST_PASSWORD']
#     EMAIL_PORT = int(data['EMAIL_PORT'])
#     EMAIL_USE_TLS = True
#     DEFAULT_TO_EMAIL = data['DEFAULT_TO_EMAIL'].split(',')
            status=health_pb2.HealthCheckResponse.SERVING)


if __name__ == "__main__":
    logger.info("initializing recommendationservice")

    try:
        sampler = always_on.AlwaysOnSampler()
        exporter = stackdriver_exporter.StackdriverExporter()
        tracer_interceptor = server_interceptor.OpenCensusServerInterceptor(sampler, exporter)
    except:
        tracer_interceptor = server_interceptor.OpenCensusServerInterceptor()

    try:
        googleclouddebugger.enable(
            module='recommendationserver',
            version='1.0.0'
        )
    except Exception, err:
        logger.error("could not enable debugger")
        logger.error(traceback.print_exc())
        pass

    port = os.environ.get('PORT', "8080")
    catalog_addr = os.environ.get('PRODUCT_CATALOG_SERVICE_ADDR', '')
    if catalog_addr == "":
        raise Exception('PRODUCT_CATALOG_SERVICE_ADDR environment variable not set')
    logger.info("product catalog address: " + catalog_addr)
    channel = grpc.insecure_channel(catalog_addr)
    product_catalog_stub = demo_pb2_grpc.ProductCatalogServiceStub(channel)

    # create gRPC server
# lines = cv2.HoughLinesP(cropped_image, 2, np.pi/180, 100, np.array([()]), minLineLength=40, maxLineGap=5)
# averaged_lines = average_slope_intercept(lane_image, lines)
# line_image = display_lines(lane_image, averaged_lines)
# combo_image = cv2.addWeighted(lane_image, 0.8, line_image, 1, 1)

#cv2.imshow('result', combo_image)
#cv2.waitKey(0)
"""Debugger for GCP"""

if __name__ == '__main__':

    try:
        import googleclouddebugger
        googleclouddebugger.enable(
            module='[detection]',
            version='[v 1.0]',
            service_account_json_file=
            '/Users/admin/Downloads/savvy-etching-254922-e6fda8dabd2c.json')
    except ImportError:
        pass
"""VIDEO DETECTION LINE'S"""

cap = cv2.VideoCapture("test2.mp4")

while (cap.isOpened()):

    _, frame = cap.read()
    canny_image = canny(frame)
    cropped_image = region_of_interest(canny_image)
    lines = cv2.HoughLinesP(cropped_image,
                            2,
Exemple #19
0
@app.route("/bug")
def bug():
    client = error_reporting.Client()
    saludo = "hola"
    cuenta = 5 + 10
    logging.info(saludo)
    try:
        # simulate calling a method that's not defined
        raise NameError
    except Exception:
        client.report_exception()
    return "Bug!"

if __name__ == "__main__":
    googleclouddebugger.enable(
        module='[MODULE]',
        version='[VERSION]',
        breakpoint_enable_canary=True
    )
    config_integration.trace_integrations(['logging','requests'])
    parser = argparse.ArgumentParser()
    parser.add_argument("--keyword",  default="", help="name of the service.")
    parser.add_argument("--endpoint", default="", help="endpoint to dispatch appended string, simply respond if not set")
    args = parser.parse_args()
    app.config['keyword'] = args.keyword
    app.config['endpoint'] = args.endpoint
    # [START trace_demo_create_exporter]
    createMiddleWare(StackdriverExporter())
    # [END trace_demo_create_exporter]
    app.run(debug=True, host='0.0.0.0', port=8080)
            exporter = stackdriver_exporter.StackdriverExporter(
                project_id=os.environ.get('GCP_PROJECT_ID'),
                transport=AsyncTransport)
            tracer_interceptor = server_interceptor.OpenCensusServerInterceptor(
                sampler, exporter)
    except (KeyError, DefaultCredentialsError):
        logger.info("Tracing disabled.")
        tracer_interceptor = server_interceptor.OpenCensusServerInterceptor()

    try:
        if "DISABLE_DEBUGGER" in os.environ:
            raise KeyError()
        else:
            logger.info("Debugger enabled.")
            try:
                googleclouddebugger.enable(module='reviewserver',
                                           version='1.0.0')
            except (Exception, DefaultCredentialsError):
                logger.error("Could not enable debugger")
                logger.error(traceback.print_exc())
                pass
    except (Exception, DefaultCredentialsError):
        logger.info("Debugger disabled.")

    port = os.environ.get('PORT', "8080")

    # create gRPC server
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),
                         interceptors=(tracer_interceptor, ))

    # add class to gRPC server
    service = ReviewService()
Exemple #21
0
from opentelemetry import trace
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.instrumentation.grpc import server_interceptor
from opentelemetry.instrumentation.grpc.grpcext import intercept_channel
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor

# import googleclouddebugger
import googlecloudprofiler

from logger import getJSONLogger
logger = getJSONLogger('emailservice-server')

try:
    import googleclouddebugger
    googleclouddebugger.enable(module='emailserver', version='1.0.0')
except ImportError:
    logger.error("could not enable debugger")
    logger.error(traceback.print_exc())
    pass

# Loads confirmation email template from file
env = Environment(loader=FileSystemLoader('templates'),
                  autoescape=select_autoescape(['html', 'xml']))
template = env.get_template('confirmation.html')


class BaseEmailService(demo_pb2_grpc.EmailServiceServicer):
    def Check(self, request, context):
        return health_pb2.HealthCheckResponse(
            status=health_pb2.HealthCheckResponse.SERVING)
Exemple #22
0
import logging

from flask import Flask
from flask_cors import CORS
from flask_restful import Api, Resource

from engine import IQueryable, LoadModel, process_args

try:
    import googleclouddebugger

    googleclouddebugger.enable(
        module='API server',
        version='1.0.6'
    )
except ImportError as e:
    print('Failed to import Google Cloud Debugger: %s' % str(e))
    pass

app = Flask(__name__)
api = Api(app)
# TODO make CORS more granual
CORS(app)


class Articles(Resource):

    def __init__(self, queryable: IQueryable = LoadModel()) -> None:
        self.queryable = queryable

    # @marshal_with(resource_fields)
Exemple #23
0
    mildredleague,
    timecapsule,
    users,
)
from src.api.index import index_api
from src.api.autobracket import ab_api
from src.api.haveyouseenx import hysx_api
from src.api.mildredleague import ml_api
from src.api.users import users_api
from src.db.startup import motor_startup, motor_shutdown

# GCP debugger
try:
    import googleclouddebugger
    googleclouddebugger.enable(
        breakpoint_enable_canary=False,
        service_account_json_file=GCP_FILE,
    )
except ImportError:
    pass


def multiproc_context():
    # possible multiprocessing solution from https://github.com/tiangolo/fastapi/issues/1487
    # this prevents gunicorn workers from crashing on multiprocessing!
    multiprocessing.set_start_method('spawn')


def create_fastapi_app():
    # create the root and API FastAPI apps
    view_app = FastAPI(
        title="tarpey.dev",
Exemple #24
0
                transport=AsyncTransport)
            tracer_interceptor = server_interceptor.OpenCensusServerInterceptor(
                sampler, exporter)
            tracer = Tracer(exporter=exporter)

    except (KeyError, DefaultCredentialsError):
        logger.info("Tracing disabled.")
        tracer_interceptor = server_interceptor.OpenCensusServerInterceptor()

    try:
        if "DISABLE_DEBUGGER" in os.environ:
            raise KeyError()
        else:
            logger.info("Debugger enabled.")
            try:
                googleclouddebugger.enable(module='recommendationserver',
                                           version='1.0.0')
            except Exception, err:
                logger.error("Could not enable debugger")
                logger.error(traceback.print_exc())
                pass
    except KeyError:
        logger.info("Debugger disabled.")

    port = os.environ.get('PORT', "8080")
    catalog_addr = os.environ.get('PRODUCT_CATALOG_SERVICE_ADDR', '')
    if catalog_addr == "":
        raise Exception(
            'PRODUCT_CATALOG_SERVICE_ADDR environment variable not set')
    logger.info("product catalog address: " + catalog_addr)

    client_tracer_interceptor = client_interceptor.OpenCensusClientInterceptor(
Exemple #25
0
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
from opentelemetry.instrumentation.grpc import server_interceptor
from opentelemetry.propagators.cloud_trace_propagator import CloudTraceFormatPropagator
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

import demo_pb2
import demo_pb2_grpc
from logger import get_json_logger

logger = get_json_logger("emailservice-server")

try:
    import googleclouddebugger

    googleclouddebugger.enable(module="emailserver", version="1.0.0")
except ImportError:
    logger.error("could not enable debugger")
    logger.error(traceback.print_exc())

# Loads confirmation email template from file
env = Environment(loader=FileSystemLoader("templates"),
                  autoescape=select_autoescape(["html", "xml"]))
template = env.get_template("confirmation.html")


class BaseEmailService(demo_pb2_grpc.EmailServiceServicer):
    def Check(self, request, context):
        return health_pb2.HealthCheckResponse(
            status=health_pb2.HealthCheckResponse.SERVING)
Exemple #26
0
from django_site.wsgi import application


try:
    import googleclouddebugger

    googleclouddebugger.enable()
except ImportError:
    pass


app = application
Exemple #27
0
def start_debugger():
    try:
        import googleclouddebugger
        googleclouddebugger.enable()
    except ImportError:
        pass