Skip to content

Conversation

@drewby
Copy link
Member

@drewby drewby commented May 4, 2025

Description

This PR adds instrumentation for OpenAI's embeddings API in the GenAI instrumentation suite. The implementation follows the OpenTelemetry semantic conventions for generative AI systems and provides automatic instrumentation for the OpenAI Python client when using embeddings functionality.

The implementation captures important metadata about embedding operations including model, dimensions, and relevant timing information while respecting sensitive data handling practices.

  • Added instrumentation for both synchronous and asynchronous OpenAI embedding API calls
  • Implemented span and metrics using existing attributes, with two new custom:
    • ai.embedding.dimensions - Number of dimensions in the embedding vectors
    • ai.embedding.encoding_format - The encoding format of the embedding vectors response (base64 or float)
  • Capturing input text content (disabled by default for privacy)
  • Added a usage example called embeddings

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Unit tests using mock responses to verify proper span creation and attribute population
  • Integration tests with the OpenAI client against a mock server
  • Manual testing using examples/embeddings with real OpenAI service

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link
Member

@lmolkova lmolkova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!!!

@xrmx xrmx self-requested a review September 10, 2025 16:19
@drewby
Copy link
Member Author

drewby commented Sep 12, 2025

@pmcollins @xrmx @lmolkova Thank You! I'm working on it and wil have updates soon.

@drewby
Copy link
Member Author

drewby commented Sep 22, 2025

@xrmx @lmolkova I've made several updates based on the feedback. I hope I addressed most concerns. There is one check not passing but seems unrelated to openai library.

@aabmass
Copy link
Member

aabmass commented Oct 7, 2025

@xrmx can you take another pass?

@lmolkova lmolkova requested review from Copilot and removed request for alizenhom and gyliu513 October 14, 2025 16:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive instrumentation for OpenAI's embeddings API to the existing OpenTelemetry instrumentation suite. The implementation provides automatic tracing and metrics collection for both synchronous and asynchronous embedding operations following OpenTelemetry semantic conventions.

  • Adds support for tracing OpenAI embeddings API calls with proper span attributes and metrics
  • Introduces new custom attributes for embedding-specific metadata (dimensions and encoding format)
  • Includes comprehensive test coverage with both unit and integration tests

Reviewed Changes

Copilot reviewed 26 out of 28 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/opentelemetry/instrumentation/openai_v2/__init__.py Adds instrumentation hooks for embeddings endpoints
src/opentelemetry/instrumentation/openai_v2/patch.py Implements tracing logic for sync/async embeddings operations
src/opentelemetry/instrumentation/openai_v2/utils.py Adds embeddings-specific request attribute handling
tests/test_embeddings.py Comprehensive test suite for synchronous embeddings API
tests/test_async_embeddings.py Test coverage for asynchronous embeddings functionality
tests/test_utils.py Shared test utilities for consistent assertion patterns

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments but LGTM.

@xrmx
Copy link
Contributor

xrmx commented Oct 16, 2025

Also I would ignore copilot comments.

Copy link
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this and do other changes as followups.

@xrmx xrmx requested a review from lmolkova November 5, 2025 08:36
@xrmx xrmx merged commit fecd8af into open-telemetry:main Nov 6, 2025
647 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.