Skip to content

Bug: Go SDK OpenAI streaming drops gen_ai.response.finish_reasons #1983

Done

Description

@basil-k-aji-dev

Component

OpenLIT Go SDK (sdk/go/instrumentation/openai)

What happened?

gen_ai.response.finish_reasons is never set on OpenAI streaming spans.

The streaming client forces stream_options.include_usage = true (streaming.go, createChatCompletionStream). With that option OpenAI sends a final chunk that carries usage and an empty choices array. readStream keeps only lastChunk = &chunk and reads the finish reasons from lastChunk.Choices at the end, so it reads them from the usage chunk, which has none.

Python keeps the finish reason across chunks and reads usage separately (sdk/python/src/openlit/instrumentation/openai/utils.py, where a comment notes the usage chunk has an empty choices list).

The existing TestChatCompletion_Streaming fixture puts finish_reason and usage in the same chunk, which the real API does not do, so it does not catch this.

Steps to reproduce

Serve three SSE chunks from an httptest server: a content delta, a chunk with finish_reason: "stop", and a final chunk with choices: [] and usage. Read the stream to the end and inspect the span.

Expected

gen_ai.response.finish_reasons = ["stop"], together with the usage attributes.

Actual

Usage is recorded, gen_ai.response.finish_reasons is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions