Skip to content

Commit 68bfea0

Browse files
committed
add metadata types
1 parent f4d76ec commit 68bfea0

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
from __future__ import annotations
2+
3+
from typing import NotRequired, TypedDict
4+
5+
# NOTE: The structure in these metadata types is intentionaly flat, to make it easier to query in
6+
# Redash or BigQuery, and they are all merged into a flat type, stored in
7+
# `GroupHashMetadata.hashing_metadata`. If entries are added, they should be namespaced according to
8+
# their corresponding hash basis (so, for example, `fingerprint_source` and `message_source`, rather
9+
# than just `source`), both for clarity and to avoid collisions.
10+
11+
12+
# Fingerprint data, gathered both during stand-alone custom/built-in fingerprinting and hybrid
13+
# fingerprinting involving message, stacktrace, security, or template hashing.
14+
class FingerprintHashingMetadata(TypedDict):
15+
# The fingerprint value
16+
fingerprint: str
17+
# Either "client", "server_builtin_rule", or "server_custom_rule". (We don't have a "none of the
18+
# above" option here because we only record fingerprint metadata in cases where there's some
19+
# sort of custom fingerprint.)
20+
fingerprint_source: str
21+
# The fingerprint value set in the SDK, if anything other than ["{{ default }}"]. Note that just
22+
# because this is set doesn't mean we necessarily used it for grouping, since server-side rules
23+
# take precedence over client fingerprints. See `fingerprint_source` above.
24+
client_fingerprint: NotRequired[str]
25+
# The server-side rule applied, if any
26+
matched_fingerprinting_rule: NotRequired[str]
27+
# Whether or not a hybrid fingerprint (one involving both the signal value `{{ default }}` and a
28+
# custom value) was used. In that case, we group as we normally would, but then split the events
29+
# into more granular groups based on the custom value.
30+
is_hybrid_fingerprint: bool
31+
32+
33+
# Data gathered when an event is grouped by log message or error type and value
34+
class MessageHashingMetadata(TypedDict):
35+
# Either "message" (from "message" or "logentry") or "exception" (error type and value, in cases
36+
# where there's no stacktrace)
37+
message_source: str
38+
# Whether we've done any parameterization of the message, such as replacing a number with "<int>"
39+
message_parameterized: bool
40+
41+
42+
# Data from message-based bybrid fingerprinting
43+
class SaltedMessageHashingMetadata(MessageHashingMetadata, FingerprintHashingMetadata):
44+
pass
45+
46+
47+
# Data gathered when an event is grouped based on a stacktrace found in an exception, a thread, or
48+
# diretly in the event
49+
class StacktraceHashingMetadata(TypedDict):
50+
# Either "in-app" or "system"
51+
stacktrace_type: str
52+
# Where in the event data the stacktrace was found - either "exception", "thread", or
53+
# "top-level"
54+
stacktrace_location: str
55+
# The number of stacktraces used for grouping (will be more than 1 in cases of chained
56+
# exceptions)
57+
num_stacktraces: int
58+
59+
60+
# Data from stacktrace-based bybrid fingerprinting
61+
class SaltedStacktraceHashingMetadata(StacktraceHashingMetadata, FingerprintHashingMetadata):
62+
pass
63+
64+
65+
# Data gathered when grouping browser-based security (Content Security Policy, Certifcate
66+
# Transparency, Online Certificate Status Protocol Stapling, or HTTP Public Key Pinning) reports
67+
class SecurityHashingMetadata(TypedDict):
68+
# Either "csp", "expect-ct", "expect-staple", or "hpkp"
69+
security_report_type: str
70+
# Domain name of the blocked address
71+
blocked_host: str
72+
# The CSP directive which was violated
73+
csp_directive: NotRequired[str]
74+
# In the case of a local `script-src` violation, whether it's an `unsafe-inline` or an
75+
# `unsafe-eval` violation
76+
csp_script_violation: NotRequired[str]
77+
78+
79+
# Data from security-report-based bybrid fingerprinting
80+
class SaltedSecurityHashingMetadata(SecurityHashingMetadata, FingerprintHashingMetadata):
81+
pass
82+
83+
84+
# Data gathered when grouping errors generated by Django templates
85+
class TemplateHashingMetadata(TypedDict):
86+
# The name of the template with the invalid template variable
87+
template_name: NotRequired[str]
88+
# The text of the line in the template containing the invalid variable
89+
template_context_line: NotRequired[str]
90+
91+
92+
# Data from template-based bybrid fingerprinting
93+
class SaltedTemplateHashingMetadata(TemplateHashingMetadata, FingerprintHashingMetadata):
94+
pass
95+
96+
97+
# Data gathered when legacy checksum grouping (wherein a hash is provided directly in the event) is used
98+
class ChecksumHashingMetadata(TypedDict):
99+
# The checksum used for grouping
100+
checksum: str
101+
# The incoming checksum value, if it was something other than a 32-digit hex value and we
102+
# therefore had to hash it before using it
103+
raw_checksum: NotRequired[str]
104+
105+
106+
# Data gathered when no other grouping method produces results
107+
class FallbackHashingMetadata(TypedDict):
108+
# Whether we landed in the fallback because of a lack of data, because we had a stacktrace but
109+
# all frames were ignored, or some other reason
110+
fallback_reason: str
111+
112+
113+
HashingMetadata = (
114+
FingerprintHashingMetadata
115+
| MessageHashingMetadata
116+
| SaltedMessageHashingMetadata
117+
| StacktraceHashingMetadata
118+
| SaltedStacktraceHashingMetadata
119+
| SecurityHashingMetadata
120+
| SaltedSecurityHashingMetadata
121+
| TemplateHashingMetadata
122+
| SaltedTemplateHashingMetadata
123+
| ChecksumHashingMetadata
124+
| FallbackHashingMetadata
125+
)

0 commit comments

Comments
 (0)