Skip to content

Bug: Go SDK OpenAI and Anthropic streaming failures end the span before recording the error #1982

Open

Description

@basil-k-aji-dev

Component

OpenLIT Go SDK (sdk/go, OpenAI and Anthropic instrumentation)

What happened?

When a streaming request fails before any chunk is read (marshal error, request-creation error, transport error, or a non-200 response), the span is ended first and the error is recorded afterwards:

span.End()
helpers.RecordError(span, err)

RecordError and SetStatus on an ended span are ignored by the OpenTelemetry SDK, so the span of a failed streaming call finishes with status Unset and no exception event. This is in sdk/go/instrumentation/openai/streaming.go (the four failure paths in createChatCompletionStream) and sdk/go/instrumentation/anthropic/streaming.go (the same four paths). The vllm instrumentation in the same SDK uses the right order (helpers.RecordError(span, err) then span.End(), vllm/streaming.go).

Steps to reproduce

Point either client at an httptest server that answers the streaming request with 401, call the streaming method with an in-memory span recorder, and inspect the ended span.

Expected

Status Error and one exception event on the span, like a failed non-streaming call.

Actual

Status Unset and no events, so a failed streaming call looks like one that did not fail.

Activity

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