Skip to content

Commit 896a017

Browse files
committed
meta: Update AGENTS.md
1 parent 641517a commit 896a017

1 file changed

Lines changed: 53 additions & 18 deletions

File tree

‎AGENTS.md‎

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Agent Instructions
1+
# Working with the Codebase
22

33
## Tox
44

@@ -40,21 +40,56 @@ Do NOT edit these directly — modify source scripts instead:
4040
3. Add to group in `scripts/split_tox_gh_actions/split_tox_gh_actions.py`
4141
4. Run `scripts/generate-test-files.sh`
4242

43-
## Integration Contract
4443

45-
- Don't crash applications or swallow exceptions
46-
- Don't mutate object references or alter function signatures
47-
- Don't leak file descriptors or make unexpected DB requests
48-
- Write defensive code
49-
- Use end-to-end tests (not mocks)
50-
51-
## Key Paths
52-
53-
| Path | Description |
54-
|------|-------------|
55-
| `sentry_sdk/integrations/` | integration modules |
56-
| `sentry_sdk/ai/` | AI monitoring |
57-
| `sentry_sdk/crons/` | Cron monitoring |
58-
| `sentry_sdk/profiler/` | Performance profiling |
59-
| `tests/integrations/{name}/` | Integration test suites |
60-
| `scripts/populate_tox/config.py` | Test suite configuration |
44+
# SDK Implementation Guidelines
45+
46+
## General Guidelines
47+
48+
- Don't crash applications. SDK-caused exceptions should always be handled with `capture_internal_exceptions`.
49+
- Don't swallow exceptions not caused by the SDK. The user's app should behave the same as it would without the SDK. If exceptions would bubble all the way up and crash the app, they should do that.
50+
- Don't submit huge PRs. If a big feature can be meaningfully split into several PRs, split it. If the PRs depend on each other, stack them.
51+
- No side effects. Don't make extra DB or HTTP requests or leak file descriptors.
52+
- The user is instructed to initialize the SDK as early as possible. You may assume this is the case.
53+
54+
## Maintainability & Code Structure
55+
56+
- **Don't fragment code unnecessarily**:
57+
- Only extract code into a function if it's used in multiple places or if it's overly complex and distracts from understanding the flow of the neighboring code.
58+
- Prefer one file over splitting implementation into multiple files. Having to follow the flow of code by jumping through several files is not good style.
59+
- Keep constants at the top of the file, under imports.
60+
- Don't inline imports in functions. Strongly prefer adding imports to the top of the file, on the top level.
61+
62+
## Integration Guidelines
63+
64+
When integrating with a package:
65+
66+
- Prefer the following approaches, in this order of preference:
67+
1) Signals, hooks, callbacks provided by the package
68+
2) Monkeypatching public functions
69+
3) Monkeypatching private functions (the more integral to the package, the better, as they're less likely to change)
70+
4) Other approaches only if the above fails
71+
- A mix of the approaches above is also acceptable.
72+
- **Minimize state.**
73+
- If you need to store state (for instance, a running span), prefer storing it on an object of the package that gets passed around "for free".
74+
- Keeping state manually (e.g., implementing lookup tables) should be a last resort option.
75+
- Write code for the most common usecase. Keep scope small. Features can always be added later, if requested. Don't design for special cases.
76+
- Don't mutate object references or alter function signatures.
77+
- Take into account that packages evolve and change.
78+
- When monkeypatching a function, unless it's public, allow for it changing the order of arguments, or adding an argument, in the future.
79+
```python
80+
# Bad monkeypatching
81+
def patched_func(arg_you_need, another_arg, third_arg):
82+
# Don't spell out all arguments. If a new argument is added or an argument
83+
# we don't use is renamed, the patch breaks.
84+
...
85+
86+
# Good monkeypatching
87+
def patched_func(arg_you_need, *args, **kwargs):
88+
# Only assume the argument you need is there. Leave the rest of the
89+
# arguments flexible, so that we don't break if they change.
90+
...
91+
```
92+
93+
## Test Guidelines
94+
95+
- Use end-to-end tests, not mocks.

0 commit comments

Comments
 (0)