-
Notifications
You must be signed in to change notification settings - Fork 552
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% 92.60% +1.64%
==========================================
Files 171 168 -3
Lines 8133 7889 -244
Branches 1649 1621 -28
==========================================
- Hits 7398 7306 -92
+ Misses 735 583 -152
|
@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?
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.
I have a commit that re-generates the src/semconv.ts using a coming script for this (from #2669), if you are okay with me pushing to your branch, @anuraaga.
It also updates the semconv dep to ^1.29.0
because you are using semconv attributes defined in that version (GEN_AI_SYSTEM_VALUE_AWS_BEDROCK
) -- though technically because a copy (in src/semconv.ts) is being used, there isn't really the runtime dep.
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.
Thanks @trentm - feel free to push anything you need to this branch
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. |
Thank you, the changes lgtm! As for the suddenly failing unit tests, the latest commit shows 15 tests failing, but I'm pretty sure 14 of them are unrelated to your changes. I suppose there is an issue with the recently added I recall I had a similar issue when using nock for Kinesis Client, but needed to enforce NodeHttpHandler requestHandler since I found that the default handler was HTTP2 which was not supported by nock. Not sure if this issue is the same. |
Sorry @jj22ee I missed the test failures behind the known node 14 ones I need advice on. Just forgot to git add the recording will do it soon |
@anuraaga I have an idea for dealing with the node v14 test breakage. It may end up looking a little gross. I still have to write it up, and I may break it into a separate PR: a PR that (a) updates the existing |
Assuming these get in, I can resync this PR to main and add my semconv updates that I mentioned above at #2700 (comment) |
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