Exemplo n.º 1
0
def on_preload_parsed(options, **kwargs):
    """
    This actually configures celery from pyramid config file
    """
    celery.conf['INI_PYRAMID'] = options['ini']
    ini_location = options['ini']
    if not ini_location:
        raise Exception('You need to pass pyramid ini location using '
                        '--ini=filename.ini argument to the worker')
    env = bootstrap(ini_location)
    try:
        import appenlight_client.client as appenlight_client
        from appenlight_client.ext.celery import register_signals
        api_key = env['request'].registry.settings['appenlight.api_key']
        tr_config = env['request'].registry.settings.get(
            'appenlight.transport_config')
        config = appenlight_client.get_config({'appenlight.api_key': api_key})
        if tr_config:
            config['appenlight.transport_config'] = tr_config
        appenlight_client = appenlight_client.Client(config)
        register_signals(appenlight_client)
    except ImportError:
        pass

    celery.pyramid = env
Exemplo n.º 2
0
    def pserve(self, *args, **kwargs):
        argv = sys.argv
        quiet = False
        ini_path = os.environ.get('APPENLIGHT_INI')
        config = {}
        if not ini_path:
            print "APPENLIGHT_INI variable is missing from environment/run cmd"
        else:
            config = client.get_config(path_to_config=ini_path)
        if not config.get('appenlight'):
            print 'WARNING Could not instantiate the client properly'
        else:
            client.Client(config)
        from pyramid.scripts import pserve

        command = pserve.PServeCommand(argv[1:], quiet=quiet)
        return command.run()
Exemplo n.º 3
0
    def pserve(self, *args, **kwargs):
        argv = sys.argv
        quiet = False
        ini_path = os.environ.get('APPENLIGHT_INI')
        config = {}
        if not ini_path:
            print("APPENLIGHT_INI variable is missing from environment/run cmd")
        else:
            config = client.get_config(path_to_config=ini_path)
        if not config.get('appenlight'):
            print('WARNING Could not instantiate the client properly')
        else:
            client.Client(config)
        from pyramid.scripts import pserve

        command = pserve.PServeCommand(argv[1:], quiet=quiet)
        return command.run()
Exemplo n.º 4
0
 def testini(cls, ini_name):
     print '\nCurrent directory: %s' % cwd
     ini_path = os.path.join(cwd, ini_name)
     config = client.get_config(path_to_config=ini_path)
     print 'INI file read - creating client'
     appenlight_client = client.Client(config)
     print 'Client created, sending test entry'
     logging.error('This is a test entry', extra={'sometag': 'appenlight.client.test',
                                                  'foo': 'bar'})
     records = appenlight_client.log_handlers_get_records()
     appenlight_client.py_log({}, records)
     result = appenlight_client.transport.send(appenlight_client.transport.log_queue[:], 'logs')
     if not result:
         print 'something went wrong, please check your API key'
         return False
     else:
         print 'Test entry transmitted correctly'
     return True
Exemplo n.º 5
0
    def testini(cls, ini_name):
        print '\nCurrent directory: %s' % cwd
        ini_path = os.path.join(cwd, ini_name)
        config = client.get_config(path_to_config=ini_path)
        print 'INI file read - creating client'
        appenlight_client = client.Client(config)
        print 'Client created, sending test entry'
        record = logging.makeLogRecord({'name': 'appenlight.client.test',
                                        'message': 'Test entry'})

        appenlight_client.py_log({}, [record])
        result = appenlight_client.submit_data()
        if not result['logs']:
            print 'something went wrong, please check your API key'
            return False
        else:
            print 'Test entry transmitted correctly'
        return True
Exemplo n.º 6
0
 def testini(cls, ini_name):
     print('\nCurrent directory: %s' % cwd)
     ini_path = os.path.join(cwd, ini_name)
     config = client.get_config(path_to_config=ini_path)
     print('INI file read - creating client')
     appenlight_client = client.Client(config)
     print('Client created, sending test entry')
     logging.error('This is a test entry', extra={'sometag': 'appenlight.client.test',
                                                  'foo': 'bar'})
     records = appenlight_client.log_handlers_get_records()
     appenlight_client.py_log({}, records)
     result = appenlight_client.transport.send(appenlight_client.transport.log_queue[:], 'logs')
     if not result:
         print('something went wrong, please check your API key')
         return False
     else:
         print('Test entry transmitted correctly')
     return True
Exemplo n.º 7
0
def on_preload_parsed(options, **kwargs):
    """
    This actually configures celery from pyramid config file
    """
    celery.conf['INI_PYRAMID'] = options['ini']
    import appenlight_client.client as e_client
    ini_location = options['ini']
    if not ini_location:
        raise Exception('You need to pass pyramid ini location using '
                        '--ini=filename.ini argument to the worker')
    env = bootstrap(ini_location)
    api_key = env['request'].registry.settings['appenlight.api_key']
    tr_config = env['request'].registry.settings.get(
        'appenlight.transport_config')
    CONFIG = e_client.get_config({'appenlight.api_key': api_key})
    if tr_config:
        CONFIG['appenlight.transport_config'] = tr_config
    APPENLIGHT_CLIENT = e_client.Client(CONFIG)
    # log.addHandler(APPENLIGHT_CLIENT.log_handler)
    register_signals(APPENLIGHT_CLIENT)
    celery.pyramid = env
Exemplo n.º 8
0
    def testini(cls, ini_name):
        print '\nCurrent directory: %s' % cwd
        ini_path = os.path.join(cwd, ini_name)
        config = client.get_config(path_to_config=ini_path)
        print 'INI file read - creating client'
        appenlight_client = client.Client(config)
        print 'Client created, sending test entry'
        record = logging.makeLogRecord({
            'name': 'appenlight.client.test',
            'message': 'Test entry'
        })

        appenlight_client.py_log({}, [record])
        result = appenlight_client.transport.send(
            appenlight_client.log_queue[:], 'logs')
        if not result:
            print 'something went wrong, please check your API key'
            return False
        else:
            print 'Test entry transmitted correctly'
        return True
Exemplo n.º 9
0
def on_preload_parsed(options, **kwargs):
    """
    This actually configures celery from pyramid config file
    """
    celery.conf["INI_PYRAMID"] = options["ini"]
    import appenlight_client.client as e_client

    ini_location = options["ini"]
    if not ini_location:
        raise Exception(
            "You need to pass pyramid ini location using "
            "--ini=filename.ini argument to the worker"
        )
    env = bootstrap(ini_location[0])
    api_key = env["request"].registry.settings["appenlight.api_key"]
    tr_config = env["request"].registry.settings.get("appenlight.transport_config")
    CONFIG = e_client.get_config({"appenlight.api_key": api_key})
    if tr_config:
        CONFIG["appenlight.transport_config"] = tr_config
    APPENLIGHT_CLIENT = e_client.Client(CONFIG)
    # log.addHandler(APPENLIGHT_CLIENT.log_handler)
    register_signals(APPENLIGHT_CLIENT)
    celery.pyramid = env
Exemplo n.º 10
0
import datetime
import logging
import socket
import pkg_resources
import time
from appenlight_client import client, make_appenlight_middleware
from appenlight_client.exceptions import get_current_traceback
from appenlight_client.logger import register_logging
from appenlight_client.wsgi import AppenlightWSGIWrapper

timing_conf = client.get_config({'appenlight.api_key': '1234'})
for k, v in timing_conf.iteritems():
    if 'appenlight.timing' in k:
        timing_conf[k] = 0.00000001

client.Client(config=timing_conf)
from appenlight_client.timing import local_timing, get_local_storage

import timeit
import jinja2

print 'traced', hasattr(jinja2.Template.render, '_e_attached_tracer')

s = """
template = jinja2.Template('''xxxxx {{1+2}} yyyyyy''')
template.render()
"""
print 'time', timeit.timeit(stmt=s, number=1500, setup="import jinja2")
stats, slow_calls = get_local_storage(local_timing).get_thread_stats()
print 'calls', len(slow_calls)
print 'stats', stats
Exemplo n.º 11
0
"""
Django settings for rocketu_blog_analytics project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import appenlight_client.client as e_client
APPENLIGHT = e_client.get_config({'appenlight.api_key':'9377163f23124aa890c5446150743780'})
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_($im*5#zz)lz!84cvt48#_+u!!4n4tjmyi=8c(c*)($v7u-lv'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

Exemplo n.º 12
0
# SOCIAL_AUTH_FACEBOOK_SCOPE = ['email', 'public_profile', 'user_photos']

# Related to users
LOGIN_REDIRECT_URL = 'search'
LOGIN_URL = 'login'
AUTH_USER_MODEL = 'date_app.Dater'

#
# EMAIL
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = ''



try:
    from local_settings import *
except ImportError:
    pass

# TEMPLATE_LOADERS = (
#     'django.template.loaders.filesystem.Loader',
#     'django.template.loaders.app_directories.Loader',
# )

import appenlight_client.client as e_client
APPENLIGHT = e_client.get_config({'appenlight.api_key':'8f6ea4ad96e4b558a82d2adabf60fc2'})
Exemplo n.º 13
0
Arquivo: base.py Projeto: Sveder/bdlr
Django settings for bdlr project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

from secret import *

import appenlight_client.client as e_client
APPENLIGHT = e_client.get_config({'appenlight.api_key': APPENLIGHT_PRIVATE_KEY})

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
ASSETS_DIR = os.path.join(BASE_DIR, "assets")
PAINTINGS_DIR = os.path.join(ASSETS_DIR, "paintings")

STATIC_DIR = os.path.join(BASE_DIR, "static")
SPRITE_SHEET_DIR = os.path.join(STATIC_DIR, "spritesheet")

SPRITE_SHEET_FILETYPE = "png"

MAIN_CACHE_LENGTH = 60 * 60 * 24

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Exemplo n.º 14
0
Arquivo: base.py Projeto: Sveder/bdlr
Django settings for bdlr project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

from secret import *

import appenlight_client.client as e_client
APPENLIGHT = e_client.get_config(
    {'appenlight.api_key': APPENLIGHT_PRIVATE_KEY})

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
ASSETS_DIR = os.path.join(BASE_DIR, "assets")
PAINTINGS_DIR = os.path.join(ASSETS_DIR, "paintings")

STATIC_DIR = os.path.join(BASE_DIR, "static")
SPRITE_SHEET_DIR = os.path.join(STATIC_DIR, "spritesheet")

SPRITE_SHEET_FILETYPE = "png"

MAIN_CACHE_LENGTH = 60 * 60 * 24

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Exemplo n.º 15
0
"""
Django settings for rocketu_blog_analytics project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

import appenlight_client.client as e_client
APPENLIGHT = e_client.get_config({'appenlight.api_key': 'cf0a8008b79e4b5a971aef5b49d3cb46'})

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_($im*5#zz)lz!84cvt48#_+u!!4n4tjmyi=8c(c*)($v7u-lv'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

Exemplo n.º 16
0
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'analytics.middleware.LocationMiddleware',
    'analytics.middleware.PageViewMiddleware',
)

ROOT_URLCONF = 'rocketu_blog_analytics.urls'

WSGI_APPLICATION = 'rocketu_blog_analytics.wsgi.application'

import appenlight_client.client as e_client
APPENLIGHT = e_client.get_config({'appenlight.api_key':'1b2f551c338a482fb1c8c4e79b8ff267'})

# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

LANGUAGE_CODE = 'en-us'
Exemplo n.º 17
0
"""
Django settings for rocketu_blog_analytics project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

import appenlight_client.client as e_client
APPENLIGHT = e_client.get_config({'appenlight.api_key':'59979eecd4bc4bbabf38b3101b2966a1'})

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_($im*5#zz)lz!84cvt48#_+u!!4n4tjmyi=8c(c*)($v7u-lv'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

Exemplo n.º 18
0
BASE_DIR = os.environ['OPENSHIFT_DATA_DIR']

STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = os.path.join(STATIC_URL, 'media/')

DATABASES = {
    'sqlite': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'site.db'),
    },
}
DATABASES['default'] = DATABASES['sqlite']

APPENLIGHT = e_client.get_config() if os.getenv('APPENLIGHT_KEY') else {}

MIDDLEWARE_CLASSES = ('appenlight_client.django_middleware.AppenlightMiddleware', ) + MIDDLEWARE_CLASSES


if os.getenv('OPENSHIFT_POSTGRESQL_DB_USERNAME'):
    DATABASES['postgres'] = {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ['OPENSHIFT_APP_NAME'],
        'USER': os.environ['OPENSHIFT_POSTGRESQL_DB_USERNAME'],
        'PASSWORD': os.environ['OPENSHIFT_POSTGRESQL_DB_PASSWORD'],
        'HOST': os.environ['OPENSHIFT_POSTGRESQL_DB_HOST'],
        'PORT': os.environ['OPENSHIFT_POSTGRESQL_DB_PORT'],
    }
    DATABASES['default'] = DATABASES['postgres']
Exemplo n.º 19
0
# set this to 60 seconds and then to 518400 when you can prove it works
SECURE_HSTS_SECONDS = 60
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_FRAME_DENY = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SECURE_SSL_REDIRECT = True

########## end django-secure


########## templates
TEMPLATE_LOADERS = (
    (
        "django.template.loaders.cached.Loader",
        ("django.template.loaders.filesystem.Loader", "django.template.loaders.app_directories.Loader"),
    ),
)

########## end templates

########## appenlight-client
import appenlight_client.client as e_client

APPENLIGHT = e_client.get_config({"appenlight.api_key": environ.get("APPENLIGHT_KEY", "")})

MIDDLEWARE_CLASSES = ("appenlight_client.django_middleware.AppenlightMiddleware",) + MIDDLEWARE_CLASSES
########## end appenlight-client
Exemplo n.º 20
0
Django settings for comics project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

import appenlight_client.client as e_client

APPENLIGHT = e_client.get_config({'appenlight.api_key':'98554e0f5b384d0c8f523f4ee6eefd55'})


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'n@dt_6xd+w8tq0qb9+iwy!a5lc=5u4y^d!bqc+d4tk#$y)2wt^'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []
Exemplo n.º 21
0
SECRET_KEY = config('SECRET_KEY', default='')

# TODO - Set the allowed hosts

INSTALLED_APPS += ('opbeat.contrib.django',)
MIDDLEWARE_CLASSES += \
    ['opbeat.contrib.django.middleware.OpbeatAPMMiddleware'] + \
    MIDDLEWARE_CLASSES

OPBEAT = {
    'ORGANIZATION_ID': config('OPBEAT_ORGANIZATION_ID', default=''),
    'APP_ID': config('OPBEAT_APP_ID', default=''),
    'SECRET_TOKEN': config('OPBEAT_SECRET_TOKEN', default=''),
}

APPENLIGHT = e_client.get_config(
    {'appenlight.api_key': config('APPENLIGHT_PRIVATE_KEY', default='')})

MIDDLEWARE_CLASSES += \
    ['appenlight_client.django_middleware.AppenlightMiddleware'] + \
    MIDDLEWARE_CLASSES

# STORAGES
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
STATIC_ROOT = base_dir_join('staticfiles')
STATIC_URL = '/static/'

# CELERY
BROKER_URL = config('REDIS_URL', default='')
CELERY_RESULT_BACKEND = config('REDIS_URL', default='')
CELERY_SEND_TASK_ERROR_EMAILS = True
Exemplo n.º 22
0
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_FRAME_DENY = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SECURE_SSL_REDIRECT = True

########## end django-secure


########## templates
TEMPLATE_LOADERS = (
    ('django.template.loaders.cached.Loader', (
        'django.template.loaders.filesystem.Loader',
        'django.template.loaders.app_directories.Loader',
    )),
)

########## end templates

#-------------------
# appenlight-client
#------------------

import appenlight_client.client as e_client
APPENLIGHT = e_client.get_config({'appenlight.api_key': os.environ.get('APPENLIGHT_KEY', '')})

MIDDLEWARE_CLASSES += (
    'appenlight_client.django_middleware.AppenlightMiddleware',
)
Exemplo n.º 23
0
# set this to 60 seconds and then to 518400 when you can prove it works
SECURE_HSTS_SECONDS = 60
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_FRAME_DENY = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SECURE_SSL_REDIRECT = True

########## end django-secure


########## templates
TEMPLATE_LOADERS = (
    ('django.template.loaders.cached.Loader', (
        'django.template.loaders.filesystem.Loader',
        'django.template.loaders.app_directories.Loader',
    )),
)

########## end templates

########## appenlight-client
import appenlight_client.client as e_client
APPENLIGHT = e_client.get_config({'appenlight.api_key': environ.get('APPENLIGHT_KEY', '')})

MIDDLEWARE_CLASSES = (
    'appenlight_client.django_middleware.AppenlightMiddleware',
) + MIDDLEWARE_CLASSES
########## end appenlight-client
Exemplo n.º 24
0
    @time_trace(name='Foo.test', min_duration=0.1)
    def test(self):
        time.sleep(0.1)
        return 1

    @time_trace(name='Foo.__call__', min_duration=0.2)
    def __call__(self):
        time.sleep(0.5)
        return 2


inst = Foo()
print inst.test()
print inst()


timing_conf = client.get_config({'appenlight.api_key':'1234'})
for k, v in timing_conf.iteritems():
    if 'appenlight.timing' in k:
        timing_conf[k] = 0.00000001

client.Client(config=timing_conf)
from appenlight_client.timing import local_timing, get_local_storage



stats, slow_calls = get_local_storage(local_timing).get_thread_stats()
print 'calls', len(slow_calls), slow_calls
print 'stats', stats
Exemplo n.º 25
0
import logging
import pkg_resources
import socket
import time
import unittest
import pprint
from appenlight_client import client, make_appenlight_middleware
from appenlight_client.exceptions import get_current_traceback
from appenlight_client.logger import register_logging
from appenlight_client.wsgi import AppenlightWSGIWrapper
from appenlight_client.utils import fullyQualifiedName
from webob import Request

fname = pkg_resources.resource_filename('appenlight_client',
                                        'templates/default_template.ini')
timing_conf = client.get_config(path_to_config=fname)
# set api key

for k, v in timing_conf.iteritems():
    if 'appenlight.timing' in k:
        timing_conf[k] = 0.0000001

#this sets up timing decoration for us
client.Client(config=timing_conf)
from appenlight_client.timing import local_timing, get_local_storage, time_trace


def example_filter_callable(structure, section=None):
    return 'filtered-data'