Skip to content

test(openai): enforce experimental embedding metric conformance - #327

Open
tomatotomata wants to merge 4 commits into
open-telemetry:mainfrom
tomatotomata:codex/openai-embedding-metrics-conformance-38
Open

test(openai): enforce experimental embedding metric conformance#327
tomatotomata wants to merge 4 commits into
open-telemetry:mainfrom
tomatotomata:codex/openai-embedding-metrics-conformance-38

Conversation

@tomatotomata

@tomatotomata tomatotomata commented Jul 28, 2026

Copy link
Copy Markdown

Summary

  • run the OpenAI embedding conformance scenario explicitly in latest experimental semantic-convention mode
  • add a regression test that requires gen_ai.provider.name on both embedding metrics

Fixes #38

Validation

  • python -m pytest instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_embedding_invocation_unit.py -q � 11 passed
  • Ruff and git diff --check pass
  • The live Weaver conformance scenario is configured but cannot run locally because the Weaver binary is not installed; CI conformance will execute it.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 28, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-08-04 14:21 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@tomatotomata
tomatotomata marked this pull request as ready for review July 28, 2026 15:37
@tomatotomata
tomatotomata requested a review from a team as a code owner July 28, 2026 15:37
logger_provider=logger_provider,
meter_provider=meter_provider,
content_capture="SPAN_ONLY",
extra_env={

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should not be necessary in this repo - we should have removed this flag here. If there are some leftovers that require it, could you please send a PR to switch to latest experimental by default and unconditionally ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The conformance scenario no longer passes an experimental-mode flag; commit c220d9d removed that plumbing so it now exercises the repository default unconditionally.

Copilot AI review requested due to automatic review settings July 29, 2026 04:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 strengthens the OpenAI embeddings instrumentation test suite to prevent metric semantic-convention regressions, and records the fix in the package changelog fragment.

Changes:

  • Adds a unit regression test asserting gen_ai.provider.name is present on the two emitted embedding metrics.
  • Adds a towncrier fragment documenting the conformance/metric attribute guard.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_embedding_invocation_unit.py Adds a regression test around embedding metric attributes for gen_ai.provider.name.
instrumentation/opentelemetry-instrumentation-genai-openai/.changelog/38.fixed Documents the user-visible fix/regression guard.

Comment on lines +151 to +175
metrics = metric_reader.get_metrics_data()
metric_names = {
metric.name
for resource_metric in metrics.resource_metrics
for scope_metric in resource_metric.scope_metrics
for metric in scope_metric.metrics
}
assert {
"gen_ai.client.operation.duration",
"gen_ai.client.token.usage",
} <= metric_names

for resource_metric in metrics.resource_metrics:
for scope_metric in resource_metric.scope_metrics:
for metric in scope_metric.metrics:
if metric.name in {
"gen_ai.client.operation.duration",
"gen_ai.client.token.usage",
}:
for point in metric.data.data_points:
assert (
point.attributes["gen_ai.provider.name"]
== "openai"
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Implemented in 8895d2f: the regression now lives in the existing embedding integration test, selects the duration and token metrics explicitly, requires data points, uses GenAIAttributes constants/enums, asserts gen_ai.provider.name == OPENAI, and verifies the deprecated gen_ai.system attribute is absent.

invocation.stop()


def test_embedding_metrics_use_provider_name_attribute(handler, metric_reader):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is already covered in

duration_point.attributes[GenAI.GEN_AI_PROVIDER_NAME], "embed-prov"

if the goal is to test all openai instrumentation e2e consider adding missing attributes in existing tests https://github.com/ahmadalguydi/opentelemetry-python-genai/blob/77dbb757b64025a90db5841eb6e79e8513c19be9/instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_embeddings.py

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Moved the regression out of the unit test and into test_embeddings_token_metrics in test_embeddings.py, so it covers the end-to-end OpenAI instrumentation path. The test now checks both emitted metrics and their data points, including the provider attribute and absence of the deprecated system key.

@tomatotomata
tomatotomata force-pushed the codex/openai-embedding-metrics-conformance-38 branch from 77dbb75 to 24c9894 Compare July 29, 2026 04:23
Run embedding conformance with the latest semantic conventions and assert both emitted metrics carry gen_ai.provider.name.

Fixes open-telemetry#38
@tomatotomata
tomatotomata force-pushed the codex/openai-embedding-metrics-conformance-38 branch from 24c9894 to b7e9ec9 Compare July 29, 2026 04:59
Remove the scenario-local stability opt-in so the conformance test follows the repository-wide experimental semantic convention default.
Move the provider-name regression into the existing embedding integration test. Check both expected metrics explicitly, require data points, and reject the deprecated provider attribute.
point.attributes[GenAIAttributes.GEN_AI_PROVIDER_NAME]
== GenAIAttributes.GenAiProviderNameValues.OPENAI.value
)
assert GenAIAttributes.GEN_AI_SYSTEM not in point.attributes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there is no need to test it. the original issue was fixed and conformance test would flag usage of deprecated attributes

Suggested change
assert GenAIAttributes.GEN_AI_SYSTEM not in point.attributes

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed the redundant assertions in 488c735. The existing conformance coverage remains the guard for deprecated attributes. The affected test_embeddings_token_metrics test passes locally, along with Ruff, formatting, and git diff --check.

@lmolkova lmolkova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this PR is empty

@tomatotomata

Copy link
Copy Markdown
Author

I checked the current base comparison before replying. The implementation commits are already present on main, so this PR now contains only the changelog fragment. I was thinking the cleanest path is to treat it as superseded rather than add another no-op commit. If the fragment is still wanted separately, I can keep it here; otherwise I’ll close this stale remainder.

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.

OpenAI instrumentation: embedding instrumentation metrics conformance

3 participants