Skip to content

Commit 5e8508f

Browse files
Merge branch 'master' into webb/unraisable-integration
2 parents 56369a2 + b1a8b63 commit 5e8508f

File tree

9 files changed

+140
-185
lines changed

9 files changed

+140
-185
lines changed

.github/workflows/test-integrations-ai.yml

Lines changed: 12 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -22,85 +22,6 @@ env:
2222
CACHED_BUILD_PATHS: |
2323
${{ github.workspace }}/dist-serverless
2424
jobs:
25-
test-ai-latest:
26-
name: AI (latest)
27-
timeout-minutes: 30
28-
runs-on: ${{ matrix.os }}
29-
strategy:
30-
fail-fast: false
31-
matrix:
32-
python-version: ["3.9","3.11","3.12"]
33-
# python3.6 reached EOL and is no longer being supported on
34-
# new versions of hosted runners on Github Actions
35-
# ubuntu-20.04 is the last version that supported python3.6
36-
# see https://github.com/actions/setup-python/issues/544#issuecomment-1332535877
37-
os: [ubuntu-22.04]
38-
# Use Docker container only for Python 3.6
39-
container: ${{ matrix.python-version == '3.6' && 'python:3.6' || null }}
40-
steps:
41-
- uses: actions/[email protected]
42-
- uses: actions/setup-python@v5
43-
if: ${{ matrix.python-version != '3.6' }}
44-
with:
45-
python-version: ${{ matrix.python-version }}
46-
allow-prereleases: true
47-
- name: Setup Test Env
48-
run: |
49-
pip install "coverage[toml]" tox
50-
- name: Erase coverage
51-
run: |
52-
coverage erase
53-
- name: Test anthropic latest
54-
run: |
55-
set -x # print commands that are executed
56-
./scripts/runtox.sh "py${{ matrix.python-version }}-anthropic-latest"
57-
- name: Test cohere latest
58-
run: |
59-
set -x # print commands that are executed
60-
./scripts/runtox.sh "py${{ matrix.python-version }}-cohere-latest"
61-
- name: Test langchain latest
62-
run: |
63-
set -x # print commands that are executed
64-
./scripts/runtox.sh "py${{ matrix.python-version }}-langchain-latest"
65-
- name: Test openai latest
66-
run: |
67-
set -x # print commands that are executed
68-
./scripts/runtox.sh "py${{ matrix.python-version }}-openai-latest"
69-
- name: Test openai_agents latest
70-
run: |
71-
set -x # print commands that are executed
72-
./scripts/runtox.sh "py${{ matrix.python-version }}-openai_agents-latest"
73-
- name: Test huggingface_hub latest
74-
run: |
75-
set -x # print commands that are executed
76-
./scripts/runtox.sh "py${{ matrix.python-version }}-huggingface_hub-latest"
77-
- name: Generate coverage XML (Python 3.6)
78-
if: ${{ !cancelled() && matrix.python-version == '3.6' }}
79-
run: |
80-
export COVERAGE_RCFILE=.coveragerc36
81-
coverage combine .coverage-sentry-*
82-
coverage xml --ignore-errors
83-
- name: Generate coverage XML
84-
if: ${{ !cancelled() && matrix.python-version != '3.6' }}
85-
run: |
86-
coverage combine .coverage-sentry-*
87-
coverage xml
88-
- name: Upload coverage to Codecov
89-
if: ${{ !cancelled() }}
90-
uses: codecov/[email protected]
91-
with:
92-
token: ${{ secrets.CODECOV_TOKEN }}
93-
files: coverage.xml
94-
# make sure no plugins alter our coverage reports
95-
plugins: noop
96-
verbose: true
97-
- name: Upload test results to Codecov
98-
if: ${{ !cancelled() }}
99-
uses: codecov/test-results-action@v1
100-
with:
101-
token: ${{ secrets.CODECOV_TOKEN }}
102-
files: .junitxml
103-
verbose: true
10425
test-ai-pinned:
10526
name: AI (pinned)
10627
timeout-minutes: 30
@@ -137,14 +58,22 @@ jobs:
13758
run: |
13859
set -x # print commands that are executed
13960
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-cohere"
140-
- name: Test langchain pinned
61+
- name: Test langchain-base pinned
62+
run: |
63+
set -x # print commands that are executed
64+
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-langchain-base"
65+
- name: Test langchain-notiktoken pinned
66+
run: |
67+
set -x # print commands that are executed
68+
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-langchain-notiktoken"
69+
- name: Test openai-base pinned
14170
run: |
14271
set -x # print commands that are executed
143-
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-langchain"
144-
- name: Test openai pinned
72+
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-openai-base"
73+
- name: Test openai-notiktoken pinned
14574
run: |
14675
set -x # print commands that are executed
147-
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-openai"
76+
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-openai-notiktoken"
14877
- name: Test openai_agents pinned
14978
run: |
15079
set -x # print commands that are executed

scripts/populate_tox/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ be expressed like so:
153153
}
154154
```
155155

156+
### `integration_name`
157+
158+
Sometimes, the name of the test suite doesn't match the name of the integration.
159+
For example, we have the `openai_base` and `openai_notiktoken` test suites, both
160+
of which are actually testing the `openai` integration. If this is the case, you can use the `integration_name` key to define the name of the integration. If not provided, it will default to the name of the test suite.
161+
162+
Linking an integration to a test suite allows the script to access integration configuration like for example the minimum version defined in `sentry_sdk/integrations/__init__.py`.
163+
156164

157165
## How-Tos
158166

scripts/populate_tox/config.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,26 @@
126126
"huggingface_hub": {
127127
"package": "huggingface_hub",
128128
},
129+
"langchain-base": {
130+
"package": "langchain",
131+
"integration_name": "langchain",
132+
"deps": {
133+
"*": ["openai", "tiktoken", "langchain-openai"],
134+
"<=0.1": ["httpx<0.28.0"],
135+
">=0.3": ["langchain-community"],
136+
},
137+
"include": "<1.0",
138+
},
139+
"langchain-notiktoken": {
140+
"package": "langchain",
141+
"integration_name": "langchain",
142+
"deps": {
143+
"*": ["openai", "langchain-openai"],
144+
"<=0.1": ["httpx<0.28.0"],
145+
">=0.3": ["langchain-community"],
146+
},
147+
"include": "<1.0",
148+
},
129149
"launchdarkly": {
130150
"package": "launchdarkly-server-sdk",
131151
},
@@ -139,6 +159,24 @@
139159
"loguru": {
140160
"package": "loguru",
141161
},
162+
"openai-base": {
163+
"package": "openai",
164+
"integration_name": "openai",
165+
"deps": {
166+
"*": ["pytest-asyncio", "tiktoken"],
167+
"<1.55": ["httpx<0.28"],
168+
},
169+
"python": ">=3.8",
170+
},
171+
"openai-notiktoken": {
172+
"package": "openai",
173+
"integration_name": "openai",
174+
"deps": {
175+
"*": ["pytest-asyncio"],
176+
"<1.55": ["httpx<0.28"],
177+
},
178+
"python": ">=3.8",
179+
},
142180
"openai_agents": {
143181
"package": "openai-agents",
144182
"deps": {

scripts/populate_tox/populate_tox.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@
7676
"httpx",
7777
"langchain",
7878
"langchain_notiktoken",
79-
"openai",
80-
"openai_notiktoken",
8179
"pure_eval",
8280
"quart",
8381
"ray",
@@ -141,7 +139,11 @@ def _prefilter_releases(
141139
- the list of prefiltered releases
142140
- an optional prerelease if there is one that should be tested
143141
"""
144-
min_supported = _MIN_VERSIONS.get(integration)
142+
integration_name = (
143+
TEST_SUITE_CONFIG[integration].get("integration_name") or integration
144+
)
145+
146+
min_supported = _MIN_VERSIONS.get(integration_name)
145147
if min_supported is not None:
146148
min_supported = Version(".".join(map(str, min_supported)))
147149
else:

scripts/populate_tox/tox.jinja

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,6 @@ envlist =
7777
{py3.9,py3.11,py3.12}-httpx-v{0.25,0.27}
7878
{py3.9,py3.12,py3.13}-httpx-latest
7979

80-
# Langchain
81-
{py3.9,py3.11,py3.12}-langchain-v0.1
82-
{py3.9,py3.11,py3.12}-langchain-v0.3
83-
{py3.9,py3.11,py3.12}-langchain-latest
84-
{py3.9,py3.11,py3.12}-langchain-notiktoken
85-
86-
# OpenAI
87-
{py3.9,py3.11,py3.12}-openai-v1.0
88-
{py3.9,py3.11,py3.12}-openai-v1.22
89-
{py3.9,py3.11,py3.12}-openai-v1.55
90-
{py3.9,py3.11,py3.12}-openai-latest
91-
{py3.9,py3.11,py3.12}-openai-notiktoken
92-
9380
# OpenTelemetry (OTel)
9481
{py3.7,py3.9,py3.12,py3.13}-opentelemetry
9582

@@ -238,34 +225,6 @@ deps =
238225
httpx-v0.27: httpx~=0.27.0
239226
httpx-latest: httpx
240227
241-
# Langchain
242-
langchain-v0.1: openai~=1.0.0
243-
langchain-v0.1: langchain~=0.1.11
244-
langchain-v0.1: tiktoken~=0.6.0
245-
langchain-v0.1: httpx<0.28.0
246-
langchain-v0.3: langchain~=0.3.0
247-
langchain-v0.3: langchain-community
248-
langchain-v0.3: tiktoken
249-
langchain-v0.3: openai
250-
langchain-{latest,notiktoken}: langchain
251-
langchain-{latest,notiktoken}: langchain-openai
252-
langchain-{latest,notiktoken}: openai>=1.6.1
253-
langchain-latest: tiktoken~=0.6.0
254-
255-
# OpenAI
256-
openai: pytest-asyncio
257-
openai-v1.0: openai~=1.0.0
258-
openai-v1.0: tiktoken
259-
openai-v1.0: httpx<0.28.0
260-
openai-v1.22: openai~=1.22.0
261-
openai-v1.22: tiktoken
262-
openai-v1.22: httpx<0.28.0
263-
openai-v1.55: openai~=1.55.0
264-
openai-v1.55: tiktoken
265-
openai-latest: openai
266-
openai-latest: tiktoken~=0.6.0
267-
openai-notiktoken: openai
268-
269228
# OpenTelemetry (OTel)
270229
opentelemetry: opentelemetry-distro
271230
@@ -397,11 +356,13 @@ setenv =
397356
httpx: TESTPATH=tests/integrations/httpx
398357
huey: TESTPATH=tests/integrations/huey
399358
huggingface_hub: TESTPATH=tests/integrations/huggingface_hub
400-
langchain: TESTPATH=tests/integrations/langchain
359+
langchain-base: TESTPATH=tests/integrations/langchain
360+
langchain-notiktoken: TESTPATH=tests/integrations/langchain
401361
launchdarkly: TESTPATH=tests/integrations/launchdarkly
402362
litestar: TESTPATH=tests/integrations/litestar
403363
loguru: TESTPATH=tests/integrations/loguru
404-
openai: TESTPATH=tests/integrations/openai
364+
openai-base: TESTPATH=tests/integrations/openai
365+
openai-notiktoken: TESTPATH=tests/integrations/openai
405366
openai_agents: TESTPATH=tests/integrations/openai_agents
406367
openfeature: TESTPATH=tests/integrations/openfeature
407368
opentelemetry: TESTPATH=tests/integrations/opentelemetry

scripts/split_tox_gh_actions/split_tox_gh_actions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@
6161
"AI": [
6262
"anthropic",
6363
"cohere",
64-
"langchain",
65-
"openai",
64+
"langchain-base",
65+
"langchain-notiktoken",
66+
"openai-base",
67+
"openai-notiktoken",
6668
"openai_agents",
6769
"huggingface_hub",
6870
],

sentry_sdk/integrations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def iter_default_integrations(with_auto_enabling_integrations):
147147
"graphene": (3, 3),
148148
"grpc": (1, 32, 0), # grpcio
149149
"huggingface_hub": (0, 22),
150-
"langchain": (0, 0, 210),
150+
"langchain": (0, 1, 0),
151151
"launchdarkly": (9, 8, 0),
152152
"loguru": (0, 7, 0),
153153
"openai": (1, 0, 0),

sentry_sdk/integrations/openai.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ def count_tokens(self, s):
7878
return 0
7979

8080

81-
def _capture_exception(exc):
82-
# type: (Any) -> None
81+
def _capture_exception(exc, manual_span_cleanup=True):
82+
# type: (Any, bool) -> None
8383
# Close an eventually open span
8484
# We need to do this by hand because we are not using the start_span context manager
8585
current_span = sentry_sdk.get_current_span()
86-
if current_span is not None:
86+
if manual_span_cleanup and current_span is not None:
8787
current_span.__exit__(None, None, None)
8888

8989
event, hint = event_from_exception(
@@ -516,7 +516,7 @@ def _execute_sync(f, *args, **kwargs):
516516
try:
517517
result = f(*args, **kwargs)
518518
except Exception as e:
519-
_capture_exception(e)
519+
_capture_exception(e, manual_span_cleanup=False)
520520
raise e from None
521521

522522
return gen.send(result)
@@ -550,7 +550,7 @@ async def _execute_async(f, *args, **kwargs):
550550
try:
551551
result = await f(*args, **kwargs)
552552
except Exception as e:
553-
_capture_exception(e)
553+
_capture_exception(e, manual_span_cleanup=False)
554554
raise e from None
555555

556556
return gen.send(result)

0 commit comments

Comments
 (0)