Skip to content

Commit 5ebc221

Browse files
authored
feat(develop): Add Python SDK knowledge base (#12175)
1 parent a672ed0 commit 5ebc221

File tree

7 files changed

+119
-2
lines changed

7 files changed

+119
-2
lines changed

develop-docs/sdk/platform-specifics/javascript-sdks/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: JavaScript SDKs
33
description: Information specific to developing Javascript based SDKs.
4-
sidebar_order: 7
4+
sidebar_order: 6
55
---
66

77
This Section contains JavaScript SDK-specific information that's useful for developing new or extending existing JS SDKs as well as for ingest and product teams to understanding how the JS SDKs works and what data it sends.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Native SDKs
33
description: Information specific to developing native SDKs.
4-
sidebar_order: 8
4+
sidebar_order: 7
55
---
66

77
<PageGrid />
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: Backporting
3+
description: How to backport to an earlier major.
4+
sidebar_order: 10
5+
---
6+
7+
The last normal 1.x release was [1.45.0](https://github.com/getsentry/sentry-python/releases/tag/1.45.0) in April 2024. Development on 1.x has stopped — we are not backporting any features or bugfixes outside of security fixes.
8+
9+
If there is a security issue in the SDK severe enough (use your judgement) that it needs a backport to 1.x (see for example [1.45.1](https://github.com/getsentry/sentry-python/releases/tag/1.45.1)):
10+
11+
- Checkout the `1.x` branch
12+
- Port the fix into the `1.x` branch
13+
- Trigger a release. Make sure to set both “Use workflow from” and “Target branch to merge into” to `1.x`
14+
- Continue with the release process as usual
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: CI
3+
description: Our test setup and how our CI files are generated.
4+
sidebar_order: 20
5+
---
6+
7+
The GitHub workflow files for testing specific integration groups (like AI, Web Frameworks, Databases, etc.) are generated by [this script](https://github.com/getsentry/sentry-python/blob/master/scripts/split-tox-gh-actions/split-tox-gh-actions.py). Essentially, the script scans our `tox.ini` and generates the group test CI YAML files in `.github/workflows`.
8+
9+
There are multiple components to this:
10+
* `tox.ini` is where the configuration (what to test and what versions) is read from
11+
* `scripts/split-tox-gh-actions/split-tox-gh-actions.py` is the script that defines the [test groups](https://github.com/getsentry/sentry-python/blob/0f3e5db0c8aabcad0baf0e8b2d3e31e27e839b3e/scripts/split-tox-gh-actions/split-tox-gh-actions.py#L57) and generates the resulting YAML files
12+
* `scripts/split-tox-gh-actions/templates` contains the jinja2 template snippets used to generate the YAML files
13+
* `.github/workflows/test-integrations-*.yml` are the resulting workflow configuration YAMLs
14+
15+
If you update any of the components without keeping the rest in sync, for instance by making a change in one of the `test-integrations-*.yml` files that is not reflected in the templates in `scripts/split-tox-gh-actions/templates`, CI will error out as it actually checks if everything is in sync, meaning it runs the `split-tox-gh-actions.py` script and compares the result with the committed YAMLs.
16+
17+
## AWS Lambda Test Suite
18+
19+
The AWS Lambda test suite will fail by default on new PRs. If you are an external contributor, this is not something you have to worry about, unless you've made changes actually affecting the AWS Lambda integration. It's a security precaution on our part.
20+
21+
Sensitive test suites (currently only AWS Lambda) require maintainer review to ensure that tests do not compromise our secrets. This review must be repeated after any code revisions.
22+
23+
Before running sensitive test suites, maintainers need to carefully check the PR. Then they will apply the `Trigger: tests using secrets` label. The label will be removed after any code changes to enforce our policy requiring maintainers to review all code revisions before running sensitive tests.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: Feature Branches
3+
description: How-to for syncing long-running feature branches.
4+
sidebar_order: 30
5+
---
6+
7+
Sometimes we have long-running feature branches that can't be merged into `master` yet because they contain breaking changes (e.g. `sentry-sdk-2.0`, `potel-base`). They have to be kept in sync with `master` though.
8+
9+
You might be tempted to branch off the feature branch and do the merge there, maybe make a PR so that you can double check the changes in the UI and make sure CI is green. In that case you need to make sure you **don't actually commit the merge from another branch** — the merge commit needs to be directly on the feature branch, otherwise `git` doesn't set the parent commits for the merge commit properly and the feature branch will still have unresolved conflicts (even though you literally just resolved them).
10+
11+
## How to sync so that merge conflicts are recognized as resolved
12+
13+
If you still want the nice GH diff and have CI run on your changes:
14+
15+
- check out the feature branch and `git merge master` into it
16+
- solve conflicts (while still on the feature branch)
17+
- commit the merge (still on the feature branch)
18+
- *(if you're already confident all is good, you can just short circuit and push now, otherwise:)*
19+
- then open a new branch from your feature branch `git checkout -b sync-feature-with-master`
20+
- push the new branch, make a PR, look at the nice diff in GitHub, see if the tests pass
21+
- if everything looks ok: don't merge the PR! this will not mark the merge conflicts as solved
22+
- instead, `git checkout` your feature branch (with the merge commit on top) and `push` it
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Generating API Docs
3+
description: How to deal with issues generating our API docs.
4+
sidebar_order: 40
5+
---
6+
7+
## Problem
8+
9+
`sphinx` (run as part of `make apidocs`) sometimes has cryptic circular import errors and causes CI to fail. This is because we run it with `TYPE_CHECKING` and while `mypy` statically checks types, `sphinx` is dynamic and thus introduces circularity into type checking which is normally ok.
10+
11+
```python
12+
sphinx.errors.SphinxWarning: autodoc: failed to import function 'api.capture_event' from module 'sentry_sdk'; the following exception was raised:
13+
cannot import name 'logger' from partially initialized module 'sentry_sdk.utils' (most likely due to a circular import) (/home/runner/work/sentry-python/sentry-python/sentry_sdk/utils.py)
14+
```
15+
16+
See https://github.com/tox-dev/sphinx-autodoc-typehints?tab=readme-ov-file#dealing-with-circular-imports
17+
18+
These circular import issues may surface not just in our SDK code but also in built-in Sphinx extensions. You might get something like this:
19+
20+
```
21+
Extension error:
22+
Could not import extension sphinx.domains.c (exception: cannot import name 'ASTDeclaration' from partially initialized module 'sphinx.domains.c._ast' (most likely due to a circular import) (.venv/lib/python3.11/site-packages/sphinx/domains/c/_ast.py))
23+
```
24+
25+
## Solution
26+
27+
To solve this in SDK code, just use forward references, so instead of:
28+
29+
```python
30+
from sentry_sdk.integrations import Integration
31+
32+
def foo(integration):
33+
# type: (Integration) -> None
34+
pass
35+
```
36+
37+
just use:
38+
39+
```python
40+
import sentry_sdk
41+
42+
def foo(integration):
43+
# type: (sentry_sdk.integrations.Integration) -> None
44+
pass
45+
```
46+
47+
If the circular import is coming from an extension, add it to the [imports in conf.py](https://github.com/getsentry/sentry-python/blob/302457dec22bd105beb849e98324f653d8c7b5f0/docs/conf.py#L6-L12).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Python SDK
3+
description: Information specific to developing the Python SDK.
4+
sidebar_order: 8
5+
---
6+
7+
This section serves as a knowledge base for the Python SDK where we document
8+
common gotchas, seldom used processes, and in general stuff that comes up every
9+
now and then.
10+
11+
<PageGrid></PageGrid>

0 commit comments

Comments
 (0)