@effect/platform 0.48.22 → 0.48.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Http/TraceContext/package.json +6 -0
- package/dist/cjs/Http/Client.js +11 -1
- package/dist/cjs/Http/Client.js.map +1 -1
- package/dist/cjs/Http/IncomingMessage.js +2 -51
- package/dist/cjs/Http/IncomingMessage.js.map +1 -1
- package/dist/cjs/Http/TraceContext.js +132 -0
- package/dist/cjs/Http/TraceContext.js.map +1 -0
- package/dist/cjs/internal/http/client.js +51 -34
- package/dist/cjs/internal/http/client.js.map +1 -1
- package/dist/cjs/internal/http/middleware.js +36 -22
- package/dist/cjs/internal/http/middleware.js.map +1 -1
- package/dist/dts/Http/Client.d.ts +16 -1
- package/dist/dts/Http/Client.d.ts.map +1 -1
- package/dist/dts/Http/IncomingMessage.d.ts +1 -7
- package/dist/dts/Http/IncomingMessage.d.ts.map +1 -1
- package/dist/dts/Http/TraceContext.d.ts +39 -0
- package/dist/dts/Http/TraceContext.d.ts.map +1 -0
- package/dist/esm/Http/Client.js +10 -0
- package/dist/esm/Http/Client.js.map +1 -1
- package/dist/esm/Http/IncomingMessage.js +1 -50
- package/dist/esm/Http/IncomingMessage.js.map +1 -1
- package/dist/esm/Http/TraceContext.js +95 -0
- package/dist/esm/Http/TraceContext.js.map +1 -0
- package/dist/esm/internal/http/client.js +50 -33
- package/dist/esm/internal/http/client.js.map +1 -1
- package/dist/esm/internal/http/middleware.js +36 -22
- package/dist/esm/internal/http/middleware.js.map +1 -1
- package/package.json +11 -3
- package/src/Http/Client.ts +25 -1
- package/src/Http/IncomingMessage.ts +2 -71
- package/src/Http/TraceContext.ts +109 -0
- package/src/internal/http/client.ts +89 -55
- package/src/internal/http/middleware.ts +46 -49
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import * as Cause from "effect/Cause"
|
|
2
|
+
import * as Context from "effect/Context"
|
|
2
3
|
import * as Effect from "effect/Effect"
|
|
3
4
|
import * as FiberRef from "effect/FiberRef"
|
|
4
5
|
import { constFalse, dual } from "effect/Function"
|
|
5
6
|
import { globalValue } from "effect/GlobalValue"
|
|
7
|
+
import * as Option from "effect/Option"
|
|
6
8
|
import type * as Predicate from "effect/Predicate"
|
|
7
9
|
import * as Headers from "../../Http/Headers.js"
|
|
8
|
-
import * as IncomingMessage from "../../Http/IncomingMessage.js"
|
|
9
10
|
import type * as Middleware from "../../Http/Middleware.js"
|
|
10
11
|
import * as ServerError from "../../Http/ServerError.js"
|
|
11
12
|
import * as ServerRequest from "../../Http/ServerRequest.js"
|
|
13
|
+
import * as TraceContext from "../../Http/TraceContext.js"
|
|
12
14
|
|
|
13
15
|
/** @internal */
|
|
14
16
|
export const make = <M extends Middleware.Middleware>(middleware: M): M => middleware
|
|
@@ -46,37 +48,33 @@ export const withTracerDisabledWhen = dual<
|
|
|
46
48
|
/** @internal */
|
|
47
49
|
export const logger = make((httpApp) => {
|
|
48
50
|
let counter = 0
|
|
49
|
-
return Effect.
|
|
50
|
-
|
|
51
|
-
(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
)),
|
|
77
|
-
`http.span.${++counter}`
|
|
78
|
-
)
|
|
79
|
-
)
|
|
51
|
+
return Effect.withFiberRuntime((fiber) => {
|
|
52
|
+
const context = fiber.getFiberRef(FiberRef.currentContext)
|
|
53
|
+
const request = Context.unsafeGet(context, ServerRequest.ServerRequest)
|
|
54
|
+
return Effect.withLogSpan(
|
|
55
|
+
Effect.onExit(httpApp, (exit) => {
|
|
56
|
+
if (fiber.getFiberRef(loggerDisabled)) {
|
|
57
|
+
return Effect.unit
|
|
58
|
+
}
|
|
59
|
+
return exit._tag === "Failure" ?
|
|
60
|
+
Effect.annotateLogs(Effect.log(exit.cause), {
|
|
61
|
+
"http.method": request.method,
|
|
62
|
+
"http.url": request.url,
|
|
63
|
+
"http.status": Cause.isInterruptedOnly(exit.cause)
|
|
64
|
+
? ServerError.isClientAbortCause(exit.cause)
|
|
65
|
+
? 499
|
|
66
|
+
: 503
|
|
67
|
+
: 500
|
|
68
|
+
}) :
|
|
69
|
+
Effect.annotateLogs(Effect.log("Sent HTTP response"), {
|
|
70
|
+
"http.method": request.method,
|
|
71
|
+
"http.url": request.url,
|
|
72
|
+
"http.status": exit.value.status
|
|
73
|
+
})
|
|
74
|
+
}),
|
|
75
|
+
`http.span.${++counter}`
|
|
76
|
+
)
|
|
77
|
+
})
|
|
80
78
|
})
|
|
81
79
|
|
|
82
80
|
/** @internal */
|
|
@@ -85,23 +83,22 @@ export const tracer = make((httpApp) => {
|
|
|
85
83
|
httpApp,
|
|
86
84
|
(response) => Effect.annotateCurrentSpan("http.status", response.status)
|
|
87
85
|
)
|
|
88
|
-
return Effect.
|
|
89
|
-
|
|
90
|
-
(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
)
|
|
86
|
+
return Effect.withFiberRuntime((fiber) => {
|
|
87
|
+
const context = fiber.getFiberRef(FiberRef.currentContext)
|
|
88
|
+
const request = Context.unsafeGet(context, ServerRequest.ServerRequest)
|
|
89
|
+
const disabled = fiber.getFiberRef(currentTracerDisabledWhen)(request)
|
|
90
|
+
if (disabled) {
|
|
91
|
+
return httpApp
|
|
92
|
+
}
|
|
93
|
+
return Effect.withSpan(
|
|
94
|
+
appWithStatus,
|
|
95
|
+
`http.server ${request.method}`,
|
|
96
|
+
{
|
|
97
|
+
attributes: { "http.method": request.method, "http.url": request.url },
|
|
98
|
+
parent: Option.getOrUndefined(TraceContext.fromHeaders(request.headers))
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
})
|
|
105
102
|
})
|
|
106
103
|
|
|
107
104
|
/** @internal */
|