@internal
| 20 | |
| 21 | /** @internal */ |
| 22 | class MetricRegistryImpl implements MetricRegistry.MetricRegistry { |
| 23 | readonly [MetricRegistryTypeId]: MetricRegistry.MetricRegistryTypeId = MetricRegistryTypeId |
| 24 | |
| 25 | private map = MutableHashMap.empty< |
| 26 | MetricKey.MetricKey<MetricKeyType.MetricKeyType.Untyped>, |
| 27 | MetricHook.MetricHook.Root |
| 28 | >() |
| 29 | |
| 30 | snapshot(): Array<MetricPair.MetricPair.Untyped> { |
| 31 | const result: Array<MetricPair.MetricPair.Untyped> = [] |
| 32 | for (const [key, hook] of this.map) { |
| 33 | result.push(metricPair.unsafeMake(key, hook.get())) |
| 34 | } |
| 35 | return result |
| 36 | } |
| 37 | |
| 38 | get<Type extends MetricKeyType.MetricKeyType<any, any>>( |
| 39 | key: MetricKey.MetricKey<Type> |
| 40 | ): MetricHook.MetricHook< |
| 41 | MetricKeyType.MetricKeyType.InType<typeof key["keyType"]>, |
| 42 | MetricKeyType.MetricKeyType.OutType<typeof key["keyType"]> |
| 43 | > { |
| 44 | const hook = pipe( |
| 45 | this.map, |
| 46 | MutableHashMap.get(key as MetricKey.MetricKey<MetricKeyType.MetricKeyType.Untyped>), |
| 47 | Option.getOrUndefined |
| 48 | ) |
| 49 | if (hook == null) { |
| 50 | if (metricKeyType.isCounterKey(key.keyType)) { |
| 51 | return this.getCounter(key as unknown as MetricKey.MetricKey.Counter<any>) as any |
| 52 | } |
| 53 | if (metricKeyType.isGaugeKey(key.keyType)) { |
| 54 | return this.getGauge(key as unknown as MetricKey.MetricKey.Gauge<any>) as any |
| 55 | } |
| 56 | if (metricKeyType.isFrequencyKey(key.keyType)) { |
| 57 | return this.getFrequency(key as unknown as MetricKey.MetricKey.Frequency) as any |
| 58 | } |
| 59 | if (metricKeyType.isHistogramKey(key.keyType)) { |
| 60 | return this.getHistogram(key as unknown as MetricKey.MetricKey.Histogram) as any |
| 61 | } |
| 62 | if (metricKeyType.isSummaryKey(key.keyType)) { |
| 63 | return this.getSummary(key as unknown as MetricKey.MetricKey.Summary) as any |
| 64 | } |
| 65 | throw new Error( |
| 66 | "BUG: MetricRegistry.get - unknown MetricKeyType - please report an issue at https://github.com/Effect-TS/effect/issues" |
| 67 | ) |
| 68 | } else { |
| 69 | return hook as any |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | getCounter<A extends (number | bigint)>(key: MetricKey.MetricKey.Counter<A>): MetricHook.MetricHook.Counter<A> { |
| 74 | let value = pipe( |
| 75 | this.map, |
| 76 | MutableHashMap.get(key as MetricKey.MetricKey<MetricKeyType.MetricKeyType.Untyped>), |
| 77 | Option.getOrUndefined |
| 78 | ) |
| 79 | if (value == null) { |
nothing calls this directly
no outgoing calls
no test coverage detected