Esempio n. 1
0
def test_collect_span_events_override(collect_span_events,
                                      span_events_enabled):

    if collect_span_events and span_events_enabled:
        spans_expected = True
    else:
        spans_expected = False

    span_count = 2 if spans_expected else 0

    @validate_span_events(count=span_count)
    @override_application_settings({
        'transaction_tracer.enabled': False,
        'distributed_tracing.enabled': True,
        'span_events.enabled': span_events_enabled,
        'collect_span_events': collect_span_events
    })
    @background_task(name='test_collect_span_events_override')
    def _test():
        transaction = current_transaction()
        transaction._sampled = True

        with FunctionTrace('span_generator'):
            pass

    if not spans_expected:
        _test = function_not_called('newrelic.core.attribute',
                                    'resolve_agent_attributes')(_test)

    _test()
def test_errors_in_error_handlers(
        nr_enabled, app, url, metric_name, metrics, errors):
    settings = global_settings()

    @override_generic_settings(settings, {'enabled': nr_enabled})
    def _test():
        # Because of a bug in Sanic versions <0.8.0, the response.status value
        # is inconsistent. Rather than assert the status value, we rely on the
        # transaction errors validator to confirm the application acted as we'd
        # expect it to.
        app.fetch('get', url)

    if nr_enabled:
        _test = validate_transaction_errors(errors=errors)(_test)
        _test = validate_transaction_metrics(metric_name,
                scoped_metrics=metrics,
                rollup_metrics=metrics)(_test)
    else:
        _test = function_not_called('newrelic.core.stats_engine',
            'StatsEngine.record_transaction')(_test)

    _test()