Skip to content

Commit a0ffa84

Browse files
committed
Merge branch 'py-2071-get-driver-type-from-broker-url' of github.com:getsentry/sentry-python into py-2071-get-driver-type-from-broker-url
2 parents cfc0a1d + da73f25 commit a0ffa84

16 files changed

Lines changed: 263 additions & 192 deletions

File tree

.craft.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
minVersion: 2.17.0
1+
minVersion: 2.21.1
2+
preReleaseCommand: bash scripts/bump-version.sh
23
targets:
34
- name: pypi
45
includeNames: /^sentry[_\-]sdk.*$/
@@ -30,5 +31,12 @@ targets:
3031
license: MIT
3132
- name: sentry-pypi
3233
internalPypiRepo: getsentry/pypi
33-
changelog: CHANGELOG.md
34-
changelogPolicy: auto
34+
artifactProvider:
35+
name: github
36+
config:
37+
artifacts:
38+
CI:
39+
- 'artifact-*'
40+
changelog:
41+
filePath: CHANGELOG.md
42+
policy: auto

.github/release.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,37 @@ changelog:
55
authors:
66
- dependabot
77
categories:
8+
- title: Breaking Changes 🛠
9+
commit_patterns:
10+
- "^(?<type>\\w+(?:\\((?<scope>[^)]+)\\))?!:\\s*)"
11+
semver: major
812
- title: New Features ✨
913
labels:
1014
- "Changelog: Feature"
1115
commit_patterns:
12-
- "^feat\\b"
16+
- "^(?<type>feat(?:\\((?<scope>[^)]+)\\))?!?:\\s*)"
1317
semver: minor
1418
- title: Bug Fixes 🐛
1519
labels:
1620
- "Changelog: Bugfix"
1721
commit_patterns:
18-
- "^(fix|bugfix)\\b"
22+
- "^(?<type>(?:fix|bugfix)(?:\\((?<scope>[^)]+)\\))?!?:\\s*)"
1923
semver: patch
2024
- title: Deprecations 🏗️
2125
labels:
2226
- "Changelog: Deprecation"
2327
commit_patterns:
24-
- "deprecat" # deprecation, deprecated
28+
- "^(?<type>deprecat(?:ion|ed|e)(?:\\((?<scope>[^)]+)\\))?!?:?\\s*)"
2529
semver: patch
2630
- title: Documentation 📚
2731
labels:
2832
- "Changelog: Docs"
2933
commit_patterns:
30-
- "^docs?\\b"
34+
- "^(?<type>docs?(?:\\((?<scope>[^)]+)\\))?!?:\\s*)"
3135
semver: patch
3236
- title: Internal Changes 🔧
3337
labels:
3438
- "Changelog: Internal"
3539
commit_patterns:
36-
- "^(build|ref|chore|ci|tests?)\\b"
40+
- "^(?<type>(?:build|refactor|meta|chore|ci|ref|perf|tests?)(?:\\((?<scope>[^)]+)\\))?!?:\\s*)"
3741
semver: patch

.github/workflows/ci.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ jobs:
6161
path: |
6262
dist/*
6363
if-no-files-found: 'error'
64-
# since this artifact will be merged, compression is not necessary
65-
compression-level: '0'
6664

6765
docs:
6866
name: Build SDK API Doc
@@ -85,17 +83,3 @@ jobs:
8583
path: |
8684
docs/_build/gh-pages.zip
8785
if-no-files-found: 'error'
88-
# since this artifact will be merged, compression is not necessary
89-
compression-level: '0'
90-
91-
merge:
92-
name: Create Release Artifact
93-
runs-on: ubuntu-latest
94-
needs: [build_lambda_layer, docs]
95-
steps:
96-
- uses: actions/upload-artifact/merge@v6
97-
with:
98-
# Craft expects release assets from github to be a single artifact named after the sha.
99-
name: ${{ github.sha }}
100-
pattern: artifact-*
101-
delete-merged: true

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
python-version: ${{ matrix.python-version }}
6767
allow-prereleases: true
6868
- name: "Setup ClickHouse Server"
69-
uses: getsentry/action-clickhouse-in-ci@v1.6
69+
uses: getsentry/action-clickhouse-in-ci@v1.7
7070
- name: Setup Test Env
7171
run: |
7272
pip install "coverage[toml]" tox

scripts/bump-version.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ fi
99
SCRIPT_DIR="$( dirname "$0" )"
1010
cd $SCRIPT_DIR/..
1111

12-
OLD_VERSION="${1}"
13-
NEW_VERSION="${2}"
14-
15-
echo "Current version: $OLD_VERSION"
16-
echo "Bumping version: $NEW_VERSION"
12+
echo "Current version: $CRAFT_OLD_VERSION"
13+
echo "Bumping version: $CRAFT_NEW_VERSION"
1714

1815
function replace() {
1916
! grep "$2" $3
2017
perl -i -pe "s/$1/$2/g" $3
2118
grep "$2" $3 # verify that replacement was successful
2219
}
2320

24-
replace "version=\"$OLD_VERSION\"" "version=\"$NEW_VERSION\"" ./setup.py
25-
replace "VERSION = \"$OLD_VERSION\"" "VERSION = \"$NEW_VERSION\"" ./sentry_sdk/consts.py
26-
replace "release = \"$OLD_VERSION\"" "release = \"$NEW_VERSION\"" ./docs/conf.py
21+
replace "version=\"$CRAFT_OLD_VERSION\"" "version=\"$CRAFT_NEW_VERSION\"" ./setup.py
22+
replace "VERSION = \"$CRAFT_OLD_VERSION\"" "VERSION = \"$CRAFT_NEW_VERSION\"" ./sentry_sdk/consts.py
23+
replace "release = \"$CRAFT_OLD_VERSION\"" "release = \"$CRAFT_NEW_VERSION\"" ./docs/conf.py

scripts/populate_tox/package_dependencies.jsonl

Lines changed: 11 additions & 10 deletions
Large diffs are not rendered by default.

scripts/populate_tox/releases.jsonl

Lines changed: 26 additions & 23 deletions
Large diffs are not rendered by default.

scripts/populate_tox/tox.jinja

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ deps =
112112
113113
# AWS Lambda
114114
aws_lambda: aws-cdk-lib
115-
aws_lambda: aws-sam-cli
116115
aws_lambda: boto3
117116
aws_lambda: fastapi
118117
aws_lambda: requests

scripts/split_tox_gh_actions/templates/test_group.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
{% if needs_clickhouse %}
5353
- name: "Setup ClickHouse Server"
54-
uses: getsentry/action-clickhouse-in-ci@v1.6
54+
uses: getsentry/action-clickhouse-in-ci@v1.7
5555
{% endif %}
5656

5757
{% if needs_redis %}

sentry_sdk/integrations/openai_agents/__init__.py

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from sentry_sdk.integrations import DidNotEnable, Integration
2+
from sentry_sdk.utils import parse_version
3+
4+
from functools import wraps
25

36
from .patches import (
47
_create_get_model_wrapper,
5-
_create_get_all_tools_wrapper,
8+
_get_all_tools,
69
_create_run_wrapper,
710
_create_run_streamed_wrapper,
811
_patch_agent_run,
@@ -17,11 +20,21 @@
1720
# after it, even if we don't use it.
1821
import agents
1922
from agents.run import DEFAULT_AGENT_RUNNER
23+
from agents.run import AgentRunner
24+
from agents.version import __version__ as OPENAI_AGENTS_VERSION
2025

2126
except ImportError:
2227
raise DidNotEnable("OpenAI Agents not installed")
2328

2429

30+
try:
31+
# AgentRunner methods moved in v0.8
32+
# https://github.com/openai/openai-agents-python/commit/3ce7c24d349b77bb750062b7e0e856d9ff48a5d5#diff-7470b3a5c5cbe2fcbb2703dc24f326f45a5819d853be2b1f395d122d278cd911
33+
from agents.run_internal import run_loop
34+
except ImportError:
35+
run_loop = None
36+
37+
2538
def _patch_runner() -> None:
2639
# Create the root span for one full agent run (including eventual handoffs)
2740
# Note agents.run.DEFAULT_AGENT_RUNNER.run_sync is a wrapper around
@@ -45,18 +58,67 @@ def _patch_model() -> None:
4558
)
4659

4760

48-
def _patch_tools() -> None:
49-
agents.run.AgentRunner._get_all_tools = classmethod(
50-
_create_get_all_tools_wrapper(agents.run.AgentRunner._get_all_tools),
51-
)
61+
class OpenAIAgentsIntegration(Integration):
62+
"""
63+
NOTE: With version 0.8.0, the class methods below have been refactored to functions.
64+
- `AgentRunner._get_model()` -> `agents.run_internal.turn_preparation.get_model()`
65+
- `AgentRunner._get_all_tools()` -> `agents.run_internal.turn_preparation.get_all_tools()`
66+
- `AgentRunner._run_single_turn()` -> `agents.run_internal.run_loop.run_single_turn()`
67+
- `RunImpl.execute_handoffs()` -> `agents.run_internal.turn_resolution.execute_handoffs()`
68+
- `RunImpl.execute_final_output()` -> `agents.run_internal.turn_resolution.execute_final_output()`
5269
70+
Typical interaction with the library:
71+
1. The user creates an Agent instance with configuration, including system instructions sent to every Responses API call.
72+
2. The user passes the agent instance to a Runner with `run()` and `run_streamed()` methods. The latter can be used to incrementally receive progress.
73+
- `Runner.run()` and `Runner.run_streamed()` are thin wrappers for `DEFAULT_AGENT_RUNNER.run()` and `DEFAULT_AGENT_RUNNER.run_streamed()`.
74+
- `DEFAULT_AGENT_RUNNER.run()` and `DEFAULT_AGENT_RUNNER.run_streamed()` are patched in `_patch_runner()` with `_create_run_wrapper()` and `_create_run_streamed_wrapper()`, respectively.
75+
3. In a loop, the agent repeatedly calls the Responses API, maintaining a conversation history that includes previous messages and tool results, which is passed to each call.
76+
- A Model instance is created at the start of the loop by calling the `Runner._get_model()`. We patch the Model instance using `_create_get_model_wrapper()` in `_patch_model()`.
77+
- Available tools are also deteremined at the start of the loop, with `Runner._get_all_tools()`. We patch Tool instances by iterating through the returned tools in `patches._get_all_tools()`.
78+
- In each loop iteration, `run_single_turn()` or `run_single_turn_streamed()` is responsible for calling the Responses API, patched with `patched_run_single_turn()` and `patched_run_single_turn_streamed()`.
79+
4. On loop termination, `RunImpl.execute_final_output()` is called. The function is patched with `patched_execute_final_output()`.
80+
81+
Local tools are run based on the return value from the Responses API as a post-API call step in the above loop.
82+
Hosted MCP Tools are run as part of the Responses API call, and involve OpenAI reaching out to an external MCP server.
83+
An agent can handoff to another agent, also directed by the return value of the Responses API and run post-API call in the loop.
84+
Handoffs are a way to switch agent-wide configuration.
85+
- Handoffs are executed by calling `RunImpl.execute_handoffs()`. The method is patched in `patched_execute_handoffs()`
86+
"""
5387

54-
class OpenAIAgentsIntegration(Integration):
5588
identifier = "openai_agents"
5689

5790
@staticmethod
5891
def setup_once() -> None:
5992
_patch_error_tracing()
60-
_patch_tools()
6193
_patch_model()
6294
_patch_runner()
95+
96+
library_version = parse_version(OPENAI_AGENTS_VERSION)
97+
if library_version is not None and library_version >= (
98+
0,
99+
8,
100+
):
101+
102+
@wraps(run_loop.get_all_tools)
103+
async def new_wrapped_get_all_tools(
104+
agent: "agents.Agent",
105+
context_wrapper: "agents.RunContextWrapper",
106+
) -> "list[agents.Tool]":
107+
return await _get_all_tools(
108+
run_loop.get_all_tools, agent, context_wrapper
109+
)
110+
111+
agents.run.get_all_tools = new_wrapped_get_all_tools
112+
return
113+
114+
original_get_all_tools = AgentRunner._get_all_tools
115+
116+
@wraps(AgentRunner._get_all_tools.__func__)
117+
async def old_wrapped_get_all_tools(
118+
cls: "agents.Runner",
119+
agent: "agents.Agent",
120+
context_wrapper: "agents.RunContextWrapper",
121+
) -> "list[agents.Tool]":
122+
return await _get_all_tools(original_get_all_tools, agent, context_wrapper)
123+
124+
agents.run.AgentRunner._get_all_tools = classmethod(old_wrapped_get_all_tools)

0 commit comments

Comments
 (0)