test(openai): enforce experimental embedding metric conformance - #327
test(openai): enforce experimental embedding metric conformance#327tomatotomata wants to merge 4 commits into
Conversation
Pull request dashboard statusWaiting on reviewers · refreshed 2026-08-04 14:21 UTC Review the latest changes. Status above doesn't look right?
|
| logger_provider=logger_provider, | ||
| meter_provider=meter_provider, | ||
| content_capture="SPAN_ONLY", | ||
| extra_env={ |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
The conformance scenario no longer passes an experimental-mode flag; commit c220d9d removed that plumbing so it now exercises the repository default unconditionally.
There was a problem hiding this comment.
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.nameis 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. |
| 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" | ||
| ) | ||
|
|
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
this is already covered in
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
There was a problem hiding this comment.
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.
77dbb75 to
24c9894
Compare
Run embedding conformance with the latest semantic conventions and assert both emitted metrics carry gen_ai.provider.name. Fixes open-telemetry#38
24c9894 to
b7e9ec9
Compare
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.
b7e9ec9 to
8895d2f
Compare
| point.attributes[GenAIAttributes.GEN_AI_PROVIDER_NAME] | ||
| == GenAIAttributes.GenAiProviderNameValues.OPENAI.value | ||
| ) | ||
| assert GenAIAttributes.GEN_AI_SYSTEM not in point.attributes |
There was a problem hiding this comment.
there is no need to test it. the original issue was fixed and conformance test would flag usage of deprecated attributes
| assert GenAIAttributes.GEN_AI_SYSTEM not in point.attributes |
There was a problem hiding this comment.
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.
|
I checked the current base comparison before replying. The implementation commits are already present on |
Summary
gen_ai.provider.nameon both embedding metricsFixes #38
Validation
python -m pytest instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_embedding_invocation_unit.py -q� 11 passedgit diff --checkpass