示例#1
0
def test_stacktrace_filtered_for_opbeat():
    client = TestClient()
    opbeat = get_client()
    instrumentation.control.instrument(opbeat)

    # Clear the LRU frame cache
    Transaction._lrucache = LRUCache(maxsize=5000)

    with mock.patch(
            "opbeat.traces.RequestsStore.should_collect") as should_collect:
        should_collect.return_value = False
        with override_settings(MIDDLEWARE_CLASSES=[
            'opbeat.contrib.django.middleware.OpbeatAPMMiddleware']):
            resp = client.get(reverse("render-heavy-template"))
    assert resp.status_code == 200

    transactions, traces = opbeat.instrumentation_store.get_all()

    expected_signatures = ['transaction', 'list_users.html',
                           'something_expensive']

    # Reorder according to the kinds list so we can just test them
    sig_dict = dict([(t['signature'], t) for t in traces])
    traces = [sig_dict[k] for k in expected_signatures]

    assert traces[1]['signature'] == 'list_users.html'
    frames = traces[1]['extra']['_frames']

    # Top frame should be inside django rendering
    assert frames[0]['module'].startswith('django.template')
示例#2
0
def test_stacktraces_have_templates():
    client = TestClient()
    opbeat = get_client()
    instrumentation.control.instrument()

    # Clear the LRU frame cache
    Transaction._lrucache = LRUCache(maxsize=5000)

    # only Django 1.9+ have the necessary information stored on Node/Template
    # instances when TEMPLATE_DEBUG = False

    TEMPLATE_DEBUG = django.VERSION < (1, 9)

    with mock.patch(
            "opbeat.traces.RequestsStore.should_collect") as should_collect:
        should_collect.return_value = False
        TEMPLATES_copy = deepcopy(settings.TEMPLATES)
        TEMPLATES_copy[0]['OPTIONS']['debug'] = TEMPLATE_DEBUG
        with override_settings(MIDDLEWARE_CLASSES=[
                'opbeat.contrib.django.middleware.OpbeatAPMMiddleware'
        ],
                               TEMPLATE_DEBUG=TEMPLATE_DEBUG,
                               TEMPLATES=TEMPLATES_copy):
            resp = client.get(reverse("render-heavy-template"))
    assert resp.status_code == 200

    transactions, traces = opbeat.instrumentation_store.get_all()
    assert len(transactions) == 1
    assert len(traces) == 3, [t["signature"] for t in traces]

    expected_signatures = [
        'transaction', 'list_users.html', 'something_expensive'
    ]

    assert set([t['signature'] for t in traces]) == set(expected_signatures)

    # Reorder according to the kinds list so we can just test them
    sig_dict = dict([(t['signature'], t) for t in traces])
    traces = [sig_dict[k] for k in expected_signatures]

    assert traces[2]['signature'] == 'something_expensive'

    # Find the template
    for frame in traces[2]['extra']['_frames']:
        if frame['lineno'] == 4 and frame['filename'].endswith(
                'django/testapp/templates/list_users.html'):
            break
    else:
        assert False is True, "Template was not found"
def test_stacktraces_have_templates():
    client = TestClient()
    opbeat = get_client()
    instrumentation.control.instrument()

    # Clear the LRU frame cache
    Transaction._lrucache = LRUCache(maxsize=5000)

    # only Django 1.9+ have the necessary information stored on Node/Template
    # instances when TEMPLATE_DEBUG = False

    TEMPLATE_DEBUG = django.VERSION < (1, 9)

    with mock.patch("opbeat.traces.RequestsStore.should_collect") as should_collect:
        should_collect.return_value = False
        TEMPLATES_copy = deepcopy(settings.TEMPLATES)
        TEMPLATES_copy[0]['OPTIONS']['debug'] = TEMPLATE_DEBUG
        with override_settings(
            MIDDLEWARE_CLASSES=[
                'opbeat.contrib.django.middleware.OpbeatAPMMiddleware'
            ],
            TEMPLATE_DEBUG=TEMPLATE_DEBUG,
            TEMPLATES=TEMPLATES_copy
        ):
            resp = client.get(reverse("render-heavy-template"))
    assert resp.status_code == 200

    transactions, traces = opbeat.instrumentation_store.get_all()
    assert len(transactions) == 1
    assert len(traces) == 3, [t["signature"] for t in traces]

    expected_signatures = ['transaction', 'list_users.html',
                           'something_expensive']

    assert set([t['signature'] for t in traces]) == set(expected_signatures)

    # Reorder according to the kinds list so we can just test them
    sig_dict = dict([(t['signature'], t) for t in traces])
    traces = [sig_dict[k] for k in expected_signatures]

    assert traces[2]['signature'] == 'something_expensive'

    # Find the template
    for frame in traces[2]['extra']['_frames']:
        if frame['lineno'] == 4 and frame['filename'].endswith('django/testapp/templates/list_users.html'):
            break
    else:
        assert False is True, "Template was not found"
示例#4
0
def client_get(client, url):
    return client.get(url)