当前位置: 首页>>代码示例>>Python>>正文


Python flask.FlaskIntegration方法代码示例

本文整理汇总了Python中sentry_sdk.integrations.flask.FlaskIntegration方法的典型用法代码示例。如果您正苦于以下问题:Python flask.FlaskIntegration方法的具体用法?Python flask.FlaskIntegration怎么用?Python flask.FlaskIntegration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sentry_sdk.integrations.flask的用法示例。


在下文中一共展示了flask.FlaskIntegration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_transaction_style

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_transaction_style(
    sentry_init, app, capture_events, transaction_style, expected_transaction
):
    sentry_init(
        integrations=[
            flask_sentry.FlaskIntegration(transaction_style=transaction_style)
        ]
    )
    events = capture_events()

    client = app.test_client()
    response = client.get("/message")
    assert response.status_code == 200

    (event,) = events
    assert event["transaction"] == expected_transaction 
开发者ID:getsentry,项目名称:sentry-python,代码行数:18,代码来源:test_flask.py

示例2: test_flask_large_json_request

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_flask_large_json_request(sentry_init, capture_events, app):
    sentry_init(integrations=[flask_sentry.FlaskIntegration()])

    data = {"foo": {"bar": "a" * 2000}}

    @app.route("/", methods=["POST"])
    def index():
        assert request.get_json() == data
        assert request.get_data() == json.dumps(data).encode("ascii")
        assert not request.form
        capture_message("hi")
        return "ok"

    events = capture_events()

    client = app.test_client()
    response = client.post("/", content_type="application/json", data=json.dumps(data))
    assert response.status_code == 200

    (event,) = events
    assert event["_meta"]["request"]["data"]["foo"]["bar"] == {
        "": {"len": 2000, "rem": [["!limit", "x", 509, 512]]}
    }
    assert len(event["request"]["data"]["foo"]["bar"]) == 512 
开发者ID:getsentry,项目名称:sentry-python,代码行数:26,代码来源:test_flask.py

示例3: test_flask_medium_formdata_request

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_flask_medium_formdata_request(sentry_init, capture_events, app):
    sentry_init(integrations=[flask_sentry.FlaskIntegration()])

    data = {"foo": "a" * 2000}

    @app.route("/", methods=["POST"])
    def index():
        assert request.form["foo"] == data["foo"]
        assert not request.get_data()
        assert not request.get_json()
        capture_message("hi")
        return "ok"

    events = capture_events()

    client = app.test_client()
    response = client.post("/", data=data)
    assert response.status_code == 200

    (event,) = events
    assert event["_meta"]["request"]["data"]["foo"] == {
        "": {"len": 2000, "rem": [["!limit", "x", 509, 512]]}
    }
    assert len(event["request"]["data"]["foo"]) == 512 
开发者ID:getsentry,项目名称:sentry-python,代码行数:26,代码来源:test_flask.py

示例4: test_logging

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_logging(sentry_init, capture_events, app):
    # ensure that Flask's logger magic doesn't break ours
    sentry_init(
        integrations=[
            flask_sentry.FlaskIntegration(),
            LoggingIntegration(event_level="ERROR"),
        ]
    )

    @app.route("/")
    def index():
        app.logger.error("hi")
        return "ok"

    events = capture_events()

    client = app.test_client()
    client.get("/")

    (event,) = events
    assert event["level"] == "error" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:23,代码来源:test_flask.py

示例5: test_500

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_500(sentry_init, capture_events, app):
    sentry_init(integrations=[flask_sentry.FlaskIntegration()])

    app.debug = False
    app.testing = False

    @app.route("/")
    def index():
        1 / 0

    @app.errorhandler(500)
    def error_handler(err):
        return "Sentry error: %s" % last_event_id()

    events = capture_events()

    client = app.test_client()
    response = client.get("/")

    (event,) = events
    assert response.data.decode("utf-8") == "Sentry error: %s" % event["event_id"] 
开发者ID:getsentry,项目名称:sentry-python,代码行数:23,代码来源:test_flask.py

示例6: test_tracing_success

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_tracing_success(sentry_init, capture_events, app):
    sentry_init(traces_sample_rate=1.0, integrations=[flask_sentry.FlaskIntegration()])

    events = capture_events()

    with app.test_client() as client:
        response = client.get("/message")
        assert response.status_code == 200

    message_event, transaction_event = events

    assert transaction_event["type"] == "transaction"
    assert transaction_event["transaction"] == "hi"
    assert transaction_event["contexts"]["trace"]["status"] == "ok"

    assert message_event["message"] == "hi"
    assert message_event["transaction"] == "hi" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:19,代码来源:test_flask.py

示例7: test_tracing_error

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_tracing_error(sentry_init, capture_events, app):
    sentry_init(traces_sample_rate=1.0, integrations=[flask_sentry.FlaskIntegration()])

    events = capture_events()

    @app.route("/error")
    def error():
        1 / 0

    with pytest.raises(ZeroDivisionError):
        with app.test_client() as client:
            response = client.get("/error")
            assert response.status_code == 500

    error_event, transaction_event = events

    assert transaction_event["type"] == "transaction"
    assert transaction_event["transaction"] == "error"
    assert transaction_event["contexts"]["trace"]["status"] == "internal_error"

    assert error_event["transaction"] == "error"
    (exception,) = error_event["exception"]["values"]
    assert exception["type"] == "ZeroDivisionError" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:25,代码来源:test_flask.py

示例8: test_class_based_views

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_class_based_views(sentry_init, app, capture_events):
    sentry_init(integrations=[flask_sentry.FlaskIntegration()])
    events = capture_events()

    @app.route("/")
    class HelloClass(View):
        def dispatch_request(self):
            capture_message("hi")
            return "ok"

    app.add_url_rule("/hello-class/", view_func=HelloClass.as_view("hello_class"))

    with app.test_client() as client:
        response = client.get("/hello-class/")
        assert response.status_code == 200

    (event,) = events

    assert event["message"] == "hi"
    assert event["transaction"] == "hello_class" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:22,代码来源:test_flask.py

示例9: init_sentry

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def init_sentry(app):
    """Init sentry if DSN *and* environment are provided."""
    dsn = app.config['SENTRY_DSN']
    env = app.config['SENTRY_ENVIRONMENT']

    if dsn is None and env is None:
        return

    if None in (dsn, env):
        raise ValueError("You need to specify both DSN and environment "
                         "to use Sentry.")

    sentry_sdk.init(
        dsn=dsn,
        integrations=[FlaskIntegration()],
        environment=env,
    ) 
开发者ID:amiv-eth,项目名称:amivapi,代码行数:19,代码来源:bootstrap.py

示例10: create_app

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def create_app(config_name):
    """Factory of Creating app
    @param:
        config_name - all configurations of app
    """
    sentry_sdk.init(
        dsn="",
        integrations=[FlaskIntegration()])
    application = Flask(__name__)
    application.config.from_object(config[config_name])
    config[config_name].init_app(application)

    csrf = CSRFProtect()

    from .image.model import image_db
    from .image.views import image as image_blueprint
    from .image.apis import blueprint as image_api_blueprint

    csrf.init_app(application)
    image_db.init_app(application)
    application.register_blueprint(image_blueprint)
    application.register_blueprint(image_api_blueprint, url_prefix='/api/v1')

    return application 
开发者ID:leollon,项目名称:yet-another-image-bed,代码行数:26,代码来源:__init__.py

示例11: register_extensions

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def register_extensions(app):
    db.init_app(app)
    executor.init_app(app)
    basic_auth.init_app(app)

    @app.before_request
    def enable_form_raw_cache():
        # Workaround to allow unparsed request body to be be read from cache
        # This is required to validate a signature on webhooks
        # This MUST go before Sentry integration as sentry triggers form parsing
        if not config.IS_TEST and (
                request.path.startswith('/api/v1/slack/') or request.path.startswith('/api/v1/poli_payments_webhook/')):
            if request.content_length > 1024 * 1024:  # 1mb
                # Payload too large
                return make_response(jsonify({'message': 'Payload too large'})), 413
            request.get_data(parse_form_data=False, cache=True)

    # limiter.init_app(app)

    CORS(app, resources={r"/api/*": {"origins": "*"}})

    celery_app.conf.update(app.config)
    if not config.IS_TEST:
        sentry_sdk.init(app.config['SENTRY_SERVER_DSN'], integrations=[FlaskIntegration()], release=config.VERSION)

    print('celery joined on {} at {}'.format(
        app.config['REDIS_URL'], datetime.utcnow())) 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:29,代码来源:__init__.py

示例12: integration_enabled_params

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def integration_enabled_params(request):
    if request.param == "auto":
        return {"_experiments": {"auto_enabling_integrations": True}}
    elif request.param == "manual":
        return {"integrations": [flask_sentry.FlaskIntegration()]}
    else:
        raise ValueError(request.param) 
开发者ID:getsentry,项目名称:sentry-python,代码行数:9,代码来源:test_flask.py

示例13: test_has_context

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_has_context(sentry_init, app, capture_events):
    sentry_init(integrations=[flask_sentry.FlaskIntegration()])
    events = capture_events()

    client = app.test_client()
    response = client.get("/message")
    assert response.status_code == 200

    (event,) = events
    assert event["transaction"] == "hi"
    assert "data" not in event["request"]
    assert event["request"]["url"] == "http://localhost/message" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:14,代码来源:test_flask.py

示例14: test_flask_session_tracking

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_flask_session_tracking(sentry_init, capture_envelopes, app):
    sentry_init(
        integrations=[flask_sentry.FlaskIntegration()],
        release="demo-release",
        _experiments=dict(auto_session_tracking=True,),
    )

    @app.route("/")
    def index():
        with configure_scope() as scope:
            scope.set_user({"ip_address": "1.2.3.4", "id": 42})
        try:
            raise ValueError("stuff")
        except Exception:
            logging.exception("stuff happened")
        1 / 0

    envelopes = capture_envelopes()

    with app.test_client() as client:
        try:
            client.get("/", headers={"User-Agent": "blafasel/1.0"})
        except ZeroDivisionError:
            pass

    Hub.current.client.flush()

    (first_event, error_event, session) = envelopes
    first_event = first_event.get_event()
    error_event = error_event.get_event()
    session = session.items[0].payload.json

    assert first_event["exception"]["values"][0]["type"] == "ValueError"
    assert error_event["exception"]["values"][0]["type"] == "ZeroDivisionError"
    assert session["status"] == "crashed"
    assert session["did"] == "42"
    assert session["errors"] == 2
    assert session["init"]
    assert session["attrs"]["release"] == "demo-release"
    assert session["attrs"]["ip_address"] == "1.2.3.4"
    assert session["attrs"]["user_agent"] == "blafasel/1.0" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:43,代码来源:test_flask.py

示例15: test_flask_too_large_raw_request

# 需要导入模块: from sentry_sdk.integrations import flask [as 别名]
# 或者: from sentry_sdk.integrations.flask import FlaskIntegration [as 别名]
def test_flask_too_large_raw_request(sentry_init, input_char, capture_events, app):
    sentry_init(integrations=[flask_sentry.FlaskIntegration()], request_bodies="small")

    data = input_char * 2000

    @app.route("/", methods=["POST"])
    def index():
        assert not request.form
        if isinstance(data, bytes):
            assert request.get_data() == data
        else:
            assert request.get_data() == data.encode("ascii")
        assert not request.get_json()
        capture_message("hi")
        return "ok"

    events = capture_events()

    client = app.test_client()
    response = client.post("/", data=data)
    assert response.status_code == 200

    (event,) = events
    assert event["_meta"]["request"]["data"] == {
        "": {"len": 2000, "rem": [["!config", "x", 0, 2000]]}
    }
    assert not event["request"]["data"] 
开发者ID:getsentry,项目名称:sentry-python,代码行数:29,代码来源:test_flask.py


注:本文中的sentry_sdk.integrations.flask.FlaskIntegration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。