MCPcopy Index your code
hub / github.com/Effect-TS/effect / fromMetricKey

Function fromMetricKey

packages/effect/src/internal/metric.ts:117–159  ·  view source on GitHub ↗
(
  key: MetricKey.MetricKey<Type>
)

Source from the content-addressed store, hash-verified

115
116/** @internal */
117export const fromMetricKey = <Type extends MetricKeyType.MetricKeyType<any, any>>(
118 key: MetricKey.MetricKey<Type>
119): Metric.Metric<
120 Type,
121 MetricKeyType.MetricKeyType.InType<Type>,
122 MetricKeyType.MetricKeyType.OutType<Type>
123> => {
124 let untaggedHook:
125 | MetricHook.MetricHook<
126 MetricKeyType.MetricKeyType.InType<Type>,
127 MetricKeyType.MetricKeyType.OutType<Type>
128 >
129 | undefined
130 const hookCache = new WeakMap<ReadonlyArray<MetricLabel.MetricLabel>, MetricHook.MetricHook<any, any>>()
131
132 const hook = (extraTags: ReadonlyArray<MetricLabel.MetricLabel>): MetricHook.MetricHook<
133 MetricKeyType.MetricKeyType.InType<Type>,
134 MetricKeyType.MetricKeyType.OutType<Type>
135 > => {
136 if (extraTags.length === 0) {
137 if (untaggedHook !== undefined) {
138 return untaggedHook
139 }
140 untaggedHook = globalMetricRegistry.get(key)
141 return untaggedHook
142 }
143
144 let hook = hookCache.get(extraTags)
145 if (hook !== undefined) {
146 return hook
147 }
148 hook = globalMetricRegistry.get(metricKey.taggedWithLabels(key, extraTags))
149 hookCache.set(extraTags, hook)
150 return hook
151 }
152
153 return make(
154 key.keyType,
155 (input, extraTags) => hook(extraTags).update(input),
156 (extraTags) => hook(extraTags).get(),
157 (input, extraTags) => hook(extraTags).modify(input)
158 )
159}
160
161/** @internal */
162export const gauge: {

Callers 5

counterFunction · 0.85
frequencyFunction · 0.85
gaugeFunction · 0.85
histogramFunction · 0.85
summaryTimestampFunction · 0.85

Calls 5

hookFunction · 0.85
makeFunction · 0.70
updateMethod · 0.65
getMethod · 0.65
modifyMethod · 0.65

Tested by

no test coverage detected