Bug Report:OpenAI instrumentation does not record gen_ai.request.seed, gen_ai.request.stop_sequences or gen_ai.output.type
Which component is this bug for?
OpenAI Instrumentation
Description
For chat completions, the OpenAI instrumentation records sampling parameters such as gen_ai.request.temperature, but does not record three request attributes defined by the OpenTelemetry GenAI semantic conventions, even when the request sets them:
| Request parameter | Semconv attribute | Requirement level | Recorded? |
|---|---|---|---|
seed |
gen_ai.request.seed |
Conditionally Required (if set) | no |
response_format |
gen_ai.output.type |
Conditionally Required (if set) | no |
stop |
gen_ai.request.stop_sequences |
Recommended | no |
No other attribute carries these values either, so they are lost from the trace.
Impact: these parameters change model output (determinism, output format, where generation stops). Traces used for debugging, replay ("open in playground") or building eval datasets cannot reproduce such requests; e.g. a replayed response_format request returns free text instead of JSON.
For comparison, opentelemetry-instrumentation-genai-openai records all three (gen_ai.output.type = "json" for a json_schema response format).
Reproduction steps
Self-contained (mock HTTP transport, no API key):
import json, httpx, openai
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
exporter = InMemorySpanExporter()
provider = TracerProvider(); provider.add_span_processor(SimpleSpanProcessor(exporter))
OpenAIInstrumentor().instrument(tracer_provider=provider)
def handler(request):
return httpx.Response(200, json={"id": "c1", "object": "chat.completion", "created": 0, "model": "m",
"choices": [{"index": 0, "finish_reason": "stop", "message": {"role": "assistant", "content": "{}"}}],
"usage": {"prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2}})
client = openai.OpenAI(api_key="x", base_url="http://mock/v1",
http_client=httpx.Client(transport=httpx.MockTransport(handler)))
client.chat.completions.create(
model="m", messages=[{"role": "user", "content": "hi"}],
seed=4242, stop=["ZZSTOP"],
response_format={"type": "json_schema", "json_schema": {"name": "S", "schema": {"type": "object"}}},
temperature=0.37,
)
a = exporter.get_finished_spans()[0].attributes
for k in ["gen_ai.request.seed", "gen_ai.request.stop_sequences", "gen_ai.output.type", "gen_ai.request.temperature"]:
print(f"{k:32s} = {a.get(k)}")
print("any attribute mentioning seed/stop/output:",
{k: v for k, v in a.items() if any(w in k for w in ("seed", "stop", "output.type", "response_format"))})Expected behavior
gen_ai.request.seed = 4242
gen_ai.request.stop_sequences = ('ZZSTOP',)
gen_ai.output.type = json
gen_ai.request.temperature = 0.37Actual Behavior with Screenshots
Same on 0.62.4 and on current main:
gen_ai.request.seed = None
gen_ai.request.stop_sequences = None
gen_ai.output.type = None
gen_ai.request.temperature = 0.37
any attribute mentioning seed/stop/output: {}Python Version
3.12
Provide any additional context for the Bug.
- opentelemetry-instrumentation-openai 0.62.4 and current
main; openai 2.54.0; opentelemetry-sdk 1.45.0; Ubuntu 24.04. - Semantic conventions reference: GenAI spans, v1.41.0 (
gen_ai.request.seedandgen_ai.output.typeConditionally Required;gen_ai.request.stop_sequencesRecommended). - For comparison,
opentelemetry-instrumentation-genai-openai1.2b0 on the same script:
gen_ai.request.seed = 4242
gen_ai.request.stop_sequences = ('ZZSTOP',)
gen_ai.output.type = json
gen_ai.request.temperature = 0.37Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
Are you willing to submit PR?
Yes I am willing to submit a PR!
Source: traceloop/openllmetry