Add instrumentation for RubyLLM::Embedding.embed#17
Merged
clarissalimab merged 1 commit intoApr 10, 2026
Conversation
Contributor
|
Thanks for this contribution! Now that #16 has been merged, could you rebase this branch onto main? There will be a conflict in the test file that needs resolving. |
Instrument the embeddings endpoint following the OpenTelemetry GenAI semantic conventions for embedding spans. The patch is applied via singleton_class.prepend on RubyLLM::Embedding, wrapping the class-level embed method with a CLIENT span. Span attributes: - gen_ai.operation.name: "embeddings" - gen_ai.provider.name: resolved provider (e.g. "openai") - gen_ai.request.model / gen_ai.response.model: model identifiers - gen_ai.usage.input_tokens: token count from the response - gen_ai.embeddings.dimension.count: length of the embedding vector - error.type: exception class on API failures Error handling follows the same pattern as Chat instrumentation: API errors are recorded on the span and re-raised, while instrumentation failures are swallowed to avoid breaking the underlying embed call. Tests cover span creation with all attributes, error recording on API failure, and resilience when instrumentation itself fails. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
20620eb to
47928cc
Compare
Contributor
Author
|
@clarissalimab I rebased, but didn't have a conflict. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Instrument the embeddings endpoint following the OpenTelemetry GenAI semantic conventions for embedding spans. The patch is applied via singleton_class.prepend on RubyLLM::Embedding, wrapping the class-level embed method with a CLIENT span.
Span attributes:
Error handling follows the same pattern as Chat instrumentation: API errors are recorded on the span and re-raised, while instrumentation failures are swallowed to avoid breaking the underlying embed call.
Tests cover span creation with all attributes, error recording on API failure, and resilience when instrumentation itself fails.