MCPcopy Create free account
hub / github.com/Effect-TS/effect / reportConnect

Function reportConnect

packages/sql/pg/src/PgPool.ts:197–227  ·  view source on GitHub ↗
(connection: PgConnection.PgConnection)

Source from the content-addressed store, hash-verified

195 >()
196
197 const reportConnect = (connection: PgConnection.PgConnection): Effect.Effect<void> =>
198 Effect.withFiber((fiber) => {
199 const opened = connects.get(connection)
200 if (opened === undefined) return Effect.void
201 connects.delete(connection)
202 const statement = fiber.cache.span
203 // Without span timing the statement span has no start time to measure from.
204 if (
205 !fiber.cache.tracerEnabled || statement?._tag !== "Span" || !fiber.getRef(SpanPropagationEnabled) ||
206 !fiber.getRef(TracerTimingEnabled)
207 ) {
208 return Effect.void
209 }
210 const [startTime, endTime, connectSpan] = opened
211 const waitedFrom = statement.status.startTime
212 if (endTime < waitedFrom) return Effect.void
213 const span = fiber.getRef(Tracer.Tracer).span({
214 name: "db.connect",
215 parent: Option.some(statement),
216 annotations: Context.empty(),
217 links: connectSpan !== undefined ? [{ span: connectSpan, attributes: {} }] : [],
218 startTime: startTime > waitedFrom ? startTime : waitedFrom,
219 kind: "client",
220 root: false,
221 sampled: statement.sampled
222 })
223 span.attribute("db.system.name", "postgresql")
224 span.attribute("db.client.connection.connect_time_ms", Number(endTime - startTime) / 1e6)
225 span.end(endTime, Exit.void)
226 return Effect.void
227 })
228
229 const handOut = (connection: PgConnection.PgConnection) =>
230 connects.has(connection) ? Effect.as(reportConnect(connection), connection) : Effect.succeed(connection)

Callers 2

handOutFunction · 0.85
runFunction · 0.85

Calls 8

getRefMethod · 0.80
spanMethod · 0.80
someMethod · 0.80
getMethod · 0.65
deleteMethod · 0.65
attributeMethod · 0.65
endMethod · 0.65
NumberFunction · 0.50

Tested by

no test coverage detected