@effect-app/infra 4.0.0-beta.210 → 4.0.0-beta.211

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.
@@ -103,7 +103,13 @@ export function makeRepoInternal<
103
103
  allE,
104
104
  (_) => decodeMany(_).pipe(Effect.orDie)
105
105
  )
106
- .pipe(Effect.map((_) => _ as T[]))
106
+ .pipe(
107
+ Effect.map((_) => _ as T[]),
108
+ Effect.withSpan("Repository.all", {
109
+ kind: "client",
110
+ attributes: { "app.entity": name }
111
+ }, { captureStackTrace: false })
112
+ )
107
113
 
108
114
  const fieldsSchema = schema as unknown as { fields: any }
109
115
  // assumes the id field never needs a service...
@@ -163,9 +169,11 @@ export function makeRepoInternal<
163
169
  )
164
170
  })
165
171
 
166
- const find = Effect.fn("find", { attributes: { "app.entity": name } })(function*(id: T[IdKey]) {
172
+ const find = Effect.fn("Repository.find", {
173
+ kind: "client",
174
+ attributes: { "app.entity": name }
175
+ })(function*(id: T[IdKey]) {
167
176
  yield* Effect.annotateCurrentSpan({ "app.entity.id": id })
168
-
169
177
  return yield* flatMapOption(findE(id), (_) => Effect.orDie(decode(_)))
170
178
  })
171
179
 
@@ -190,7 +198,7 @@ export function makeRepoInternal<
190
198
  Effect.andThen(saveAllE)
191
199
  )
192
200
 
193
- const saveAndPublish = Effect.fn("saveAndPublish", { attributes: { "app.entity": name } })(
201
+ const saveAndPublish = Effect.fn("Repository.saveAndPublish", { attributes: { "app.entity": name } })(
194
202
  function*(items: Iterable<T>, events: Iterable<Evt> = []) {
195
203
  const it = Chunk.fromIterable(items)
196
204
  const evts = [...events]
@@ -209,7 +217,7 @@ export function makeRepoInternal<
209
217
  }
210
218
  )
211
219
 
212
- const removeAndPublish = Effect.fn("removeAndPublish", { attributes: { "app.entity": name } })(
220
+ const removeAndPublish = Effect.fn("Repository.removeAndPublish", { attributes: { "app.entity": name } })(
213
221
  function*(a: Iterable<T>, events: Iterable<Evt> = []) {
214
222
  const { set } = yield* cms
215
223
  const it = [...a]
@@ -237,7 +245,7 @@ export function makeRepoInternal<
237
245
  }
238
246
  )
239
247
 
240
- const removeById = Effect.fn("removeById", { attributes: { "app.entity": name } })(
248
+ const removeById = Effect.fn("Repository.removeById", { attributes: { "app.entity": name } })(
241
249
  function*(idOrIds: T[IdKey] | ReadonlyArray<T[IdKey]>) {
242
250
  const ids = globalThis.Array.isArray(idOrIds)
243
251
  ? idOrIds as readonly T[IdKey][]
@@ -262,12 +270,22 @@ export function makeRepoInternal<
262
270
  return yield* decodeMany(items.map((_) => mapReverse(_, cm.set))).pipe(Effect.orDie)
263
271
  }
264
272
  )
273
+ const decodeManyCache = new WeakMap<
274
+ S.Codec<any, any, any>,
275
+ (i: readonly any[]) => Effect.Effect<any, any, any>
276
+ >()
277
+ const getDecodeMany = (s: S.Codec<any, Encoded, any>) => {
278
+ let dec = decodeManyCache.get(s)
279
+ if (!dec) {
280
+ dec = S.decodeEffectConcurrently(S.Array(s))
281
+ decodeManyCache.set(s, dec)
282
+ }
283
+ return dec
284
+ }
265
285
  const parseMany2 = Effect.fn("parseMany2", { attributes: { "app.entity": name } })(
266
286
  function*<A, R>(items: readonly PM[], schema: S.Codec<A, Encoded, R>) {
267
287
  const cm = yield* cms
268
- return yield* S.decodeEffectConcurrently(S.Array(schema))(items.map((_) => mapReverse(_, cm.set))).pipe(
269
- Effect.orDie
270
- )
288
+ return yield* getDecodeMany(schema)(items.map((_) => mapReverse(_, cm.set))).pipe(Effect.orDie)
271
289
  }
272
290
  )
273
291
  const filter = <U extends keyof Encoded = keyof Encoded>(args: FilterArgs<Encoded, U>) =>
@@ -340,18 +358,21 @@ export function makeRepoInternal<
340
358
  .map(eff, (_) => NonNegativeInt(_.length))
341
359
  .pipe(Effect.catchTag("SchemaError", (e) => Effect.die(e)))
342
360
  : eff,
343
- Effect.withSpan(`query ${name}`, {
361
+ Effect.tap((r) =>
362
+ Effect.annotateCurrentSpan({
363
+ "app.query.ttype": a.ttype,
364
+ "app.query.mode": a.mode,
365
+ "db.response.returned_rows": Array.isArray(r) ? r.length : 1
366
+ })
367
+ ),
368
+ Effect.withSpan("Repository.query", {
344
369
  kind: "client",
345
- attributes: {
346
- "app.entity": name,
347
- "db.operation.name": "query",
348
- "db.collection.name": name
349
- }
370
+ attributes: { "app.entity": name }
350
371
  }, { captureStackTrace: false })
351
372
  )
352
373
  }) as any
353
374
 
354
- const validateSample = Effect.fn("validateSample", { attributes: { "app.entity": name } })(
375
+ const validateSample = Effect.fn("Repository.validateSample", { attributes: { "app.entity": name } })(
355
376
  function*(options?: {
356
377
  percentage?: number
357
378
  maxItems?: number
@@ -360,10 +381,15 @@ export function makeRepoInternal<
360
381
  const maxItems = options?.maxItems
361
382
 
362
383
  // 1. get all IDs with projection (bypasses main schema decode)
363
- const allIds = yield* store.filter({
364
- t: null as unknown as Encoded,
365
- select: [idKey as keyof Encoded]
366
- })
384
+ const allIds = yield* store
385
+ .filter({
386
+ t: null as unknown as Encoded,
387
+ select: [idKey as keyof Encoded]
388
+ })
389
+ .pipe(Effect.withSpan("Repository.filter", {
390
+ kind: "client",
391
+ attributes: { "app.entity": name }
392
+ }, { captureStackTrace: false }))
367
393
 
368
394
  // 2. random subset
369
395
  const shuffled = [...allIds].sort(() => Math.random() - 0.5)
@@ -378,7 +404,12 @@ export function makeRepoInternal<
378
404
 
379
405
  for (const item of sample) {
380
406
  const id = item[idKey]
381
- const rawResult = yield* store.find(id)
407
+ const rawResult = yield* store.find(id).pipe(
408
+ Effect.withSpan("Repository.find", {
409
+ kind: "client",
410
+ attributes: { "app.entity": name, "app.entity.id": id }
411
+ }, { captureStackTrace: false })
412
+ )
382
413
 
383
414
  if (Option.isNone(rawResult)) continue
384
415
 
@@ -424,7 +455,13 @@ export function makeRepoInternal<
424
455
  validateSample,
425
456
  queryRaw<A, Out, QR>(schema: S.Codec<A, Out, QR>, q: Q.RawQuery<Encoded, Out>) {
426
457
  const dec = S.decodeEffectConcurrently(S.Array(schema))
427
- return store.queryRaw(q).pipe(Effect.flatMap(dec))
458
+ return store.queryRaw(q).pipe(
459
+ Effect.flatMap(dec),
460
+ Effect.withSpan("Repository.queryRaw", {
461
+ kind: "client",
462
+ attributes: { "app.entity": name }
463
+ }, { captureStackTrace: false })
464
+ )
428
465
  },
429
466
  query(q: any) {
430
467
  // eslint-disable-next-line prefer-rest-params
@@ -437,12 +474,20 @@ export function makeRepoInternal<
437
474
  const dec = S.decodeEffectConcurrently(schema)
438
475
  const encMany = S.encodeEffect(S.Array(schema))
439
476
  const decMany = S.decodeEffectConcurrently(S.Array(schema))
477
+ const spanAttrs = { kind: "client" as const, attributes: { "app.entity": name } }
440
478
  return {
441
479
  all: allE.pipe(
442
480
  Effect.flatMap(decMany),
443
- Effect.map((_) => _ as any[])
481
+ Effect.map((_) => _ as any[]),
482
+ Effect.withSpan("Repository.mapped.all", spanAttrs, { captureStackTrace: false })
444
483
  ),
445
- find: (id: T[IdKey]) => flatMapOption(findE(id), dec),
484
+ find: (id: T[IdKey]) =>
485
+ flatMapOption(findE(id), dec).pipe(
486
+ Effect.withSpan("Repository.mapped.find", {
487
+ ...spanAttrs,
488
+ attributes: { ...spanAttrs.attributes, "app.entity.id": id }
489
+ }, { captureStackTrace: false })
490
+ ),
446
491
  // query: (q: any) => {
447
492
  // const a = Q.toFilter(q)
448
493
 
@@ -461,7 +506,7 @@ export function makeRepoInternal<
461
506
  // },
462
507
  save: (...xes: any[]) =>
463
508
  Effect.flatMap(encMany(xes), (_) => saveAllE(_)).pipe(
464
- Effect.withSpan("mapped.save", { attributes: { "app.entity": name } }, { captureStackTrace: false })
509
+ Effect.withSpan("Repository.mapped.save", spanAttrs, { captureStackTrace: false })
465
510
  )
466
511
  }
467
512
  }
@@ -8,7 +8,7 @@ import { OptimisticConcurrencyException } from "../errors.js"
8
8
  import { InfraLogger } from "../logger.js"
9
9
  import type { FieldValues } from "../Model/filter/types.js"
10
10
  import { type RawQuery } from "../Model/query.js"
11
- import { annotateCosmosResponse, withDbSpan } from "../otel.js"
11
+ import { annotateCosmosResponse, annotateDb } from "../otel.js"
12
12
  import { buildWhereCosmosQuery3, logQuery } from "./Cosmos/query.js"
13
13
  import { storeId } from "./Memory.js"
14
14
  import { type FilterArgs, type PersistenceModelType, type StorageConfig, type Store, type StoreConfig, StoreMaker } from "./service.js"
@@ -140,7 +140,7 @@ const makeCosmosStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
140
140
  )
141
141
  }),
142
142
  Effect.withLogSpan(`Cosmos.seedCheck ${name} in ${ns} [effect-app/infra/Store]`),
143
- withDbSpan({
143
+ annotateDb({
144
144
  operation: "seed",
145
145
  system: "cosmosdb",
146
146
  collection: containerId,
@@ -260,7 +260,7 @@ const makeCosmosStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
260
260
  return batchResult.flat() as unknown as NonEmptyReadonlyArray<Encoded>
261
261
  })
262
262
  .pipe(
263
- withDbSpan({
263
+ annotateDb({
264
264
  operation: "bulkSet",
265
265
  system: "cosmosdb",
266
266
  collection: containerId,
@@ -334,7 +334,7 @@ const makeCosmosStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
334
334
  })) as unknown as NonEmptyReadonlyArray<Encoded>
335
335
  })))
336
336
  })
337
- .pipe(withDbSpan({
337
+ .pipe(annotateDb({
338
338
  operation: "batchSet",
339
339
  system: "cosmosdb",
340
340
  collection: containerId,
@@ -364,7 +364,7 @@ const makeCosmosStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
364
364
  )
365
365
  })
366
366
  .pipe(
367
- withDbSpan({
367
+ annotateDb({
368
368
  operation: "queryRaw",
369
369
  system: "cosmosdb",
370
370
  collection: containerId,
@@ -392,7 +392,7 @@ const makeCosmosStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
392
392
  )
393
393
  )
394
394
  .pipe(
395
- withDbSpan({
395
+ annotateDb({
396
396
  operation: "batchRemove",
397
397
  system: "cosmosdb",
398
398
  collection: containerId,
@@ -421,7 +421,7 @@ const makeCosmosStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
421
421
  return response.resources.map((_) => ({ ...defaultValues, ...mapReverseId(_) }))
422
422
  })
423
423
  .pipe(
424
- withDbSpan({
424
+ annotateDb({
425
425
  operation: "all",
426
426
  system: "cosmosdb",
427
427
  collection: containerId,
@@ -486,7 +486,7 @@ const makeCosmosStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
486
486
  return response.resources.map(({ f }) => ({ ...defaultValues, ...mapReverseId(f as any) }) as any)
487
487
  })
488
488
  .pipe(
489
- withDbSpan({
489
+ annotateDb({
490
490
  operation: "filter",
491
491
  system: "cosmosdb",
492
492
  collection: containerId,
@@ -512,7 +512,7 @@ const makeCosmosStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
512
512
  Option.map((_) => ({ ...defaultValues, ...mapReverseId(_) }))
513
513
  )
514
514
  })
515
- .pipe(withDbSpan({
515
+ .pipe(annotateDb({
516
516
  operation: "find",
517
517
  system: "cosmosdb",
518
518
  collection: containerId,
@@ -572,7 +572,7 @@ const makeCosmosStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
572
572
  _etag: x.etag
573
573
  }))
574
574
  }),
575
- withDbSpan({
575
+ annotateDb({
576
576
  operation: "set",
577
577
  system: "cosmosdb",
578
578
  collection: containerId,
package/src/Store/Disk.ts CHANGED
@@ -5,7 +5,7 @@ import fs from "fs"
5
5
 
6
6
  import { Console, Effect, flow, Semaphore } from "effect-app"
7
7
  import type { FieldValues } from "../Model/filter/types.js"
8
- import { withDbSpan } from "../otel.js"
8
+ import { annotateDb } from "../otel.js"
9
9
  import { makeMemoryStoreInt, storeId } from "./Memory.js"
10
10
  import { type PersistenceModelType, type StorageConfig, type Store, type StoreConfig, StoreMaker } from "./service.js"
11
11
 
@@ -32,7 +32,7 @@ function makeDiskStoreInt<IdKey extends keyof Encoded, Encoded extends FieldValu
32
32
  get: fu
33
33
  .readTextFile(file)
34
34
  .pipe(
35
- withDbSpan({
35
+ annotateDb({
36
36
  operation: "read.readFile",
37
37
  system: "disk",
38
38
  collection: name,
@@ -42,7 +42,7 @@ function makeDiskStoreInt<IdKey extends keyof Encoded, Encoded extends FieldValu
42
42
  }),
43
43
  Effect.flatMap((x) =>
44
44
  Effect.sync(() => JSON.parse(x) as PM[]).pipe(
45
- withDbSpan({
45
+ annotateDb({
46
46
  operation: "read.parse",
47
47
  system: "disk",
48
48
  collection: name,
@@ -53,7 +53,7 @@ function makeDiskStoreInt<IdKey extends keyof Encoded, Encoded extends FieldValu
53
53
  )
54
54
  ),
55
55
  Effect.orDie,
56
- withDbSpan({
56
+ annotateDb({
57
57
  operation: "read",
58
58
  system: "disk",
59
59
  collection: name,
@@ -66,7 +66,7 @@ function makeDiskStoreInt<IdKey extends keyof Encoded, Encoded extends FieldValu
66
66
  Effect
67
67
  .sync(() => JSON.stringify([...v], undefined, 2))
68
68
  .pipe(
69
- withDbSpan({
69
+ annotateDb({
70
70
  operation: "stringify",
71
71
  system: "disk",
72
72
  collection: name,
@@ -79,7 +79,7 @@ function makeDiskStoreInt<IdKey extends keyof Encoded, Encoded extends FieldValu
79
79
  (json) =>
80
80
  fu
81
81
  .writeTextFile(file, json)
82
- .pipe(withDbSpan({
82
+ .pipe(annotateDb({
83
83
  operation: "write.writeFile",
84
84
  system: "disk",
85
85
  collection: name,
@@ -88,7 +88,7 @@ function makeDiskStoreInt<IdKey extends keyof Encoded, Encoded extends FieldValu
88
88
  extra: { ...fileExtra, "disk.file.size": json.length }
89
89
  }))
90
90
  ),
91
- withDbSpan({
91
+ annotateDb({
92
92
  operation: "write",
93
93
  system: "disk",
94
94
  collection: name,
@@ -4,7 +4,7 @@ import { Array, Context, Effect, flow, type NonEmptyReadonlyArray, Option, Order
4
4
  import { NonEmptyString255 } from "effect-app/Schema"
5
5
  import { InfraLogger } from "../logger.js"
6
6
  import type { FieldValues } from "../Model/filter/types.js"
7
- import { withDbSpan } from "../otel.js"
7
+ import { annotateDb } from "../otel.js"
8
8
  import { codeFilter, codeFilter3_ } from "./codeFilter.js"
9
9
  import { type FilterArgs, type PersistenceModelType, type Store, type StoreConfig, StoreMaker } from "./service.js"
10
10
  import { makeUpdateETag } from "./utils.js"
@@ -163,7 +163,7 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
163
163
  .pipe(
164
164
  // Effect.tap(() => logQuery(query, defaultValues)),
165
165
  Effect.map(query.memory),
166
- withDbSpan({
166
+ annotateDb({
167
167
  operation: "queryRaw",
168
168
  system: "memory",
169
169
  collection: modelName,
@@ -172,7 +172,7 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
172
172
  })
173
173
  ),
174
174
 
175
- all: all.pipe(withDbSpan({
175
+ all: all.pipe(annotateDb({
176
176
  operation: "all",
177
177
  system: "memory",
178
178
  collection: modelName,
@@ -184,7 +184,7 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
184
184
  .get(store)
185
185
  .pipe(
186
186
  Effect.map((_) => Option.fromNullishOr(_.get(id))),
187
- withDbSpan({
187
+ annotateDb({
188
188
  operation: "find",
189
189
  system: "memory",
190
190
  collection: modelName,
@@ -198,7 +198,7 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
198
198
  .pipe(
199
199
  Effect.tap(() => logQuery(f, defaultValues)),
200
200
  Effect.map(memFilter(f)),
201
- withDbSpan({
201
+ annotateDb({
202
202
  operation: "filter",
203
203
  system: "memory",
204
204
  collection: modelName,
@@ -219,7 +219,7 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
219
219
  )
220
220
  ),
221
221
  withPermit,
222
- withDbSpan({
222
+ annotateDb({
223
223
  operation: "set",
224
224
  system: "memory",
225
225
  collection: modelName,
@@ -237,7 +237,7 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
237
237
  Effect.filterOrFail((_) => _.length <= 100, () => "BatchRemove: a batch may not exceed 100 items"),
238
238
  Effect.orDie,
239
239
  Effect.andThen(batchRemove),
240
- withDbSpan({
240
+ annotateDb({
241
241
  operation: "batchRemove",
242
242
  system: "memory",
243
243
  collection: modelName,
@@ -255,7 +255,7 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
255
255
  Effect.filterOrFail((_) => _.length <= 100, () => "BatchSet: a batch may not exceed 100 items"),
256
256
  Effect.orDie,
257
257
  Effect.andThen(batchSet),
258
- withDbSpan({
258
+ annotateDb({
259
259
  operation: "batchSet",
260
260
  system: "memory",
261
261
  collection: modelName,
@@ -267,7 +267,7 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
267
267
  bulkSet: flow(
268
268
  batchSet,
269
269
  (_) =>
270
- _.pipe(withDbSpan({
270
+ _.pipe(annotateDb({
271
271
  operation: "bulkSet",
272
272
  system: "memory",
273
273
  collection: modelName,
@@ -6,7 +6,7 @@ import { SqlClient } from "effect/unstable/sql"
6
6
  import { OptimisticConcurrencyException } from "../../errors.js"
7
7
  import { InfraLogger } from "../../logger.js"
8
8
  import type { FieldValues } from "../../Model/filter/types.js"
9
- import { withDbSpan } from "../../otel.js"
9
+ import { annotateDb } from "../../otel.js"
10
10
  import { storeId } from "../Memory.js"
11
11
  import { type FilterArgs, type PersistenceModelType, type StorageConfig, type Store, type StoreConfig, StoreMaker } from "../service.js"
12
12
  import { makeETag } from "../utils.js"
@@ -167,7 +167,7 @@ const makePgStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
167
167
  return exec(sqlText, [ns])
168
168
  .pipe(
169
169
  Effect.map((rows) => (rows as any[]).map((r) => parseRow<Encoded>(r, idKey, defaultValues))),
170
- withDbSpan({
170
+ annotateDb({
171
171
  operation: "all",
172
172
  system: "postgresql",
173
173
  collection: tableName,
@@ -191,7 +191,7 @@ const makePgStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
191
191
  ? Option.some(parseRow<Encoded>(row, idKey, defaultValues))
192
192
  : Option.none()
193
193
  }),
194
- withDbSpan({
194
+ annotateDb({
195
195
  operation: "find",
196
196
  system: "postgresql",
197
197
  collection: tableName,
@@ -255,7 +255,7 @@ const makePgStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
255
255
  })
256
256
  )
257
257
  ),
258
- withDbSpan({
258
+ annotateDb({
259
259
  operation: "filter",
260
260
  system: "postgresql",
261
261
  collection: tableName,
@@ -269,7 +269,7 @@ const makePgStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
269
269
  set: (e) =>
270
270
  resolveNamespace.pipe(Effect.flatMap((ns) =>
271
271
  setInternal(e, ns).pipe(
272
- withDbSpan({
272
+ annotateDb({
273
273
  operation: "set",
274
274
  system: "postgresql",
275
275
  collection: tableName,
@@ -283,7 +283,7 @@ const makePgStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
283
283
  batchSet: (items) =>
284
284
  resolveNamespace.pipe(Effect.flatMap((ns) =>
285
285
  bulkSetInternal(items, ns).pipe(
286
- withDbSpan({
286
+ annotateDb({
287
287
  operation: "batchSet",
288
288
  system: "postgresql",
289
289
  collection: tableName,
@@ -296,7 +296,7 @@ const makePgStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
296
296
  bulkSet: (items) =>
297
297
  resolveNamespace.pipe(Effect.flatMap((ns) =>
298
298
  bulkSetInternal(items, ns).pipe(
299
- withDbSpan({
299
+ annotateDb({
300
300
  operation: "bulkSet",
301
301
  system: "postgresql",
302
302
  collection: tableName,
@@ -314,7 +314,7 @@ const makePgStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
314
314
  return exec(sqlText, [...ids, ns])
315
315
  .pipe(
316
316
  Effect.asVoid,
317
- withDbSpan({
317
+ annotateDb({
318
318
  operation: "batchRemove",
319
319
  system: "postgresql",
320
320
  collection: tableName,
@@ -329,7 +329,7 @@ const makePgStore = Effect.fnUntraced(function*({ prefix }: StorageConfig) {
329
329
  queryRaw: (query) =>
330
330
  s.all.pipe(
331
331
  Effect.map(query.memory),
332
- withDbSpan({
332
+ annotateDb({
333
333
  operation: "queryRaw",
334
334
  system: "postgresql",
335
335
  collection: tableName,
package/src/Store/SQL.ts CHANGED
@@ -7,7 +7,7 @@ import { SqlClient } from "effect/unstable/sql"
7
7
  import { OptimisticConcurrencyException } from "../errors.js"
8
8
  import { InfraLogger } from "../logger.js"
9
9
  import type { FieldValues } from "../Model/filter/types.js"
10
- import { type DbSystem, withDbSpan } from "../otel.js"
10
+ import { annotateDb, type DbSystem } from "../otel.js"
11
11
  import { storeId } from "./Memory.js"
12
12
  import { type FilterArgs, type PersistenceModelType, type StorageConfig, type Store, type StoreConfig, StoreMaker } from "./service.js"
13
13
  import { buildWhereSQLQuery, logQuery, type SQLDialect, sqliteDialect } from "./SQL/query.js"
@@ -181,7 +181,7 @@ function makeSQLStoreInt(system: DbSystem, dialect: SQLDialect, jsonColumnType:
181
181
  return exec(sqlText, [ns])
182
182
  .pipe(
183
183
  Effect.map((rows) => (rows as any[]).map((r) => parseRow<Encoded>(r, idKey, defaultValues))),
184
- withDbSpan({
184
+ annotateDb({
185
185
  operation: "all",
186
186
  system,
187
187
  collection: tableName,
@@ -205,7 +205,7 @@ function makeSQLStoreInt(system: DbSystem, dialect: SQLDialect, jsonColumnType:
205
205
  ? Option.some(parseRow<Encoded>(row, idKey, defaultValues))
206
206
  : Option.none()
207
207
  }),
208
- withDbSpan({
208
+ annotateDb({
209
209
  operation: "find",
210
210
  system,
211
211
  collection: tableName,
@@ -290,7 +290,7 @@ function makeSQLStoreInt(system: DbSystem, dialect: SQLDialect, jsonColumnType:
290
290
  })
291
291
  )
292
292
  ),
293
- withDbSpan({
293
+ annotateDb({
294
294
  operation: "filter",
295
295
  system,
296
296
  collection: tableName,
@@ -304,7 +304,7 @@ function makeSQLStoreInt(system: DbSystem, dialect: SQLDialect, jsonColumnType:
304
304
  set: (e) =>
305
305
  resolveNamespace.pipe(Effect.flatMap((ns) =>
306
306
  setInternal(e, ns).pipe(
307
- withDbSpan({
307
+ annotateDb({
308
308
  operation: "set",
309
309
  system,
310
310
  collection: tableName,
@@ -318,7 +318,7 @@ function makeSQLStoreInt(system: DbSystem, dialect: SQLDialect, jsonColumnType:
318
318
  batchSet: (items) =>
319
319
  resolveNamespace.pipe(Effect.flatMap((ns) =>
320
320
  bulkSetInternal(items, ns).pipe(
321
- withDbSpan({
321
+ annotateDb({
322
322
  operation: "batchSet",
323
323
  system,
324
324
  collection: tableName,
@@ -331,7 +331,7 @@ function makeSQLStoreInt(system: DbSystem, dialect: SQLDialect, jsonColumnType:
331
331
  bulkSet: (items) =>
332
332
  resolveNamespace.pipe(Effect.flatMap((ns) =>
333
333
  bulkSetInternal(items, ns).pipe(
334
- withDbSpan({
334
+ annotateDb({
335
335
  operation: "bulkSet",
336
336
  system,
337
337
  collection: tableName,
@@ -348,7 +348,7 @@ function makeSQLStoreInt(system: DbSystem, dialect: SQLDialect, jsonColumnType:
348
348
  return exec(sqlText, [...ids, ns])
349
349
  .pipe(
350
350
  Effect.asVoid,
351
- withDbSpan({
351
+ annotateDb({
352
352
  operation: "batchRemove",
353
353
  system,
354
354
  collection: tableName,
@@ -363,7 +363,7 @@ function makeSQLStoreInt(system: DbSystem, dialect: SQLDialect, jsonColumnType:
363
363
  queryRaw: (query) =>
364
364
  s.all.pipe(
365
365
  Effect.map(query.memory),
366
- withDbSpan({
366
+ annotateDb({
367
367
  operation: "queryRaw",
368
368
  system,
369
369
  collection: tableName,
@@ -526,7 +526,7 @@ function makeSQLiteStorePerNs(
526
526
  return exec(ns, sqlText)
527
527
  .pipe(
528
528
  Effect.map((rows) => (rows as any[]).map((r) => parseRow<Encoded>(r, idKey, defaultValues))),
529
- withDbSpan({
529
+ annotateDb({
530
530
  operation: "all",
531
531
  system: "sqlite",
532
532
  collection: tableName,
@@ -549,7 +549,7 @@ function makeSQLiteStorePerNs(
549
549
  ? Option.some(parseRow<Encoded>(row, idKey, defaultValues))
550
550
  : Option.none()
551
551
  }),
552
- withDbSpan({
552
+ annotateDb({
553
553
  operation: "find",
554
554
  system: "sqlite",
555
555
  collection: tableName,
@@ -613,7 +613,7 @@ function makeSQLiteStorePerNs(
613
613
  })
614
614
  )
615
615
  ),
616
- withDbSpan({
616
+ annotateDb({
617
617
  operation: "filter",
618
618
  system: "sqlite",
619
619
  collection: tableName,
@@ -627,7 +627,7 @@ function makeSQLiteStorePerNs(
627
627
  set: (e) =>
628
628
  resolveNamespace.pipe(Effect.flatMap((ns) =>
629
629
  setInternal(e, ns).pipe(
630
- withDbSpan({
630
+ annotateDb({
631
631
  operation: "set",
632
632
  system: "sqlite",
633
633
  collection: tableName,
@@ -641,7 +641,7 @@ function makeSQLiteStorePerNs(
641
641
  batchSet: (items) =>
642
642
  resolveNamespace.pipe(Effect.flatMap((ns) =>
643
643
  bulkSetInternal(items, ns).pipe(
644
- withDbSpan({
644
+ annotateDb({
645
645
  operation: "batchSet",
646
646
  system: "sqlite",
647
647
  collection: tableName,
@@ -654,7 +654,7 @@ function makeSQLiteStorePerNs(
654
654
  bulkSet: (items) =>
655
655
  resolveNamespace.pipe(Effect.flatMap((ns) =>
656
656
  bulkSetInternal(items, ns).pipe(
657
- withDbSpan({
657
+ annotateDb({
658
658
  operation: "bulkSet",
659
659
  system: "sqlite",
660
660
  collection: tableName,
@@ -671,7 +671,7 @@ function makeSQLiteStorePerNs(
671
671
  return exec(ns, sqlText, [...ids])
672
672
  .pipe(
673
673
  Effect.asVoid,
674
- withDbSpan({
674
+ annotateDb({
675
675
  operation: "batchRemove",
676
676
  system: "sqlite",
677
677
  collection: tableName,
@@ -686,7 +686,7 @@ function makeSQLiteStorePerNs(
686
686
  queryRaw: (query) =>
687
687
  s.all.pipe(
688
688
  Effect.map(query.memory),
689
- withDbSpan({
689
+ annotateDb({
690
690
  operation: "queryRaw",
691
691
  system: "sqlite",
692
692
  collection: tableName,