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