Skip to main content

Overview

This example uses InferenceRuntime with streaming enabled and shows the Langfuse connection inline while sending the full LLM and HTTP lifecycle — including the complete response body — to Langfuse. For streaming responses the HTTP span stays open while chunks arrive and closes only when the stream is exhausted (HttpStreamCompleted). By enabling captureStreamingChunks: true each SSE chunk is also recorded as a log event under the http.client.request span, which is useful for debugging but should be left off in production. Key concepts:
  • explicit LangfuseConfig / LangfuseHttpTransport / LangfuseExporter setup
  • withStreaming(): requests a server-sent-events stream from the LLM provider
  • HttpClientTelemetryProjector($hub, captureStreamingChunks: true): records each chunk and closes the HTTP span with the full body on stream completion
  • HttpStreamCompleted: new event fired when the stream generator is exhausted
  • Telemetry::flush(): must be called after the stream is consumed

Example