예제 #1
0
def test__trace_plugin__auto_db__env_var(monkeypatch):
    monkeypatch.setenv("IOPIPE_TRACE_AUTO_DB_ENABLED", "false")
    iopipe = IOpipeCore(plugins=[TracePlugin()])
    assert iopipe.plugins[0].auto_db is False

    monkeypatch.setenv("IOPIPE_TRACE_AUTO_DB_ENABLED", "true")
    iopipe = IOpipeCore(plugins=[TracePlugin()])
    assert iopipe.plugins[0].auto_db is True
예제 #2
0
def default_iopipe_override():
    return IOpipe(
        "test-suite",
        "https://metrics-api.iopipe.com",
        True,
        plugins=[TracePlugin(auto_measure=False)],
    )
예제 #3
0
def test_get_plugin_meta():
    assert get_plugin_meta([TracePlugin()]) == [{
        'name': 'trace',
        'version': '1.1.0',
        'homepage': 'https://github.com/iopipe/iopipe-python#trace-plugin',
        'enabled': True,
    }]
예제 #4
0
def test_get_plugin_meta():
    assert get_plugin_meta([TracePlugin()]) == [{
        "name": "trace",
        "version": "1.1.0",
        "homepage": "https://github.com/iopipe/iopipe-python#trace-plugin",
        "enabled": True,
    }]
예제 #5
0
def iopipe_with_trace_auto_http():
    plugin = TracePlugin(auto_http=True)
    return IOpipeCore(
        token="test-suite",
        url="https://metrics-api.iopipe.com",
        debug=True,
        plugins=[plugin],
    )
예제 #6
0
def test_is_plugin():
    class NotAPlugin(object):
        def do_nothing(self):
            pass

    assert not is_plugin(NotAPlugin)
    assert not is_plugin(NotAPlugin())
    assert is_plugin(TracePlugin)
    assert is_plugin(TracePlugin())
예제 #7
0
def iopipe_with_trace_auto_http_filter_request():
    def http_filter(request, response):
        return None, response

    plugin = TracePlugin(auto_http=True, http_filter=http_filter)
    return IOpipeCore(
        token="test-suite",
        url="https://metrics-api.iopipe.com",
        debug=True,
        plugins=[plugin],
    )
예제 #8
0
def iopipe_with_trace_auto_http_filter():
    def http_filter(request, response):
        if request["url"].startswith("https://www.iopipe.com"):
            raise Exception("Do not trace this URL")

    plugin = TracePlugin(auto_http=True, http_filter=http_filter)
    return IOpipeCore(
        token="test-suite",
        url="https://metrics-api.iopipe.com",
        debug=True,
        plugins=[plugin],
    )
예제 #9
0
import os
import sys
import time

from iopipe import IOpipe
from iopipe.contrib.trace import TracePlugin

iopipe = IOpipe(os.getenv('IOPIPE_TOKEN'))

trace_plugin = TracePlugin()
iopipe_with_tracing = IOpipe(os.getenv('IOPIPE_TOKEN'), plugins=[trace_plugin])


@iopipe
def caught_error(event, context):
    try:
        raise Exception('Caught exception')
    except Exception as e:
        context.iopipe.error(e)


@iopipe
def coldstart(event, context):
    sys.exit(1)


@iopipe
def custom_metrics(event, context):
    context.iopipe.log('time', time.time())

예제 #10
0
eventinfo_plugin = EventInfoPlugin()
iopipe_with_eventinfo = IOpipeCore(debug=True, plugins=[eventinfo_plugin])

logger_plugin = LoggerPlugin(enabled=True)
iopipe_with_logging = IOpipeCore(debug=True, plugins=[logger_plugin])

logger_plugin_tmp = LoggerPlugin(enabled=True, use_tmp=True)
iopipe_with_logging_tmp = IOpipeCore(debug=True, plugins=[logger_plugin_tmp])

profiler_plugin = ProfilerPlugin(enabled=True)
iopipe_with_profiling = IOpipeCore(debug=True, plugins=[profiler_plugin])

iopipe_with_sync_http = IOpipe(debug=True, sync_http=True)

trace_plugin = TracePlugin()
iopipe_with_tracing = IOpipeCore(debug=True, plugins=[trace_plugin])

trace_plugin_auto_http = TracePlugin(auto_http=True)
iopipe_with_auto_http = IOpipeCore(debug=True,
                                   plugins=[trace_plugin_auto_http])


@iopipe_with_eventinfo
def api_gateway(event, context):
    return {"statusCode": 200, "body": json.dumps({"success": True})}


@iopipe_with_auto_http
def api_trigger(event, context):
    gateway_url = os.getenv("PY_API_GATEWAY_URL")
예제 #11
0
def iopipe_with_plugin():
    plugin = TracePlugin()
    return IOpipe(token='test-suite',
                  url='https://metrics-api.iopipe.com',
                  debug=True,
                  plugins=[plugin])
예제 #12
0
def iopipe_with_trace_no_auto_measure():
    plugin = TracePlugin(auto_measure=False)
    return IOpipeCore(token='test-suite',
                      url='https://metrics-api.iopipe.com',
                      debug=True,
                      plugins=[plugin])
예제 #13
0
import os

import psycopg2
import pymysql

from iopipe import IOpipeCore
from iopipe.contrib.trace import TracePlugin

trace_plugin = TracePlugin(auto_db=True)
iopipe = IOpipeCore(debug=True, plugins=[trace_plugin])


@iopipe
def _pymysql(event, context):
    conn = pymysql.connect(
        db=os.environ["DB_NAME"],
        host=os.environ["MYSQL_HOST"],
        password=os.environ["DB_PASSWORD"],
        port=int(os.environ["MYSQL_PORT"]),
        user=os.environ["DB_USERNAME"],
    )
    cur = conn.cursor()

    cur.execute("""
        CREATE TABLE IF NOT EXISTS test (
            id int(11) NOT NULL AUTO_INCREMENT,
            num int(11),
            data varchar(255),
            PRIMARY KEY (id)
        );
    """)