function instrumentStream({ langchain, shim }) {
  shim.record(
    langchain.RunnableSequence.prototype,
    'stream',
    function wrapStream(shim, _stream, fnName, args) {
      const [request, params] = args
      const metadata = params?.metadata ?? {}
      const tags = params?.tags ?? []

      return new RecorderSpec({
        name: `${LANGCHAIN.CHAIN}/${fnName}`,
        promise: true,
        after({ error: err, result: output, segment, transaction }) {
          // Input error occurred which means a stream was not created.
          // Skip instrumenting streaming and create Llm Events from
          // the data we have
          if (output?.next) {
            wrapNextHandler({ shim, output, segment, request, metadata, tags, transaction })
          } else {
            recordChatCompletionEvents({
              transaction,
              segment,
              messages: [],
              events: [request],
              metadata,
              tags,
              err,
              shim
            })
          }
        }
      })
    }
  )
}
Instruments and records span and relevant LLM events for `chain.stream`

@param {object} params function params
@param {object} params.langchain `@langchain/core/runnables/base` export
@param {Shim} params.shim instace of shim