Skip to content

Add instrumentation for RubyLLM::Embedding.embed#17

Merged
clarissalimab merged 1 commit into
thoughtbot:mainfrom
mitigate-dev:feature/support-embeddings
Apr 10, 2026
Merged

Add instrumentation for RubyLLM::Embedding.embed#17
clarissalimab merged 1 commit into
thoughtbot:mainfrom
mitigate-dev:feature/support-embeddings

Conversation

@ebeigarts
Copy link
Copy Markdown
Contributor

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.

Screenshot 2026-03-26 at 12 41 36

@clarissalimab
Copy link
Copy Markdown
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>
@ebeigarts ebeigarts force-pushed the feature/support-embeddings branch from 20620eb to 47928cc Compare April 10, 2026 15:30
@ebeigarts
Copy link
Copy Markdown
Contributor Author

@clarissalimab I rebased, but didn't have a conflict.

@clarissalimab clarissalimab merged commit cac521f into thoughtbot:main Apr 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants