def attach_to_call(active_call)
      metadata[Gruf.error_metadata_key.to_sym] = serialize if Gruf.append_server_errors_to_trailing_metadata
      return self if metadata.empty? || !active_call || !active_call.respond_to?(:output_metadata)

      # Check if we've overflown the maximum size of output metadata. If so,
      # log a warning and replace the metadata with something smaller to avoid
      # resource exhausted errors.
      if metadata.inspect.size > MAX_METADATA_SIZE
        code = METADATA_SIZE_EXCEEDED_CODE
        msg = METADATA_SIZE_EXCEEDED_MSG
        logger.warn "#{code}: #{msg} Original error: #{to_h.inspect}"
        err = Gruf::Error.new(code: :internal, app_code: code, message: msg)
        return err.attach_to_call(active_call)
      end

      active_call.output_metadata.update(metadata)
      self
    end
def attach_to_call(active_call)
      metadata[Gruf.error_metadata_key.to_sym] = serialize if Gruf.append_server_errors_to_trailing_metadata
      return self if metadata.empty? || !active_call || !active_call.respond_to?(:output_metadata)

      # Check if we've overflown the maximum size of output metadata. If so,
      # log a warning and replace the metadata with something smaller to avoid
      # resource exhausted errors.
      if metadata.inspect.size > MAX_METADATA_SIZE
        code = METADATA_SIZE_EXCEEDED_CODE
        msg = METADATA_SIZE_EXCEEDED_MSG
        logger.warn "#{code}: #{msg} Original error: #{to_h.inspect}"
        err = Gruf::Error.new(code: :internal, app_code: code, message: msg)
        return err.attach_to_call(active_call)
      end

      active_call.output_metadata.update(metadata)
      self
    end
Update the trailing metadata on the given gRPC call, including the error payload if configured
 to do so.

 @param [GRPC::ActiveCall] active_call The marshalled gRPC call
 @return [Error] Return the error itself after updating metadata on the given gRPC call.
                 In the case of a metadata overflow error, we replace the current error with
                 a new one that won't cause a low-level http2 error.