Skip to content

Commit 18a646c

Browse files
committed
Merge remote-tracking branch 'origin/master' into potel-base
2 parents ef1b2af + 7b028b6 commit 18a646c

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

requirements-testing.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pytest-forked
66
pytest-localserver
77
pytest-watch
88
jsonschema
9-
pyrsistent
109
executing
1110
asttokens
1211
responses

sentry_sdk/ai/monitoring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def ai_track(description: str, **span_kwargs: Any) -> Callable[..., Any]:
2828
def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
2929
def sync_wrapped(*args: Any, **kwargs: Any) -> Any:
3030
curr_pipeline = _ai_pipeline_name.get()
31-
op = span_kwargs.get("op", "ai.run" if curr_pipeline else "ai.pipeline")
31+
op = span_kwargs.pop("op", "ai.run" if curr_pipeline else "ai.pipeline")
3232

3333
with start_span(
3434
name=description, op=op, only_if_parent=True, **span_kwargs
@@ -58,7 +58,7 @@ def sync_wrapped(*args: Any, **kwargs: Any) -> Any:
5858

5959
async def async_wrapped(*args: Any, **kwargs: Any) -> Any:
6060
curr_pipeline = _ai_pipeline_name.get()
61-
op = span_kwargs.get("op", "ai.run" if curr_pipeline else "ai.pipeline")
61+
op = span_kwargs.pop("op", "ai.run" if curr_pipeline else "ai.pipeline")
6262

6363
with start_span(
6464
name=description, op=op, only_if_parent=True, **span_kwargs

sentry_sdk/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,14 @@ def serialize_frame(
551551
if tb_lineno is None:
552552
tb_lineno = frame.f_lineno
553553

554+
try:
555+
os_abs_path = os.path.abspath(abs_path) if abs_path else None
556+
except Exception:
557+
os_abs_path = None
558+
554559
rv: Dict[str, Any] = {
555560
"filename": filename_for_module(module, abs_path) or None,
556-
"abs_path": os.path.abspath(abs_path) if abs_path else None,
561+
"abs_path": os_abs_path,
557562
"function": function or "<unknown>",
558563
"module": module,
559564
"lineno": tb_lineno,

tests/test_ai_monitoring.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,44 @@ async def async_pipeline():
119119
assert ai_pipeline_span["tags"]["user"] == "czyber"
120120
assert ai_pipeline_span["data"]["some_data"] == "value"
121121
assert ai_run_span["description"] == "my async tool"
122+
123+
124+
def test_ai_track_with_explicit_op(sentry_init, capture_events):
125+
sentry_init(traces_sample_rate=1.0)
126+
events = capture_events()
127+
128+
@ai_track("my tool", op="custom.operation")
129+
def tool(**kwargs):
130+
pass
131+
132+
with sentry_sdk.start_transaction():
133+
tool()
134+
135+
transaction = events[0]
136+
assert transaction["type"] == "transaction"
137+
assert len(transaction["spans"]) == 1
138+
span = transaction["spans"][0]
139+
140+
assert span["description"] == "my tool"
141+
assert span["op"] == "custom.operation"
142+
143+
144+
@pytest.mark.asyncio
145+
async def test_ai_track_async_with_explicit_op(sentry_init, capture_events):
146+
sentry_init(traces_sample_rate=1.0)
147+
events = capture_events()
148+
149+
@ai_track("my async tool", op="custom.async.operation")
150+
async def async_tool(**kwargs):
151+
pass
152+
153+
with sentry_sdk.start_transaction():
154+
await async_tool()
155+
156+
transaction = events[0]
157+
assert transaction["type"] == "transaction"
158+
assert len(transaction["spans"]) == 1
159+
span = transaction["spans"][0]
160+
161+
assert span["description"] == "my async tool"
162+
assert span["op"] == "custom.async.operation"

0 commit comments

Comments
 (0)