@effect/platform
Advanced tools
Comparing version 0.31.0 to 0.31.1
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.xForwardedHeaders = exports.withLoggerDisabled = exports.make = exports.loggerDisabled = exports.logger = void 0; | ||
exports.xForwardedHeaders = exports.withTracerDisabledWhen = exports.withLoggerDisabled = exports.make = exports.loggerDisabled = exports.logger = exports.currentTracerDisabledWhen = void 0; | ||
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../internal/http/middleware.js")); | ||
@@ -56,2 +56,12 @@ function _getRequireWildcardCache(e) { | ||
* @since 1.0.0 | ||
* @category fiber refs | ||
*/ | ||
const currentTracerDisabledWhen = exports.currentTracerDisabledWhen = internal.currentTracerDisabledWhen; | ||
/** | ||
* @since 1.0.0 | ||
* @category fiber refs | ||
*/ | ||
const withTracerDisabledWhen = exports.withTracerDisabledWhen = internal.withTracerDisabledWhen; | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
@@ -58,0 +68,0 @@ */ |
@@ -6,5 +6,6 @@ "use strict"; | ||
}); | ||
exports.xForwardedHeaders = exports.withLoggerDisabled = exports.tracer = exports.make = exports.loggerDisabled = exports.logger = void 0; | ||
exports.xForwardedHeaders = exports.withTracerDisabledWhen = exports.withLoggerDisabled = exports.tracer = exports.make = exports.loggerDisabled = exports.logger = exports.currentTracerDisabledWhen = void 0; | ||
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect")); | ||
var FiberRef = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/FiberRef")); | ||
var Function = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Function")); | ||
var _GlobalValue = /*#__PURE__*/require("effect/GlobalValue"); | ||
@@ -48,2 +49,6 @@ var Headers = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../../Http/Headers.js")); | ||
exports.withLoggerDisabled = withLoggerDisabled; | ||
const currentTracerDisabledWhen = exports.currentTracerDisabledWhen = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("@effect/platform/Http/Middleware/tracerDisabledWhen"), () => FiberRef.unsafeMake(Function.constFalse)); | ||
/** @internal */ | ||
const withTracerDisabledWhen = exports.withTracerDisabledWhen = /*#__PURE__*/Function.dual(2, (self, pred) => Effect.locally(self, currentTracerDisabledWhen, pred)); | ||
/** @internal */ | ||
const logger = exports.logger = /*#__PURE__*/make(httpApp => { | ||
@@ -69,3 +74,3 @@ let counter = 0; | ||
const appWithStatus = Effect.tap(httpApp, response => Effect.annotateCurrentSpan("http.status", response.status)); | ||
return Effect.flatMap(ServerRequest.ServerRequest, request => Effect.flatMap(request.headers["x-b3-traceid"] || request.headers["b3"] ? Effect.orElseSucceed(IncomingMessage.schemaExternalSpan(request), () => undefined) : Effect.succeed(undefined), parent => Effect.withSpan(appWithStatus, `http ${request.method}`, { | ||
return Effect.flatMap(Effect.zip(ServerRequest.ServerRequest, FiberRef.get(currentTracerDisabledWhen)), ([request, disabledWhen]) => Effect.flatMap(request.headers["x-b3-traceid"] || request.headers["b3"] ? Effect.orElseSucceed(IncomingMessage.schemaExternalSpan(request), () => undefined) : Effect.succeed(undefined), parent => disabledWhen(request) ? httpApp : Effect.withSpan(appWithStatus, `http ${request.method}`, { | ||
attributes: { | ||
@@ -72,0 +77,0 @@ "http.method": request.method, |
@@ -6,3 +6,5 @@ /** | ||
import type * as FiberRef from "effect/FiberRef"; | ||
import type * as Predicate from "effect/Predicate"; | ||
import type * as App from "./App.js"; | ||
import type * as ServerRequest from "./ServerRequest.js"; | ||
/** | ||
@@ -48,2 +50,15 @@ * @since 1.0.0 | ||
* @since 1.0.0 | ||
* @category fiber refs | ||
*/ | ||
export declare const currentTracerDisabledWhen: FiberRef.FiberRef<Predicate.Predicate<ServerRequest.ServerRequest>>; | ||
/** | ||
* @since 1.0.0 | ||
* @category fiber refs | ||
*/ | ||
export declare const withTracerDisabledWhen: { | ||
(predicate: Predicate.Predicate<ServerRequest.ServerRequest>): <R, E, A>(effect: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>; | ||
<R, E, A>(effect: Effect.Effect<R, E, A>, predicate: Predicate.Predicate<ServerRequest.ServerRequest>): Effect.Effect<R, E, A>; | ||
}; | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
@@ -50,0 +65,0 @@ */ |
@@ -24,2 +24,12 @@ import * as internal from "../internal/http/middleware.js"; | ||
* @since 1.0.0 | ||
* @category fiber refs | ||
*/ | ||
export const currentTracerDisabledWhen = internal.currentTracerDisabledWhen; | ||
/** | ||
* @since 1.0.0 | ||
* @category fiber refs | ||
*/ | ||
export const withTracerDisabledWhen = internal.withTracerDisabledWhen; | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
@@ -26,0 +36,0 @@ */ |
import * as Effect from "effect/Effect"; | ||
import * as FiberRef from "effect/FiberRef"; | ||
import * as Function from "effect/Function"; | ||
import { globalValue } from "effect/GlobalValue"; | ||
@@ -14,2 +15,6 @@ import * as Headers from "../../Http/Headers.js"; | ||
/** @internal */ | ||
export const currentTracerDisabledWhen = /*#__PURE__*/globalValue( /*#__PURE__*/Symbol.for("@effect/platform/Http/Middleware/tracerDisabledWhen"), () => FiberRef.unsafeMake(Function.constFalse)); | ||
/** @internal */ | ||
export const withTracerDisabledWhen = /*#__PURE__*/Function.dual(2, (self, pred) => Effect.locally(self, currentTracerDisabledWhen, pred)); | ||
/** @internal */ | ||
export const logger = /*#__PURE__*/make(httpApp => { | ||
@@ -35,3 +40,3 @@ let counter = 0; | ||
const appWithStatus = Effect.tap(httpApp, response => Effect.annotateCurrentSpan("http.status", response.status)); | ||
return Effect.flatMap(ServerRequest.ServerRequest, request => Effect.flatMap(request.headers["x-b3-traceid"] || request.headers["b3"] ? Effect.orElseSucceed(IncomingMessage.schemaExternalSpan(request), () => undefined) : Effect.succeed(undefined), parent => Effect.withSpan(appWithStatus, `http ${request.method}`, { | ||
return Effect.flatMap(Effect.zip(ServerRequest.ServerRequest, FiberRef.get(currentTracerDisabledWhen)), ([request, disabledWhen]) => Effect.flatMap(request.headers["x-b3-traceid"] || request.headers["b3"] ? Effect.orElseSucceed(IncomingMessage.schemaExternalSpan(request), () => undefined) : Effect.succeed(undefined), parent => disabledWhen(request) ? httpApp : Effect.withSpan(appWithStatus, `http ${request.method}`, { | ||
attributes: { | ||
@@ -38,0 +43,0 @@ "http.method": request.method, |
{ | ||
"name": "@effect/platform", | ||
"version": "0.31.0", | ||
"version": "0.31.1", | ||
"description": "Unified interfaces for common platform-specific services", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -6,4 +6,6 @@ /** | ||
import type * as FiberRef from "effect/FiberRef" | ||
import type * as Predicate from "effect/Predicate" | ||
import * as internal from "../internal/http/middleware.js" | ||
import type * as App from "./App.js" | ||
import type * as ServerRequest from "./ServerRequest.js" | ||
@@ -57,4 +59,25 @@ /** | ||
* @since 1.0.0 | ||
* @category fiber refs | ||
*/ | ||
export const currentTracerDisabledWhen: FiberRef.FiberRef<Predicate.Predicate<ServerRequest.ServerRequest>> = | ||
internal.currentTracerDisabledWhen | ||
/** | ||
* @since 1.0.0 | ||
* @category fiber refs | ||
*/ | ||
export const withTracerDisabledWhen: { | ||
( | ||
predicate: Predicate.Predicate<ServerRequest.ServerRequest> | ||
): <R, E, A>(effect: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A> | ||
<R, E, A>( | ||
effect: Effect.Effect<R, E, A>, | ||
predicate: Predicate.Predicate<ServerRequest.ServerRequest> | ||
): Effect.Effect<R, E, A> | ||
} = internal.withTracerDisabledWhen | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
*/ | ||
export const xForwardedHeaders: <R, E>(httpApp: App.Default<R, E>) => App.Default<R, E> = internal.xForwardedHeaders |
import * as Effect from "effect/Effect" | ||
import * as FiberRef from "effect/FiberRef" | ||
import * as Function from "effect/Function" | ||
import { globalValue } from "effect/GlobalValue" | ||
import type * as Predicate from "effect/Predicate" | ||
import * as Headers from "../../Http/Headers.js" | ||
@@ -26,2 +28,19 @@ import * as IncomingMessage from "../../Http/IncomingMessage.js" | ||
/** @internal */ | ||
export const currentTracerDisabledWhen = globalValue( | ||
Symbol.for("@effect/platform/Http/Middleware/tracerDisabledWhen"), | ||
() => FiberRef.unsafeMake<Predicate.Predicate<ServerRequest.ServerRequest>>(Function.constFalse) | ||
) | ||
/** @internal */ | ||
export const withTracerDisabledWhen = Function.dual< | ||
( | ||
predicate: Predicate.Predicate<ServerRequest.ServerRequest> | ||
) => <R, E, A>(effect: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>, | ||
<R, E, A>( | ||
effect: Effect.Effect<R, E, A>, | ||
predicate: Predicate.Predicate<ServerRequest.ServerRequest> | ||
) => Effect.Effect<R, E, A> | ||
>(2, (self, pred) => Effect.locally(self, currentTracerDisabledWhen, pred)) | ||
/** @internal */ | ||
export const logger = make((httpApp) => { | ||
@@ -65,4 +84,4 @@ let counter = 0 | ||
return Effect.flatMap( | ||
ServerRequest.ServerRequest, | ||
(request) => | ||
Effect.zip(ServerRequest.ServerRequest, FiberRef.get(currentTracerDisabledWhen)), | ||
([request, disabledWhen]) => | ||
Effect.flatMap( | ||
@@ -73,7 +92,9 @@ request.headers["x-b3-traceid"] || request.headers["b3"] ? | ||
(parent) => | ||
Effect.withSpan( | ||
appWithStatus, | ||
`http ${request.method}`, | ||
{ attributes: { "http.method": request.method, "http.url": request.url }, parent } | ||
) | ||
disabledWhen(request) ? | ||
httpApp : | ||
Effect.withSpan( | ||
appWithStatus, | ||
`http ${request.method}`, | ||
{ attributes: { "http.method": request.method, "http.url": request.url }, parent } | ||
) | ||
) | ||
@@ -80,0 +101,0 @@ ) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1247529
22243