| 313 | } |
| 314 | |
| 315 | const onRequest = (rpc: Rpc.AnyWithProps) => { |
| 316 | const isStream = RpcSchema.isStreamSchema(rpc.successSchema) |
| 317 | const middleware = getRpcClientMiddleware(rpc) |
| 318 | const tracing = Context.get(rpc.annotations, Rpc.TracingEnabled) |
| 319 | const createSpan = !disableTracing && (tracing === "both" || tracing === "client") |
| 320 | return (payload: any, opts?: { |
| 321 | readonly asQueue?: boolean | undefined |
| 322 | readonly streamBufferSize?: number | undefined |
| 323 | readonly headers?: Headers.Input | undefined |
| 324 | readonly context?: Context.Context<never> | undefined |
| 325 | readonly discard?: boolean | undefined |
| 326 | }) => { |
| 327 | const headers = opts?.headers ? Headers.fromInput(opts.headers) : Headers.empty |
| 328 | const context = opts?.context ?? Context.empty() |
| 329 | if (!isStream) { |
| 330 | const onRequest = (span: Tracer.Span | undefined) => |
| 331 | onEffectRequest( |
| 332 | rpc, |
| 333 | middleware, |
| 334 | span, |
| 335 | rpc.payloadSchema.make(payload), |
| 336 | headers, |
| 337 | context, |
| 338 | opts?.discard ?? false |
| 339 | ) |
| 340 | if (!createSpan) return onRequest(undefined) |
| 341 | const method = RpcTracing.methodName(groupTracing, rpc._tag) |
| 342 | return Effect.useSpan( |
| 343 | RpcTracing.spanName(spanPrefix, method), |
| 344 | { kind: "client", attributes: RpcTracing.spanAttributes(groupTracing, method, options.spanAttributes) }, |
| 345 | onRequest |
| 346 | ) |
| 347 | } |
| 348 | const queue = onStreamRequest( |
| 349 | rpc, |
| 350 | createSpan, |
| 351 | middleware, |
| 352 | rpc.payloadSchema.make(payload), |
| 353 | headers, |
| 354 | opts?.streamBufferSize ?? 16, |
| 355 | context |
| 356 | ) |
| 357 | if (opts?.asQueue) return queue |
| 358 | return Stream.unwrap(Effect.map(queue, Stream.fromQueue)) |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | const onEffectRequest = ( |
| 363 | rpc: Rpc.AnyWithProps, |