-
Notifications
You must be signed in to change notification settings - Fork 872
fix(bedrock): add error logging to instrumented functions #3623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Adds try/except blocks to record exceptions in spans for all four instrumented functions: - _instrumented_model_invoke - _instrumented_model_invoke_with_response_stream - _instrumented_converse - _instrumented_converse_stream When an exception occurs, the span now: - Sets ERROR_TYPE attribute with the exception class name - Records the exception details via span.record_exception() - Sets span status to ERROR with the exception message - Increments the exception counter metric This follows the OTel error recording pattern per: https://opentelemetry.io/docs/languages/python/instrumentation/#record-exceptions-in-spans Partial fix for traceloop#412
📝 WalkthroughWalkthroughThis change adds comprehensive error handling and metrics recording to Bedrock instrumentation wrappers. For each API call path (invoke, invoke stream, converse, converse stream), exceptions are caught, spans are annotated with error types, span status is set to ERROR, exception counters are incremented, and exceptions are re-raised. New imports for Status, StatusCode, and ERROR_TYPE were added. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed everything up to 9685686 in 1 minute and 0 seconds. Click for details.
- Reviewed
96lines of code in1files - Skipped
0files when reviewing. - Skipped posting
4draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py:207
- Draft comment:
Good use of try/except in _instrumented_model_invoke to record exceptions on the span. The error attributes and metric update look correct. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
2. packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py:236
- Draft comment:
The _instrumented_model_invoke_with_response_stream correctly calls span.end() on exception and updates the counter; this aligns with non-context span usage. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
3. packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py:268
- Draft comment:
Exception handling in _instrumented_converse properly records errors, sets span status, and updates metrics in line with OTel guidelines. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
4. packages/opentelemetry-instrumentation-bedrock/opentelemetry/instrumentation/bedrock/__init__.py:295
- Draft comment:
In _instrumented_converse_stream, the try/except properly ends the span on error and updates metrics, which is consistent with other implementations. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
Workflow ID: wflow_s6DpVBM1bjVYIxGt
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
|
recheck |
Summary
Adds error logging to all four instrumented Bedrock functions so exceptions are properly recorded in spans.
Changes:
_instrumented_model_invoke- wrap call in try/except_instrumented_model_invoke_with_response_stream- wrap call in try/except_instrumented_converse- wrap call in try/except_instrumented_converse_stream- wrap call in try/exceptWhen an error occurs, each function now:
error.typeattribute with the exception class namespan.record_exception(e)ERRORWhy
Per the OTel spec for recording exceptions in spans, errors should be captured so they're visible in traces.
Testing
Partial fix for #412
Important
Add error logging to instrumented Bedrock functions to capture exceptions in spans.
_instrumented_model_invoke,_instrumented_model_invoke_with_response_stream,_instrumented_converse,_instrumented_converse_stream.error.typeattribute, record exception, set span status toERROR, increment exception counter.This description was created by
for 9685686. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.