Skip to content

Commit

Permalink
Merge branch 'master' into add-readbeat-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana authored Mar 18, 2024
2 parents c0d15c9 + 9bdd029 commit 68bc628
Show file tree
Hide file tree
Showing 78 changed files with 1,502 additions and 207 deletions.
4 changes: 3 additions & 1 deletion .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ targets:
pypi:sentry-sdk:
- name: github
- name: aws-lambda-layer
includeNames: /^sentry-python-serverless-\d+(\.\d+)*\.zip$/
# This regex that matches the version is taken from craft:
# https://github.com/getsentry/craft/blob/8d77c38ddbe4be59f98f61b6e42952ca087d3acd/src/utils/version.ts#L11
includeNames: /^sentry-python-serverless-\bv?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-?([\da-z-]+(?:\.[\da-z-]+)*))?(?:\+([\da-z-]+(?:\.[\da-z-]+)*))?\b.zip$/
layerName: SentryPythonServerlessSDK
compatibleRuntimes:
- name: python
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
force:
description: Force a release even when there are release-blockers (optional)
required: false
merge_target:
description: Target branch to merge into. Uses the default branch as a fallback (optional)
required: false

jobs:
release:
Expand All @@ -26,3 +29,4 @@ jobs:
with:
version: ${{ github.event.inputs.version }}
force: ${{ github.event.inputs.force }}
merge_target: ${{ github.event.inputs.merge_target }}
14 changes: 13 additions & 1 deletion .github/workflows/test-integrations-data-processing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.5","3.7","3.8","3.11","3.12"]
python-version: ["3.5","3.7","3.8","3.9","3.11","3.12"]
# python3.6 reached EOL and is no longer being supported on
# new versions of hosted runners on Github Actions
# ubuntu-20.04 is the last version that supported python3.6
Expand Down Expand Up @@ -58,6 +58,10 @@ jobs:
run: |
set -x # print commands that are executed
./scripts/runtox.sh "py${{ matrix.python-version }}-huey-latest" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
- name: Test openai latest
run: |
set -x # print commands that are executed
./scripts/runtox.sh "py${{ matrix.python-version }}-openai-latest" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
- name: Test rq latest
run: |
set -x # print commands that are executed
Expand Down Expand Up @@ -110,6 +114,10 @@ jobs:
run: |
set -x # print commands that are executed
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-huey" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
- name: Test openai pinned
run: |
set -x # print commands that are executed
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-openai" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
- name: Test rq pinned
run: |
set -x # print commands that are executed
Expand Down Expand Up @@ -151,6 +159,10 @@ jobs:
run: |
set -x # print commands that are executed
./scripts/runtox.sh --exclude-latest "py2.7-huey" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
- name: Test openai py27
run: |
set -x # print commands that are executed
./scripts/runtox.sh --exclude-latest "py2.7-openai" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
- name: Test rq py27
run: |
set -x # print commands that are executed
Expand Down
95 changes: 95 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,100 @@
# Changelog

## 1.42.0

### Various fixes & improvements

- **New integration:** [OpenAI integration](https://docs.sentry.io/platforms/python/integrations/openai/) (#2791) by @colin-sentry

We added an integration for OpenAI to capture errors and also performance data when using the OpenAI Python SDK.

Useage:

This integrations is auto-enabling, so if you have the `openai` package in your project it will be enabled. Just initialize Sentry before you create your OpenAI client.

```python
from openai import OpenAI

import sentry_sdk

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
enable_tracing=True,
traces_sample_rate=1.0,
)

client = OpenAI()
```

For more information, see the documentation for [OpenAI integration](https://docs.sentry.io/platforms/python/integrations/openai/).

- Discard open OpenTelemetry spans after 10 minutes (#2801) by @antonpirker
- Propagate sentry-trace and baggage headers to Huey tasks (#2792) by @cnschn
- Added Event type (#2753) by @szokeasaurusrex
- Improve scrub_dict typing (#2768) by @szokeasaurusrex
- Dependencies: bump types-protobuf from 4.24.0.20240302 to 4.24.0.20240311 (#2797) by @dependabot

## 1.41.0

### Various fixes & improvements

- Add recursive scrubbing to `EventScrubber` (#2755) by @Cheapshot003

By default, the `EventScrubber` will not search your events for potential
PII recursively. With this release, you can enable this behavior with:

```python
import sentry_sdk
from sentry_sdk.scrubber import EventScrubber

sentry_sdk.init(
# ...your usual settings...
event_scrubber=EventScrubber(recursive=True),
)
```

- Expose `socket_options` (#2786) by @sentrivana

If the SDK is experiencing connection issues (connection resets, server
closing connection without response, etc.) while sending events to Sentry,
tweaking the default `urllib3` socket options to the following can help:

```python
import socket
from urllib3.connection import HTTPConnection
import sentry_sdk

sentry_sdk.init(
# ...your usual settings...
socket_options=HTTPConnection.default_socket_options + [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
# note: skip the following line if you're on MacOS since TCP_KEEPIDLE doesn't exist there
(socket.SOL_TCP, socket.TCP_KEEPIDLE, 45),
(socket.SOL_TCP, socket.TCP_KEEPINTVL, 10),
(socket.SOL_TCP, socket.TCP_KEEPCNT, 6),
],
)
```

- Allow to configure merge target for releases (#2777) by @sentrivana
- Allow empty character in metric tags values (#2775) by @viglia
- Replace invalid tag values with an empty string instead of _ (#2773) by @markushi
- Add documentation comment to `scrub_list` (#2769) by @szokeasaurusrex
- Fixed regex to parse version in lambda package file (#2767) by @antonpirker
- xfail broken AWS Lambda tests for now (#2794) by @sentrivana
- Removed print statements because it messes with the tests (#2789) by @antonpirker
- Bump `types-protobuf` from 4.24.0.20240129 to 4.24.0.20240302 (#2782) by @dependabot
- Bump `checkouts/data-schemas` from `eb941c2` to `ed078ed` (#2781) by @dependabot

## 1.40.6

### Various fixes & improvements

- Fix compatibility with `greenlet`/`gevent` (#2756) by @sentrivana
- Fix query source relative filepath (#2717) by @gggritso
- Support `clickhouse-driver==0.2.7` (#2752) by @sentrivana
- Bump `checkouts/data-schemas` from `6121fd3` to `eb941c2` (#2747) by @dependabot

## 1.40.5

### Various fixes & improvements
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ lint: .venv
apidocs: .venv
@$(VENV_PATH)/bin/pip install --editable .
@$(VENV_PATH)/bin/pip install -U -r ./docs-requirements.txt
rm -rf docs/_build
@$(VENV_PATH)/bin/sphinx-build -vv -W -b html docs/ docs/_build
.PHONY: apidocs

Expand Down
2 changes: 1 addition & 1 deletion checkouts/data-schemas
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
copyright = "2019-{}, Sentry Team and Contributors".format(datetime.now().year)
author = "Sentry Team and Contributors"

release = "1.40.5"
release = "1.42.0"
version = ".".join(release.split(".")[:2]) # The short X.Y version.


Expand Down
2 changes: 1 addition & 1 deletion linter-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mypy
black
flake8==5.0.4 # flake8 depends on pyflakes>=3.0.0 and this dropped support for Python 2 "# type:" comments
types-certifi
types-protobuf==4.24.0.20240129 # newer raises an error on mypy sentry_sdk
types-protobuf==4.24.0.20240311 # newer raises an error on mypy sentry_sdk
types-redis
types-setuptools
pymongo # There is no separate types module.
Expand Down
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ ignore_missing_imports = True
ignore_missing_imports = True
[mypy-huey.*]
ignore_missing_imports = True
[mypy-openai.*]
ignore_missing_imports = True
[mypy-arq.*]
ignore_missing_imports = True
[mypy-grpc.*]
Expand Down
1 change: 1 addition & 0 deletions scripts/split-tox-gh-actions/split-tox-gh-actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"beam",
"celery",
"huey",
"openai",
"rq",
],
"Databases": [
Expand Down
64 changes: 62 additions & 2 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@


if TYPE_CHECKING:
from collections.abc import MutableMapping

from datetime import datetime

from types import TracebackType
from typing import Any
from typing import Callable
Expand All @@ -19,13 +23,69 @@
from typing import Tuple
from typing import Type
from typing import Union
from typing_extensions import Literal
from typing_extensions import Literal, TypedDict

# "critical" is an alias of "fatal" recognized by Relay
LogLevelStr = Literal["fatal", "critical", "error", "warning", "info", "debug"]

Event = TypedDict(
"Event",
{
"breadcrumbs": dict[
Literal["values"], list[dict[str, Any]]
], # TODO: We can expand on this type
"check_in_id": str,
"contexts": dict[str, dict[str, object]],
"dist": str,
"duration": Optional[float],
"environment": str,
"errors": list[dict[str, Any]], # TODO: We can expand on this type
"event_id": str,
"exception": dict[
Literal["values"], list[dict[str, Any]]
], # TODO: We can expand on this type
"extra": MutableMapping[str, object],
"fingerprint": list[str],
"level": LogLevelStr,
"logentry": Mapping[str, object],
"logger": str,
"measurements": dict[str, object],
"message": str,
"modules": dict[str, str],
"monitor_config": Mapping[str, object],
"monitor_slug": Optional[str],
"platform": Literal["python"],
"profile": object, # Should be sentry_sdk.profiler.Profile, but we can't import that here due to circular imports
"release": str,
"request": dict[str, object],
"sdk": Mapping[str, object],
"server_name": str,
"spans": list[dict[str, object]],
"stacktrace": dict[
str, object
], # We access this key in the code, but I am unsure whether we ever set it
"start_timestamp": datetime,
"status": Optional[str],
"tags": MutableMapping[
str, str
], # Tags must be less than 200 characters each
"threads": dict[
Literal["values"], list[dict[str, Any]]
], # TODO: We can expand on this type
"timestamp": Optional[datetime], # Must be set before sending the event
"transaction": str,
"transaction_info": Mapping[str, Any], # TODO: We can expand on this type
"type": Literal["check_in", "transaction"],
"user": dict[str, object],
"_metrics_summary": dict[str, object],
},
total=False,
)

ExcInfo = Tuple[
Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]
]

Event = Dict[str, Any]
Hint = Dict[str, Any]

Breadcrumb = Dict[str, Any]
Expand Down
5 changes: 3 additions & 2 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
BreadcrumbHint,
ExcInfo,
MeasurementUnit,
LogLevelStr,
)
from sentry_sdk.tracing import Span

Expand Down Expand Up @@ -91,7 +92,7 @@ def capture_event(
@hubmethod
def capture_message(
message, # type: str
level=None, # type: Optional[str]
level=None, # type: Optional[LogLevelStr]
scope=None, # type: Optional[Any]
**scope_kwargs # type: Any
):
Expand Down Expand Up @@ -189,7 +190,7 @@ def set_user(value):

@scopemethod
def set_level(value):
# type: (str) -> None
# type: (LogLevelStr) -> None
return Hub.current.scope.set_level(value)


Expand Down
Loading

0 comments on commit 68bc628

Please sign in to comment.