-
Notifications
You must be signed in to change notification settings - Fork 549
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
feat(instrumentation-aws-sdk): add bedrock extension to apply gen ai conventions #2700
base: main
Are you sure you want to change the base?
Conversation
Hi @AmanAgarwal041 - just wanted to share this PR adding gen ai instrumentation of bedrock. Notably, for tests it takes a pattern of recording real LLM responses using nock back, which I see most gen ai instrumentation outside of opentelemetry taking due to the complexity of the models. It may be a good approach for #2402 (if you need help with that PR, let me know). Cheers. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2700 +/- ##
==========================================
+ Coverage 90.96% 91.05% +0.09%
==========================================
Files 171 168 -3
Lines 8133 7880 -253
Branches 1649 1623 -26
==========================================
- Hits 7398 7175 -223
+ Misses 735 705 -30
|
@trentm Oh I remembered now that the latest version of the AWS SDK doesn't support Node 14, which is causing the unit tests to fail after anuraaga#1 (comment). Let me know what's a good way forward, I think either dropping Node 14 support for this package (not sure it's allowed) or downgrading again. |
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.
Surprisingly concise change to add the toehold here. I know there's more to do, but good work!
Hi @anuraaga, thanks for this. Just to let you know, the ADOT team from AWS also had vested interest in Gen AI support in AWS SDK instrumentation, and planning to contribute in the future as well. There are Bedrock Service Extension implementations in multiple languages in the ADOT's downstream of the auto-instrumentations (JS, Python), which are similar but might not be fully 1:1 with your changes. I was wondering if you could also consider ADOT's implementations in this PR? I'll also spend time to compare the 2 implementations for any subtle differences. |
@jj22ee drive-by comment, but one thing to give heads up about is that the toehold here is based on the latest genai semantic conventions, and I don't expect this to want to do too much in one PR. So, one thing to think about is what happens in this PR vs a follow-up to add more features or things that are defined beyond the otel specs. Doing it like that might result in the same or similar end, but faster vs trying to do too much in the first of many PRs. food for thought! https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-spans.md |
Thanks for the heads up @codefromthecrypt. I agree to start smaller. Just wanted to ensure there are no conflicts, but the latest Gen AI conventions will take priority, so I have no issue with that. |
const { inputTokens, outputTokens } = usage; | ||
if (inputTokens !== undefined) { | ||
span.setAttribute(ATTR_GEN_AI_USAGE_INPUT_TOKENS, inputTokens); | ||
} | ||
if (outputTokens !== undefined) { | ||
span.setAttribute(ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens); | ||
} |
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.
In case usage
is undefined:
const { inputTokens, outputTokens } = usage; | |
if (inputTokens !== undefined) { | |
span.setAttribute(ATTR_GEN_AI_USAGE_INPUT_TOKENS, inputTokens); | |
} | |
if (outputTokens !== undefined) { | |
span.setAttribute(ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens); | |
} | |
if (usage) { | |
const { inputTokens, outputTokens } = usage; | |
if (inputTokens !== undefined) { | |
span.setAttribute(ATTR_GEN_AI_USAGE_INPUT_TOKENS, inputTokens); | |
} | |
if (outputTokens !== undefined) { | |
span.setAttribute(ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens); | |
} | |
} |
* limitations under the License. | ||
*/ | ||
|
||
// Gen AI conventions |
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.
Can you also help copy over comments for the copied ATTR_*
attribute keys from the semantic-conventions?
nice work! looks good for the most part. |
Thanks @jj22ee - I think the implementation pattern itself is similar/same as almost all the work is done by the service extension anyways. Technically there isn't any overlap yet since AFAIU, ADOT currently only instruments The bigger difference is the test infrastructure using nock-back, which we also adopted in upstream python so I think if we get this in for the initial infrastructure we'll be able to smoothly add more features over subsequent PRs by only focusing on business logic instead of build infra. |
Which problem is this PR solving?
Short description of the changes
Converse
with span attributes. Future PRs will add other bedrock APIs and other gen AI conventions such as events and metrics/cc @trentm @codefromthecrypt