Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_trusted_external_relays_should_receive_minimal_configs(self):
self._setup_relay(False, True)
result, status_code = self._call_endpoint(full_config=False)
assert status_code < 400
cfg = safe.get_path(result, "configs", six.text_type(self.project.id))
assert safe.get_path(cfg, "disabled") is False
public_key, = cfg["publicKeys"]
assert public_key["publicKey"] == self.projectkey.public_key
assert public_key["isEnabled"]
assert "quotas" not in public_key
assert safe.get_path(cfg, "slug") == self.project.slug
last_change = safe.get_path(cfg, "lastChange")
assert self._date_regex.match(last_change) is not None
last_fetch = safe.get_path(cfg, "lastFetch")
assert self._date_regex.match(last_fetch) is not None
assert safe.get_path(cfg, "projectId") == self.project.id
assert safe.get_path(cfg, "slug") == self.project.slug
assert safe.get_path(cfg, "rev") is not None
assert safe.get_path(cfg, "organizationId") is None
assert safe.get_path(cfg, "config", "trustedRelays") == [self.relay.public_key]
assert safe.get_path(cfg, "config", "filterSettings") is None
assert safe.get_path(cfg, "config", "groupingConfig") is None
assert safe.get_path(cfg, "config", "datascrubbingSettings", "scrubData") is not None
assert safe.get_path(cfg, "config", "datascrubbingSettings", "scrubIpAddresses") is not None
assert safe.get_path(cfg, "config", "piiConfig", "rules") is None
assert safe.get_path(cfg, "config", "piiConfig", "applications") is None
def from_event_json(cls, event_data):
sdk_name = get_path(event_data, "sdk", "name")
if sdk_name:
sdk_name = sdk_name.lower().rsplit(":", 1)[0]
if sdk_name == "sentry-python":
sdk_name = "sentry.python"
return cls(
sdk_name=sdk_name,
sdk_version=get_path(event_data, "sdk", "version"),
modules=get_path(event_data, "modules"),
integrations=get_path(event_data, "sdk", "integrations"),
)
def _get_attr_with_meta(self, event, attr, default=None):
value = event.data.get(attr, default)
meta = get_path(event.data, "_meta", attr)
return (value, meta_with_chunks(value, meta))
def _report_stack(stacktrace, container, is_exception=False):
if not is_exception and (not stacktrace or not get_path(stacktrace, "frames", filter=True)):
return
platforms = set(
frame.get("platform") or data.get("platform")
for frame in get_path(stacktrace, "frames", filter=True, default=())
)
rv.append(
StacktraceInfo(
stacktrace=stacktrace,
container=container,
platforms=platforms,
is_exception=is_exception,
)
def _get_legacy_message_with_meta(self, event):
meta = event.data.get("_meta")
message = get_path(event.data, "logentry", "formatted")
msg_meta = get_path(meta, "logentry", "formatted")
if not message:
message = get_path(event.data, "logentry", "message")
msg_meta = get_path(meta, "logentry", "message")
if not message:
message = event.message
msg_meta = None
return (message, meta_with_chunks(message, msg_meta))
def get_metadata(self, data):
message = strip(
get_path(data, "logentry", "formatted") or get_path(data, "logentry", "message")
)
if message:
title = truncatechars(message.splitlines()[0], 100)
else:
title = ""
return {"title": title}
def normalize_stacktraces_for_grouping(data, grouping_config=None):
"""
Applies grouping enhancement rules and ensure in_app is set on all frames.
This also trims functions if necessary.
"""
stacktraces = []
for stacktrace_info in find_stacktraces_in_data(data, include_raw=True):
frames = get_path(stacktrace_info.stacktrace, "frames", filter=True, default=())
if frames:
stacktraces.append(frames)
if not stacktraces:
return
platform = data.get("platform")
# Put the trimmed function names into the frames. We only do this if
# the trimming produces a different function than the function we have
# otherwise stored in `function` to not make the payload larger
# unnecessarily.
for frames in stacktraces:
for frame in frames:
# Restore the original in_app value before the first grouping
# enhancers have been run. This allows to re-apply grouping
def exceptions(self):
return get_path(self.values, filter=True)
def _iter_frames(data):
try:
for frame in get_path(data, "stacktrace", "frames", filter=True) or ():
yield frame
except KeyError:
pass
try:
values = get_path(data, "exception", "values", filter=True) or ()
except KeyError:
return
for value in values:
try:
for frame in get_path(value, "stacktrace", "frames", filter=True) or ():
yield frame
except KeyError:
continue
@classmethod
def to_python(cls, data):
return cls(
values=[
v and SingleException.to_python(v, slim_frames=False)
for v in get_path(data, "values", default=[])
],
exc_omitted=data.get("exc_omitted"),
)