Beispiel #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
Beispiel #2
0
def iopipe_with_eventinfo():
    plugin = EventInfoPlugin()
    return IOpipeCore(
        token="test-suite",
        url="https://metrics-api.iopipe.com",
        debug=True,
        plugins=[plugin],
    )
Beispiel #3
0
def iopipe_with_profiler():
    plugin = ProfilerPlugin(enabled=True)
    return IOpipeCore(
        token="test-suite",
        url="https://metrics-api.iopipe.com",
        debug=True,
        plugins=[plugin],
    )
Beispiel #4
0
def iopipe_with_logger_debug():
    plugin = LoggerPlugin(name="testlog", enabled=True)
    return IOpipeCore(
        token="test-suite",
        url="https://metrics-api.iopipe.com",
        debug=True,
        plugins=[plugin],
    )
Beispiel #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],
    )
Beispiel #6
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],
    )
Beispiel #7
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],
    )
Beispiel #8
0
def test_custom_metrics(mock_send_report, handler_with_events, mock_context):
    """Assert that the agent collects custom metrics"""
    iopipe = IOpipeCore()
    assert iopipe.report is None
    iopipe.log("foo", "bar")
    assert iopipe.report is None

    iopipe, handler = handler_with_events
    handler(None, mock_context)

    assert len(iopipe.report.custom_metrics) == 7
    # Decimals are converted to strings
    assert (
        iopipe.report.custom_metrics[6]["s"]
        == "12.300000000000000710542735760100185871124267578125"
    )
    assert "@iopipe/metrics" in iopipe.report.labels
Beispiel #9
0
def test_erroring(mock_send_report, handler_that_errors, mock_context):
    """Assert that the agent catches and traces uncaught exceptions"""
    iopipe = IOpipeCore()
    assert iopipe.report is None
    try:
        iopipe.error(Exception("Before report is created"))
    except Exception:
        pass
    assert iopipe.report is None
    iopipe, handler = handler_that_errors

    with pytest.raises(ValueError):
        handler(None, mock_context)

    assert iopipe.report.report["errors"]["name"] == "ValueError"
    assert iopipe.report.report["errors"]["message"] == "Behold, a value error"
    assert isinstance(iopipe.report.report["errors"]["stack"], str)
    assert "@iopipe/error" in iopipe.report.labels
Beispiel #10
0
def iopipe_with_trace():
    plugin = TracePlugin()
    return IOpipeCore(token='test-suite',
                      url='https://metrics-api.iopipe.com',
                      debug=True,
                      plugins=[plugin])
Beispiel #11
0
def iopipe():
    return IOpipeCore("test-suite", "https://metrics-api.iopipe.com", True)
Beispiel #12
0
def iopipe_with_logger_disabled():
    plugin = LoggerPlugin(name="testlog", enabled=False)
    return IOpipeCore(token="test-suite",
                      url="https://metrics-api.iopipe.com",
                      plugins=[plugin])
Beispiel #13
0
try:
    from urllib.request import urlopen
except ImportError:
    from urllib2 import urlopen

from iopipe import IOpipe, IOpipeCore
from iopipe.contrib.eventinfo import EventInfoPlugin
from iopipe.contrib.logger import LoggerPlugin
from iopipe.contrib.profiler import ProfilerPlugin
from iopipe.contrib.trace import TracePlugin

iopipe = IOpipe(debug=True)

eventinfo_plugin = EventInfoPlugin()
iopipe_with_eventinfo = IOpipeCore(debug=True, plugins=[eventinfo_plugin])

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

logger_plugin_tmp = LoggerPlugin(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])
Beispiel #14
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)
        );
    """)
Beispiel #15
0
def iopipe_with_logger():
    plugin = LoggerPlugin('testlog')
    return IOpipeCore(token='test-suite',
                      url='https://metrics-api.iopipe.com',
                      plugins=[plugin])
Beispiel #16
0
def iopipe_with_logger_use_tmp():
    plugin = LoggerPlugin(name='testlog', use_tmp=True)
    return IOpipeCore(token='test-suite',
                      url='https://metrics-api.iopipe.com',
                      plugins=[plugin])
Beispiel #17
0
def iopipe():
    return IOpipeCore('test-suite', 'https://metrics-api.iopipe.com', True)