-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into martinhaintz/redact-screenshots-via-view-h…
…ierarchy * master: (28 commits) feat(angular): Update SDK provider setup for Angular 19 (#11921) feat(dynamic-sampling): adapt docs to new dynamic sampling logic (#11886) update banner for post-launch week promotion (#11964) chore(android): Add masking options to AndroidManifest (#11863) Bump API schema to 2126f7dd (#11965) chore(Profiling): Add callouts and links to Android Profiling troubleshooting info (#11905) docs(flutter): Use sentry flutter init in samples (#11858) use native crypto to generate uuid (#11959) fix vercel integration 404 (#11958) Add RN Replay Privacy page (#11798) feat(dashboards): Add docs for Dashboard Edit Access Selector (#11822) feat(app-starts): Add RN SDK min version (#11650) feat(realy): Add Relay best practices guide (#11914) docs(sdks): New Scope APIs (#11943) docs(sdks): Span Sampling (#11940) Add include explaining sample code options (#11866) devenv: internal troubleshooting (#11947) Bump API schema to 0b18bfae (#11946) Bump API schema to 2bee5317 (#11945) feat: Link to Replay Issues when we mention Perf Issues as well (#11933) ...
- Loading branch information
Showing
105 changed files
with
1,178 additions
and
582 deletions.
There are no files selected for viewing
103 changes: 60 additions & 43 deletions
103
develop-docs/application-architecture/dynamic-sampling/fidelity-and-biases.mdx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
--- | ||
title: Relay Best Practices | ||
--- | ||
|
||
Relay is a critical component in Sentry's infrastructure handling hundreds of thousands of requests per second. | ||
To make sure your changes to Relay go smoothly, there are some best practices to follow. | ||
|
||
For general Rust development best practices, make sure you read the [Rust Development](/engineering-practices/rust/) | ||
document. | ||
|
||
|
||
## Forward Compatibility | ||
|
||
Make sure changes to the event protocol and APIs are forward-compatible. Relay should not drop | ||
or truncate data it does not understand. It is a supported use-case to have customers running | ||
outdated Relays but up-to-date SDKs. | ||
|
||
|
||
## Feature Gate new Functionality | ||
|
||
|
||
Consider making your new feature conditional. Not only does this allow a gradual roll-out, but can also | ||
function as a kill-switch when something goes wrong. | ||
|
||
|
||
### Sentry Features | ||
|
||
Sentry features are best used for new product features. They can be gradually rolled out to a subset | ||
of organizations and projects. | ||
|
||
|
||
### Global Config | ||
|
||
Kill-switches, sample- and rollout-rates can also be configured via "global config". Global config | ||
is a simple mechanism to propagate a dynamic configuration from Sentry to Relay. | ||
|
||
Global config works very well for technical rollouts and kill-switches. | ||
|
||
|
||
### Relay Config | ||
|
||
The relay configuration file can also be used to feature gate functionality. This is best used | ||
for configuration which is environment specific or fundamental to how Relay operates and should not | ||
be used for product features. | ||
|
||
|
||
## Regular expressions | ||
|
||
Regular expressions are a powerful tool, they are well known and also extremely performant. | ||
But they aren't always the right choice for Relay. | ||
|
||
Some of the listed issues are specific to the [regex](https://docs.rs/regex/latest/regex/) Rust crate Relay uses | ||
and others apply to regular expressions in general. | ||
|
||
<Alert level="info" title="Important"> | ||
Review the [Rust crate's documentation](https://docs.rs/regex/latest/regex/#overview) carefully before introducing a Regex. | ||
</Alert> | ||
|
||
|
||
### Compiling | ||
|
||
Compiling a Regex is quite costly. | ||
|
||
- Do not compile a regular expression for every element that is processed. | ||
- Always cache regular expressions. | ||
|
||
Static regular expressions can be cached using [`std::sync::LazyLock`](https://doc.rust-lang.org/beta/std/sync/struct.LazyLock.html). | ||
|
||
|
||
### User defined Regular Expressions | ||
|
||
Avoid exposing regular expressions to users. Instead, consider using a targeted domain specific language or | ||
glob like patterns for which Relay has good support. | ||
|
||
<Alert level="warning" title="Important"> | ||
User-defined regexes are prone to leading to unexpected CPU or memory usage. | ||
Review the [Untrusted Input](https://docs.rs/regex/latest/regex/#untrusted-input) section in the regex crate documentation | ||
carefully. | ||
</Alert> | ||
|
||
|
||
### Avoid Unicode | ||
|
||
When not strictly necessary, specify match groups without Unicode support. For example, `\w` matches around 140000 | ||
distinct code points, when you only need to match ASCII consider using explicit groups `[0-9A-Za-z_]` instead or disable Unicode `(?-u:\w)` | ||
for the group. | ||
|
||
|
||
## (De-)Serialization | ||
|
||
(De-)Serialization of JSON, protobuf, message-pack uses a considerable amount of CPU and memory. Be mindful when and where | ||
you (de-)serialize data. | ||
|
||
Relay's architecture requires all CPU heavy operations to be done on a dedicated thread pool, which is used in the so called | ||
[processor service](https://github.com/getsentry/relay/blob/master/relay-server/src/services/processor.rs). | ||
|
||
|
||
## Data Structures | ||
|
||
All data structures come with a cost, consider using the correct data structure for your workload. | ||
|
||
- A `BTreeMap` may be more performant than a `HashMap` for small amounts of data. | ||
- Use `ahash` (through `hashbrown::HashMap`) as hasher for a `HashMap` to reduce the hashing overhead for high throughput | ||
`HashMap`'s. | ||
- Use `smallvec` over `Vec` when your data is likely to be small. | ||
- Avoid iterating through large collections in regular intervals, consider using a [priority queue](https://en.wikipedia.org/wiki/Priority_queue) or | ||
[heap](https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html) instead. | ||
|
||
|
||
## CPU and Memory constraints | ||
|
||
Relay operates on untrusted user input, make sure there are enough precautions taken to avoid a denial of service | ||
attack. | ||
|
||
- Apply size limits to payloads. | ||
- Limit memory consumption in Relay. For example, also apply size limits to decompression, not just the incoming compressed data. | ||
- Avoid exponential algorithms, often there are better data structures and algorithms available. If this is not possible, set a limit. | ||
|
||
|
||
## Don't panic | ||
|
||
Relay needs to be able to handle any user input without a [panic](https://doc.rust-lang.org/std/macro.panic.html). | ||
Always return useful errors when encountering unexpected or malformed inputs. This improves debuggability, | ||
guarantees stability and generates the necessary outcomes. |
Oops, something went wrong.