def html_insertion_manual():
    header = get_browser_timing_header()
    footer = get_browser_timing_footer()

    header = get_browser_timing_header()
    footer = get_browser_timing_footer()

    assert header == ''
    assert footer == ''

    return ('<!DOCTYPE html><html><head>Some header</head>'
            '<body><h1>My First Heading</h1><p>My first paragraph.</p>'
            '</body></html>')
Exemple #2
0
def target_wsgi_application_manual_rum_insertion(environ, start_response):
    status = '200 OK'

    output = b'<html><body><p>RESPONSE</p></body></html>'

    header = get_browser_timing_header()
    footer = get_browser_timing_footer()

    header = get_browser_timing_header()
    footer = get_browser_timing_footer()

    assert header == ''
    assert footer == ''

    response_headers = [('Content-Type', 'text/html; charset=utf-8'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    yield output
Exemple #3
0
def target_wsgi_application(environ, start_response):
    status = '200 OK'

    txn_name = environ.get('txn')
    if six.PY2:
        txn_name = txn_name.decode('UTF-8')
    txn_name = txn_name.split('/', 3)

    guid = environ.get('guid')
    old_cat = environ.get('old_cat') == 'True'
    txn = current_transaction()

    txn.guid = guid
    for req in OUTBOUD_REQUESTS:
        # Change the transaction name before making an outbound call.
        outgoing_name = req['outboundTxnName'].split('/', 3)
        if outgoing_name[0] != 'WebTransaction':
            set_background_task(True)

        set_transaction_name(outgoing_name[2], group=outgoing_name[1])

        expected_outbound_header = obfuscate(
            json_encode(req['expectedOutboundPayload']), ENCODING_KEY)
        generated_outbound_header = dict(
            ExternalTrace.generate_request_headers(txn))

        # A 500 error is returned because 'assert' statements in the wsgi app
        # are ignored.

        if old_cat:
            if (expected_outbound_header !=
                    generated_outbound_header['X-NewRelic-Transaction']):
                status = '500 Outbound Headers Check Failed.'
        else:
            if 'X-NewRelic-Transaction' in generated_outbound_header:
                status = '500 Outbound Headers Check Failed.'
        r = urlopen(environ['server_url'])
        r.read(10)

    # Set the final transaction name.

    if txn_name[0] != 'WebTransaction':
        set_background_task(True)
    set_transaction_name(txn_name[2], group=txn_name[1])

    text = '<html><head>%s</head><body><p>RESPONSE</p>%s</body></html>'

    output = (text % (get_browser_timing_header(),
                      get_browser_timing_footer())).encode('UTF-8')

    response_headers = [('Content-type', 'text/html; charset=utf-8'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]
Exemple #4
0
async def target_asgi_application_manual_rum_insertion(scope, receive, send):
    output = b'<html><body><p>RESPONSE</p></body></html>'

    header = get_browser_timing_header()
    footer = get_browser_timing_footer()

    header = get_browser_timing_header()
    footer = get_browser_timing_footer()

    assert header == ''
    assert footer == ''

    response_headers = [(b'content-type', b'text/html; charset=utf-8'),
                        (b'content-length', str(len(output)).encode("utf-8"))]

    await send({
        "type": "http.response.start",
        "status": 200,
        "headers": response_headers
    })
    await send({"type": "http.response.body", "body": output})
Exemple #5
0
def fully_featured_app(environ, start_response):
    status = '200 OK'

    path = environ.get('PATH_INFO')
    use_user_attrs = environ.get('record_attributes', 'TRUE') == 'TRUE'

    environ['wsgi.input'].read()
    environ['wsgi.input'].readline()
    environ['wsgi.input'].readlines()

    if use_user_attrs:

        for attr, val in _custom_parameters.items():
            add_custom_parameter(attr, val)

    if 'db' in environ and int(environ['db']) > 0:
        connection = db.connect(":memory:")
        for i in range(int(environ['db']) - 1):
            connection.execute("create table test_db%d (a, b, c)" % i)

    if 'external' in environ:
        for i in range(int(environ['external'])):
            r = urlopen('http://www.python.org')
            r.read(10)

    if 'err_message' in environ:
        n_errors = int(environ.get('n_errors', 1))
        for i in range(n_errors):
            try:

                # append number to stats engine to get unique errors, so they
                # don't immediately get filtered out.

                raise ValueError(environ['err_message'] + str(i))
            except ValueError:
                if use_user_attrs:
                    record_exception(params=_err_param)
                else:
                    record_exception()

    text = '<html><head>%s</head><body><p>RESPONSE</p>%s</body></html>'

    output = (text % (get_browser_timing_header(),
                      get_browser_timing_footer())).encode('UTF-8')

    response_headers = [('Content-type', 'text/html; charset=utf-8'),
                        ('Content-Length', str(len(output)))]
    write = start_response(status, response_headers)

    write(b'')

    return [output]
Exemple #6
0
def target_wsgi_application_manual_rum(environ, start_response):
    status = '200 OK'

    text = '<html><head>%s</head><body><p>RESPONSE</p>%s</body></html>'

    output = (text % (get_browser_timing_header(),
                      get_browser_timing_footer())).encode('UTF-8')

    response_headers = [('Content-Type', 'text/html; charset=utf-8'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]
Exemple #7
0
async def target_asgi_application_manual_rum(scope, receive, send):
    text = '<html><head>%s</head><body><p>RESPONSE</p>%s</body></html>'

    output = (text % (get_browser_timing_header(),
                      get_browser_timing_footer())).encode('UTF-8')

    response_headers = [(b'content-type', b'text/html; charset=utf-8'),
                        (b'content-length', str(len(output)).encode('utf-8'))]

    await send({
        "type": "http.response.start",
        "status": 200,
        "headers": response_headers
    })
    await send({"type": "http.response.body", "body": output})
def target_wsgi_application(environ, start_response):
    status = '200 OK'

    txn_name = environ.get('txn_name')
    set_transaction_name(txn_name, group='')

    user_attrs = json.loads(environ.get('user_attrs'))
    for key, value in user_attrs.items():
        add_custom_parameter(key, value)

    text = '<html><head>%s</head><body><p>RESPONSE</p></body></html>'

    output = (text % get_browser_timing_footer()).encode('UTF-8')

    response_headers = [('Content-Type', 'text/html; charset=utf-8'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]