Skip to content

Commit a5f6c7f

Browse files
committed
Fix request body double-read in OTLP trace proxy handler
Parse JSON from the already-read body bytes instead of re-reading the request stream via HttpServerRequest.schemaBodyJson. HTTP request bodies are stream-based and can only be consumed once, so the second read would silently fail (caught by Effect.catch), causing local browser trace recording to never work. Also set the correct content-type (application/json) on the forwarded upstream request body.
1 parent b2bd70a commit a5f6c7f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

apps/server/src/http.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Mime from "@effect/platform-node/Mime";
2-
import { Effect, FileSystem, Layer, Option, Path } from "effect";
2+
import { Effect, FileSystem, Layer, Option, Path, Schema } from "effect";
33
import {
44
HttpBody,
55
HttpClient,
@@ -39,8 +39,10 @@ export const otlpTracesProxyRouteLayer = HttpRouter.add(
3939
Effect.map((buffer) => new Uint8Array(buffer)),
4040
);
4141

42-
// Collect traces to local trace sink
43-
yield* HttpServerRequest.schemaBodyJson(OtlpTracePayloadSchema).pipe(
42+
// Collect traces to local trace sink (parse from already-read body bytes)
43+
yield* Schema.decodeEffect(Schema.fromJsonString(OtlpTracePayloadSchema))(
44+
new TextDecoder().decode(body),
45+
).pipe(
4446
Effect.map(decodeOtlpTraceRecords),
4547
Effect.flatMap(browserTraceCollector.record),
4648
Effect.catch((cause) => Effect.logWarning("Failed to record browser OTLP traces", { cause })),
@@ -53,7 +55,7 @@ export const otlpTracesProxyRouteLayer = HttpRouter.add(
5355
// Forward request to remote OTLP traces endpoint
5456
return yield* httpClient
5557
.post(otlpTracesUrl, {
56-
body: HttpBody.uint8Array(body),
58+
body: HttpBody.uint8Array(body, "application/json"),
5759
})
5860
.pipe(
5961
Effect.flatMap(HttpClientResponse.filterStatusOk),

0 commit comments

Comments
 (0)