MPT-20733 add trace span decorator#189
Conversation
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds a new ChangesSpan decorator feature
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
5423f95 to
dbb2ab8
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/observability/test_tracing.py (1)
98-129: ⚡ Quick winAdd a regression case for failing attribute callables.
Please add one test where an attribute callable raises (for example,
itemgetter("missing")) and assert the wrapped function still succeeds while that attribute is omitted.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/observability/test_tracing.py` around lines 98 - 129, Add a new test (e.g., test_trace_omits_failing_callable_attr) that patches decorators.TRACER using span_exporter like the other tests, then invokes the traced function (use trace_sample_async via asyncio.run or trace_sample_sync as appropriate) while supplying/arranging for one traced attribute to be a callable that will raise when invoked (example: operator.itemgetter("missing")). Assert the traced function still returns/succeeds, then locate the finished span by name (same approach as test_trace_span_wraps_async_attrs/test_trace_span_wraps_sync_function) and assert the failing attribute key is not present in span.attributes while other expected attributes remain. Ensure the test imports/uses itemgetter (or equivalent) and follows the pattern of inspecting exporter.get_finished_spans() for the span.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@mpt_extension_sdk/observability/decorators.py`:
- Around line 123-126: The loop in decorators.py currently calls
attribute_source(*args, **kwargs) directly when attribute_source is callable
(the attributes dict loop that assigns resolved_value), which can raise and
prevent the decorated function from running; update the loop to wrap each
callable invocation of attribute_source in a try/except that catches broad
exceptions (e.g., Exception), logs or records the error if needed, and continues
without adding that attribute (i.e., skip the failing key) so only the failing
attribute is dropped and tracing never blocks business execution; ensure you
reference the same attributes, attribute_source, and resolved_value symbols when
making the change.
---
Nitpick comments:
In `@tests/observability/test_tracing.py`:
- Around line 98-129: Add a new test (e.g.,
test_trace_omits_failing_callable_attr) that patches decorators.TRACER using
span_exporter like the other tests, then invokes the traced function (use
trace_sample_async via asyncio.run or trace_sample_sync as appropriate) while
supplying/arranging for one traced attribute to be a callable that will raise
when invoked (example: operator.itemgetter("missing")). Assert the traced
function still returns/succeeds, then locate the finished span by name (same
approach as
test_trace_span_wraps_async_attrs/test_trace_span_wraps_sync_function) and
assert the failing attribute key is not present in span.attributes while other
expected attributes remain. Ensure the test imports/uses itemgetter (or
equivalent) and follows the pattern of inspecting exporter.get_finished_spans()
for the span.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 89e56cc4-e84d-4198-b135-317acd7d9509
📒 Files selected for processing (3)
mpt_extension_sdk/observability/__init__.pympt_extension_sdk/observability/decorators.pytests/observability/test_tracing.py
a568a40 to
826625c
Compare
Expose trace_span from the observability package so extension code can create child spans around business operations. Cover sync and async decorated functions, including static and callable span attributes.
826625c to
cde67a9
Compare
|



🤖 AI-generated PR — Please review carefully.
Summary
trace_spanobservability decorator for extension-defined business operations.trace_spanfrommpt_extension_sdk.observabilityso extensions can import it directly.Noneattribute values before setting OpenTelemetry span attributes.Testing
make checkmake testCloses MPT-20733