本文整理汇总了Python中sentry_sdk.configure_scope方法的典型用法代码示例。如果您正苦于以下问题:Python sentry_sdk.configure_scope方法的具体用法?Python sentry_sdk.configure_scope怎么用?Python sentry_sdk.configure_scope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sentry_sdk
的用法示例。
在下文中一共展示了sentry_sdk.configure_scope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sentry_init
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def sentry_init(obs_apiurl=None, tags=None):
try:
import sentry_sdk
except ImportError:
sentry_init.client = sentry_client_dummy()
return sentry_sdk_dummy()
sentry_init.client = sentry_sdk.init(
conf.config.get('sentry_sdk.dsn'),
environment=conf.config.get('sentry_sdk.environment'),
release=VERSION)
with sentry_sdk.configure_scope() as scope:
scope.set_tag('osc', core.__version__)
if obs_apiurl:
scope.set_tag('obs_apiurl', obs_apiurl)
scope.user = {'username': conf.get_apiurl_usr(obs_apiurl)}
if tags:
for key, value in tags.items():
scope.set_tag(key, value)
return sentry_sdk
示例2: post_setup
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def post_setup(cls):
"""Post setup configuration.
This is the place where you can configure settings that require other
settings to be loaded.
"""
super().post_setup()
# The DJANGO_SENTRY_DSN environment variable should be set to activate
# sentry for an environment
if cls.SENTRY_DSN is not None:
sentry_sdk.init(
dsn=cls.SENTRY_DSN,
environment=cls.ENVIRONMENT,
release=cls.RELEASE,
integrations=[DjangoIntegration()],
)
with sentry_sdk.configure_scope() as scope:
scope.set_extra("application", "backend")
示例3: test_no_stackoverflows
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def test_no_stackoverflows(celery):
"""We used to have a bug in the Celery integration where its monkeypatching
was repeated for every task invocation, leading to stackoverflows.
See https://github.com/getsentry/sentry-python/issues/265
"""
results = []
@celery.task(name="dummy_task")
def dummy_task():
with configure_scope() as scope:
scope.set_tag("foo", "bar")
results.append(42)
for _ in range(10000):
dummy_task.delay()
assert results == [42] * 10000
with configure_scope() as scope:
assert not scope._tags
示例4: test_scope_initialized_before_client
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def test_scope_initialized_before_client(sentry_init, capture_events):
"""
This is a consequence of how configure_scope() works. We must
make `configure_scope()` a noop if no client is configured. Even
if the user later configures a client: We don't know that.
"""
with configure_scope() as scope:
scope.set_tag("foo", 42)
sentry_init()
events = capture_events()
capture_message("hi")
(event,) = events
assert "tags" not in event
示例5: test_cyclic_data
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def test_cyclic_data(sentry_init, capture_events):
sentry_init()
events = capture_events()
with configure_scope() as scope:
data = {}
data["is_cyclic"] = data
other_data = ""
data["not_cyclic"] = other_data
data["not_cyclic2"] = other_data
scope.set_extra("foo", data)
capture_message("hi")
(event,) = events
data = event["extra"]["foo"]
assert data == {"not_cyclic2": "", "not_cyclic": "", "is_cyclic": "<cyclic>"}
示例6: _handle_sentry
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def _handle_sentry(self):
"""Handle exceptions using Sentry."""
from sentry_sdk import capture_exception, configure_scope
from sentry_sdk.utils import capture_internal_exceptions
with configure_scope() as scope:
with capture_internal_exceptions():
from git import Repo
from renku.core.commands import get_git_home
from renku.core.models.provenance.agents import Person
repo = Repo(get_git_home())
user = Person.from_git(repo)
scope.user = {'name': user.name, 'email': user.email}
event_id = capture_exception()
click.echo(
_BUG + 'Recorded in Sentry with ID: {0}\n'.format(event_id),
err=True,
)
raise
示例7: post_setup
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def post_setup(cls):
"""Post setup configuration.
This is the place where you can configure settings that require other
settings to be loaded.
"""
super().post_setup()
# The SENTRY_DSN setting should be available to activate sentry for an environment
if cls.SENTRY_DSN is not None:
sentry_sdk.init(
dsn=cls.SENTRY_DSN,
environment=cls.ENVIRONMENT,
release=cls.RELEASE,
integrations=[DjangoIntegration()],
)
with sentry_sdk.configure_scope() as scope:
scope.set_extra("application", "backend")
示例8: deactivate_repo
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def deactivate_repo(repository_id: UUID, reason: DeactivationReason):
with sentry_sdk.configure_scope() as scope:
scope.set_tag("repository_id", str(repository_id))
repository = Repository.query.unrestricted_unsafe().get(repository_id)
repository.status = RepositoryStatus.inactive
with db.session.begin_nested():
ItemOption.query.filter(
ItemOption.item_id == repository_id, ItemOption.name == "auth.private-key"
).delete()
db.session.add(repository)
current_app.logger.warn(
"repository.deactivated repository_id=%s reason=%s", repository_id, reason
)
db.session.commit()
msg = build_message(repository, reason)
if msg:
mail.send(msg)
示例9: handle_message
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def handle_message(self, message: Message) -> None:
with sentry_sdk.configure_scope() as scope:
scope.set_extra("message", message)
try:
if isinstance(message, PFSCapacityUpdate):
changed_channel: Optional[Channel] = self.on_capacity_update(message)
elif isinstance(message, PFSFeeUpdate):
changed_channel = self.on_fee_update(message)
else:
log.debug("Ignoring message", unknown_message=message)
return
if changed_channel:
self.database.upsert_channel(changed_channel)
except DeferMessage as ex:
self.defer_message_until_channel_is_open(ex.deferred_message)
except InvalidGlobalMessage as ex:
log.info(str(ex), **asdict(message))
示例10: register_metadata
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def register_metadata(ctx):
"""Attach additional data to sentry events."""
with configure_scope() as scope:
scope.user = {"id": ctx.author.id, "username": str(ctx.author)}
scope.set_context("client_os", {"name": system(), "version": release()})
scope.set_tag("command", ctx.message.content)
scope.set_tag("channel", str(ctx.channel))
示例11: configure_scope
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def configure_scope(*args, **kw):
return nop_class()
示例12: test_does_not_leak_scope
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def test_does_not_leak_scope(sentry_init, capture_events):
sentry_init(integrations=[FalconIntegration()])
events = capture_events()
with sentry_sdk.configure_scope() as scope:
scope.set_tag("request_data", False)
app = falcon.API()
class Resource:
def on_get(self, req, resp):
with sentry_sdk.configure_scope() as scope:
scope.set_tag("request_data", True)
def generator():
for row in range(1000):
with sentry_sdk.configure_scope() as scope:
assert scope._tags["request_data"]
yield (str(row) + "\n").encode()
resp.stream = generator()
app.add_route("/", Resource())
client = falcon.testing.TestClient(app)
response = client.simulate_get("/")
expected_response = "".join(str(row) + "\n" for row in range(1000))
assert response.text == expected_response
assert not events
with sentry_sdk.configure_scope() as scope:
assert not scope._tags["request_data"]
示例13: get
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def get(self):
with configure_scope() as scope:
scope.set_tag("foo", 42)
1 / 0
示例14: test_basic
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def test_basic(tornado_testcase, sentry_init, capture_events):
sentry_init(integrations=[TornadoIntegration()], send_default_pii=True)
events = capture_events()
client = tornado_testcase(Application([(r"/hi", CrashingHandler)]))
response = client.fetch(
"/hi?foo=bar", headers={"Cookie": "name=value; name2=value2; name3=value3"}
)
assert response.code == 500
(event,) = events
(exception,) = event["exception"]["values"]
assert exception["type"] == "ZeroDivisionError"
assert exception["mechanism"]["type"] == "tornado"
request = event["request"]
host = request["headers"]["Host"]
assert event["request"] == {
"env": {"REMOTE_ADDR": "127.0.0.1"},
"headers": {
"Accept-Encoding": "gzip",
"Connection": "close",
"Host": host,
"Cookie": "name=value; name2=value2; name3=value3",
},
"cookies": {"name": "value", "name2": "value2", "name3": "value3"},
"method": "GET",
"query_string": "foo=bar",
"url": "http://{host}/hi".format(host=host),
}
assert event["tags"] == {"foo": 42}
assert (
event["transaction"]
== "tests.integrations.tornado.test_tornado.CrashingHandler.get"
)
with configure_scope() as scope:
assert not scope._tags
示例15: test_propagates_hub
# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import configure_scope [as 别名]
def test_propagates_hub(sentry_init, capture_events, propagate_hub):
sentry_init(
default_integrations=False,
integrations=[ThreadingIntegration(propagate_hub=propagate_hub)],
)
events = capture_events()
def stage1():
with configure_scope() as scope:
scope.set_tag("stage1", True)
t = Thread(target=stage2)
t.start()
t.join()
def stage2():
1 / 0
t = Thread(target=stage1)
t.start()
t.join()
(event,) = events
(exception,) = event["exception"]["values"]
assert exception["type"] == "ZeroDivisionError"
assert exception["mechanism"] == {"type": "threading", "handled": False}
if propagate_hub:
assert event["tags"]["stage1"] is True
else:
assert "stage1" not in event.get("tags", {})