@toa.io/extensions.telemetry 1.0.0-alpha.302 → 1.0.0-alpha.304
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.
- package/grafana.md +17 -3
- package/package.json +6 -6
- package/readme.md +38 -7
- package/transpiled/Metrics.d.ts +21 -0
- package/transpiled/Metrics.js +75 -0
- package/transpiled/Metrics.js.map +1 -0
- package/transpiled/aspects.d.ts +12 -0
- package/transpiled/extension.d.ts +2 -1
- package/transpiled/extension.js +28 -4
- package/transpiled/extension.js.map +1 -1
package/grafana.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Grafana stack setup
|
|
2
2
|
|
|
3
|
-
Toa-specific notes for wiring application traces into Tempo, Prometheus and Grafana.
|
|
3
|
+
Toa-specific notes for wiring application traces and metrics into Tempo, Prometheus and Grafana.
|
|
4
4
|
Reference configuration: [`observability/`](../../observability) in the Toa repository.
|
|
5
5
|
|
|
6
6
|
## Local environment
|
|
@@ -8,8 +8,9 @@ Reference configuration: [`observability/`](../../observability) in the Toa repo
|
|
|
8
8
|
The application environment needs:
|
|
9
9
|
|
|
10
10
|
- [Tempo](https://grafana.com/oss/tempo/) with OTLP/HTTP enabled (port `4318`)
|
|
11
|
-
and Prometheus with `--web.enable-remote-write-receiver`
|
|
12
11
|
(see [`tempo.yaml`](../../observability/tempo.yaml) for the metrics-generator wiring)
|
|
12
|
+
- Prometheus with `--web.enable-remote-write-receiver`, which is where Tempo's generator
|
|
13
|
+
writes, and `--web.enable-otlp-receiver`, which is where Toa posts its own metrics
|
|
13
14
|
- Grafana with a Prometheus datasource and a Tempo datasource
|
|
14
15
|
with `serviceMap.datasourceUid` pointing at it
|
|
15
16
|
(see [`grafana-datasources.yaml`](../../observability/grafana-datasources.yaml))
|
|
@@ -25,12 +26,23 @@ telemetry:
|
|
|
25
26
|
console: ~
|
|
26
27
|
otlp:
|
|
27
28
|
endpoint: http://localhost:4318
|
|
29
|
+
metrics:
|
|
30
|
+
exporters:
|
|
31
|
+
otlp:
|
|
32
|
+
endpoint: http://localhost:9090/api/v1/otlp
|
|
28
33
|
```
|
|
29
34
|
|
|
35
|
+
[`dashboards/toa.json`](../../observability/dashboards/toa.json) reads those metrics: operations,
|
|
36
|
+
exposition, the outbox, the broker, storage, what is in flight and the event loop.
|
|
37
|
+
|
|
30
38
|
## Production
|
|
31
39
|
|
|
32
|
-
- Point `exporters.otlp.endpoint` at any OTLP/HTTP receiver (`/v1/traces` is appended)
|
|
40
|
+
- Point `traces.exporters.otlp.endpoint` at any OTLP/HTTP receiver (`/v1/traces` is appended),
|
|
41
|
+
and `metrics.exporters.otlp.endpoint` at one that takes metrics (`/v1/metrics` is appended).
|
|
33
42
|
Use `headers` for authentication (e.g. Grafana Cloud `Authorization: Basic ...`).
|
|
43
|
+
- Metrics carry the context as `service.namespace` and the environment as
|
|
44
|
+
`deployment.environment.name`, so several products and several environments reaching one
|
|
45
|
+
backend separate by `job` rather than by metric name.
|
|
34
46
|
- Skip the usual per-process `service.name` setup (`OTEL_SERVICE_NAME` and the like):
|
|
35
47
|
Toa attributes spans to component ids (`default.orders`) or `exposition` automatically,
|
|
36
48
|
even when multiple components run in a single process.
|
|
@@ -43,6 +55,8 @@ telemetry:
|
|
|
43
55
|
are the knobs controlling the exported volume.
|
|
44
56
|
- Spans are sent in batches (512 spans or every 5 seconds) and flushed on process exit;
|
|
45
57
|
abrupt termination (`SIGKILL`) may lose the last batch.
|
|
58
|
+
- Metrics are cumulative, so a lost export costs resolution and not totals: the next one carries
|
|
59
|
+
what the lost one would have.
|
|
46
60
|
|
|
47
61
|
## Trace to logs
|
|
48
62
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/extensions.telemetry",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.304",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Toa Telemetry extension",
|
|
6
6
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"transpile": "tsc"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@toa.io/core": "1.0.0-alpha.
|
|
33
|
-
"@toa.io/definitions": "1.0.0-alpha.
|
|
34
|
-
"@toa.io/generic": "1.0.0-alpha.
|
|
35
|
-
"openspan": "1.0.0-alpha.
|
|
32
|
+
"@toa.io/core": "1.0.0-alpha.304",
|
|
33
|
+
"@toa.io/definitions": "1.0.0-alpha.304",
|
|
34
|
+
"@toa.io/generic": "1.0.0-alpha.304",
|
|
35
|
+
"openspan": "1.0.0-alpha.304"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a95a5a5a64922b11b23142d4acbcee1331ed31aa"
|
|
38
38
|
}
|
package/readme.md
CHANGED
|
@@ -210,6 +210,38 @@ of the tracing backend.
|
|
|
210
210
|
|
|
211
211
|
See [Grafana stack setup](grafana.md) for local and production wiring.
|
|
212
212
|
|
|
213
|
+
## Metrics
|
|
214
|
+
|
|
215
|
+
Metrics are recorded whether or not the trace is sampled. Nothing is measured until the `metrics`
|
|
216
|
+
annotation is declared, and nothing leaves the process until an exporter is configured under it.
|
|
217
|
+
|
|
218
|
+
```yaml
|
|
219
|
+
# context.toa.yaml
|
|
220
|
+
|
|
221
|
+
telemetry:
|
|
222
|
+
metrics:
|
|
223
|
+
interval: 15000 # collection and export period, the default
|
|
224
|
+
exporters:
|
|
225
|
+
otlp:
|
|
226
|
+
endpoint: http://prometheus:9090/api/v1/otlp # POSTs to {endpoint}/v1/metrics
|
|
227
|
+
timeout: 5000 # request timeout, the default
|
|
228
|
+
cooldown: 30000 # how long to drop series for after a failure, the default
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
A missing or unavailable endpoint is reported with a single warning and series are dropped until it
|
|
232
|
+
recovers, the same as for spans.
|
|
233
|
+
|
|
234
|
+
A component records the metrics its manifest declares, through the `metrics` Context Aspect:
|
|
235
|
+
|
|
236
|
+
```javascript
|
|
237
|
+
async function convert(input, context) {
|
|
238
|
+
context.metrics.conversions.add(1, { currency: input.currency })
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
See [Metrics](/documentation/metrics.md) for the declaration, the three instrument types, and every
|
|
243
|
+
metric the runtime records.
|
|
244
|
+
|
|
213
245
|
## Logs best practices
|
|
214
246
|
|
|
215
247
|
Use constant messages and attributes to facilitate log analysis.
|
|
@@ -234,9 +266,7 @@ Logs are not comments or documentation, nor are they a replacement for them.
|
|
|
234
266
|
:-1: Don't:
|
|
235
267
|
|
|
236
268
|
```javascript
|
|
237
|
-
context.logs.error(
|
|
238
|
-
'Failed to send the email, please check the email server configuration'
|
|
239
|
-
)
|
|
269
|
+
context.logs.error('Failed to send the email, please check the email server configuration')
|
|
240
270
|
```
|
|
241
271
|
|
|
242
272
|
:+1: Do:
|
|
@@ -244,7 +274,7 @@ context.logs.error(
|
|
|
244
274
|
```javascript
|
|
245
275
|
context.logs.error('Failed to send the email', {
|
|
246
276
|
reason: 'SMTP error',
|
|
247
|
-
status: response.statusCode
|
|
277
|
+
status: response.statusCode,
|
|
248
278
|
})
|
|
249
279
|
```
|
|
250
280
|
|
|
@@ -285,7 +315,7 @@ context.logs.debug('Configuration', context.configuration)
|
|
|
285
315
|
```javascript
|
|
286
316
|
context.logs.debug('Limits', {
|
|
287
317
|
max: context.configuration.limits.max,
|
|
288
|
-
min: context.configuration.limits.min
|
|
318
|
+
min: context.configuration.limits.min,
|
|
289
319
|
})
|
|
290
320
|
```
|
|
291
321
|
|
|
@@ -317,8 +347,9 @@ telemetry:
|
|
|
317
347
|
|
|
318
348
|
The exposition gateway is a separate service process with a nested identity composition in-process.
|
|
319
349
|
|
|
320
|
-
It exposes its own `GET /.ready` on
|
|
350
|
+
It exposes its own `GET /.ready` on a port of its own, **`8004`**, because the kubelet probes over
|
|
351
|
+
HTTP/1.1 and the gateway port answers nothing else when it serves h2c.
|
|
321
352
|
Deployment sets `TOA_TELEMETRY_READY=false` for that service so the nested composition does **not**
|
|
322
|
-
start a second probe. Kubernetes probes the gateway on **
|
|
353
|
+
start a second probe. Kubernetes probes the gateway on **8004**; composition Deployments on **8001**.
|
|
323
354
|
|
|
324
355
|
See [exposition ready probe](../exposition/readme.md#ready-probe).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Connector } from '@toa.io/core';
|
|
2
|
+
import type { Counter, Gauge, Histogram } from 'openspan';
|
|
3
|
+
import type { Locator } from '@toa.io/core';
|
|
4
|
+
import type { extensions } from '@toa.io/core/types';
|
|
5
|
+
import type { Declaration } from '@toa.io/definitions/extensions.telemetry';
|
|
6
|
+
/**
|
|
7
|
+
* The instruments a component declared, by the name it declared them under.
|
|
8
|
+
*
|
|
9
|
+
* Built at construction rather than per call, and named after the component: two components that
|
|
10
|
+
* both declare `conversions` mean two different things by it, and one series name would merge
|
|
11
|
+
* them into one series of two meanings.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Metrics extends Connector implements extensions.Aspect {
|
|
14
|
+
readonly name = "metrics";
|
|
15
|
+
private readonly instruments;
|
|
16
|
+
constructor(locator: Locator, declaration: Declaration);
|
|
17
|
+
invoke(): Instruments;
|
|
18
|
+
}
|
|
19
|
+
type Recorder = Counter | Gauge | Histogram;
|
|
20
|
+
type Instruments = Record<string, Recorder>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { registry } from 'openspan';
|
|
2
|
+
import { Connector, exceptions } from '@toa.io/core';
|
|
3
|
+
/**
|
|
4
|
+
* The instruments a component declared, by the name it declared them under.
|
|
5
|
+
*
|
|
6
|
+
* Built at construction rather than per call, and named after the component: two components that
|
|
7
|
+
* both declare `conversions` mean two different things by it, and one series name would merge
|
|
8
|
+
* them into one series of two meanings.
|
|
9
|
+
*/
|
|
10
|
+
export class Metrics extends Connector {
|
|
11
|
+
name = 'metrics';
|
|
12
|
+
instruments;
|
|
13
|
+
constructor(locator, declaration) {
|
|
14
|
+
super();
|
|
15
|
+
this.instruments = guard(create(locator, declaration));
|
|
16
|
+
}
|
|
17
|
+
invoke() {
|
|
18
|
+
return this.instruments;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A name the manifest does not declare raises rather than answering `undefined`. It is a literal
|
|
23
|
+
* in the source, so it is wrong on every invocation of that path and on every retry — and
|
|
24
|
+
* `Misuse` is classified permanent, so where nobody is waiting the message is parked on its first
|
|
25
|
+
* delivery instead of being tried again for minutes.
|
|
26
|
+
*
|
|
27
|
+
* What is asked of every object rather than of this one answers `undefined`: a symbol, anything
|
|
28
|
+
* `Object.prototype` has, and the two names a language protocol reads — `then`, which would make
|
|
29
|
+
* awaiting this object raise, and `toJSON`, which would make logging it raise. None of them is a
|
|
30
|
+
* metric anybody meant to declare.
|
|
31
|
+
*/
|
|
32
|
+
function guard(instruments) {
|
|
33
|
+
return new Proxy(instruments, {
|
|
34
|
+
get(target, property) {
|
|
35
|
+
if (typeof property === 'symbol')
|
|
36
|
+
return undefined;
|
|
37
|
+
const instrument = target[property];
|
|
38
|
+
if (instrument !== undefined)
|
|
39
|
+
return instrument;
|
|
40
|
+
if (property in Object.prototype || PROTOCOL.has(property))
|
|
41
|
+
return undefined;
|
|
42
|
+
throw new exceptions.MisuseException(`Metric '${property}' is not declared`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const PROTOCOL = new Set(['then', 'toJSON']);
|
|
47
|
+
function create(locator, declaration) {
|
|
48
|
+
const meters = registry();
|
|
49
|
+
const instruments = {};
|
|
50
|
+
for (const [name, instrument] of Object.entries(declaration.metrics ?? {})) {
|
|
51
|
+
const series = `${locator.id}.${name}`;
|
|
52
|
+
const labels = keys(instrument);
|
|
53
|
+
if (instrument.type === 'histogram')
|
|
54
|
+
instruments[name] = meters.histogram(series, options(instrument), labels);
|
|
55
|
+
else if (instrument.type === 'gauge')
|
|
56
|
+
instruments[name] = meters.gauge(series, labels);
|
|
57
|
+
else
|
|
58
|
+
instruments[name] = meters.counter(series, labels);
|
|
59
|
+
}
|
|
60
|
+
return instruments;
|
|
61
|
+
}
|
|
62
|
+
function options(instrument) {
|
|
63
|
+
const declared = { buckets: instrument.buckets };
|
|
64
|
+
if (instrument.unit !== undefined)
|
|
65
|
+
declared.unit = instrument.unit;
|
|
66
|
+
return declared;
|
|
67
|
+
}
|
|
68
|
+
/** A label value travels as a string, because that is what a label is. */
|
|
69
|
+
function keys(instrument) {
|
|
70
|
+
const labels = {};
|
|
71
|
+
for (const [key, values] of Object.entries(instrument.labels ?? {}))
|
|
72
|
+
labels[key] = values === null ? null : values.map(String);
|
|
73
|
+
return labels;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=Metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Metrics.js","sourceRoot":"","sources":["../source/Metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAMpD;;;;;;GAMG;AACH,MAAM,OAAO,OAAQ,SAAQ,SAAS;IACpB,IAAI,GAAG,SAAS,CAAA;IAEf,WAAW,CAAa;IAEzC,YAAmB,OAAgB,EAAE,WAAwB;QAC3D,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAA;IACxD,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,SAAS,KAAK,CAAC,WAAqC;IAClD,OAAO,IAAI,KAAK,CAAC,WAAW,EAAE;QAC5B,GAAG,CAAC,MAAM,EAAE,QAAQ;YAClB,IAAI,OAAO,QAAQ,KAAK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A;IACzD,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,SAAS,OAAO,CAAC,UAAsB;IACrC,MAAM,QAAQ,GAAyC,EAAE,OAAO,EAAE,UAAU,CAAC,OAAQ,EAAE,CAAA;IAEvF,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS;QAAE,QAAQ,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;IAElE,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,0EAA0E;AAC1E,SAAS,IAAI,CAAC,UAAsB;IAClC,MAAM,MAAM,GAAW,EAAE,CAAA;IAEzB,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,IAAI,EAAE,CAAC;QACjE,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAE3D,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/transpiled/aspects.d.ts
CHANGED
|
@@ -8,3 +8,15 @@ export interface Span {
|
|
|
8
8
|
<T>(name: string, task: () => T | Promise<T>): Promise<T>;
|
|
9
9
|
<T>(name: string, attributes: object, task: () => T | Promise<T>): Promise<T>;
|
|
10
10
|
}
|
|
11
|
+
/** The instruments this component declared in its manifest, by the name each was declared under. */
|
|
12
|
+
export type Metrics = Record<string, Counter | Gauge | Histogram>;
|
|
13
|
+
export interface Counter {
|
|
14
|
+
add: (value?: number, labels?: Record<string, unknown>) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface Gauge {
|
|
17
|
+
set: (value: number, labels?: Record<string, unknown>) => void;
|
|
18
|
+
add: (delta: number, labels?: Record<string, unknown>) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface Histogram {
|
|
21
|
+
record: (value: number, labels?: Record<string, unknown>) => void;
|
|
22
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Declaration } from '@toa.io/definitions/extensions.telemetry';
|
|
1
2
|
import type { Locator } from '@toa.io/core';
|
|
2
3
|
import type { extensions } from '@toa.io/core/types';
|
|
3
4
|
type Resident = extensions.Resident;
|
|
@@ -5,7 +6,7 @@ export declare class Factory implements extensions.Factory {
|
|
|
5
6
|
private readonly logsOptions;
|
|
6
7
|
private readonly ready;
|
|
7
8
|
constructor();
|
|
8
|
-
aspect(locator: Locator): extensions.Aspect[];
|
|
9
|
+
aspect(locator: Locator, declaration: Declaration): extensions.Aspect[];
|
|
9
10
|
/**
|
|
10
11
|
* The probe answers for the process, so it is the process it belongs to — and not whichever
|
|
11
12
|
* composition happens to be nearest, which in a service is the one nested inside it. That is
|
package/transpiled/extension.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { console, traces } from 'openspan';
|
|
1
|
+
import { console, metrics, traces } from 'openspan';
|
|
2
2
|
import { environment } from '@toa.io/generic';
|
|
3
|
-
import { LOGS_PREFIX, TRACES_ENV } from '@toa.io/definitions/extensions.telemetry';
|
|
3
|
+
import { LOGS_PREFIX, METRICS_ENV, TRACES_ENV } from '@toa.io/definitions/extensions.telemetry';
|
|
4
4
|
import { Logs } from './Logs.js';
|
|
5
5
|
import { Span } from './Span.js';
|
|
6
|
+
import { Metrics } from './Metrics.js';
|
|
6
7
|
import { Ready } from './Ready.js';
|
|
7
8
|
export class Factory {
|
|
8
9
|
logsOptions;
|
|
@@ -20,12 +21,14 @@ export class Factory {
|
|
|
20
21
|
if (options.exporters?.otlp !== undefined)
|
|
21
22
|
options.exporters.otlp.service ??= environment.get('TOA_CONTEXT');
|
|
22
23
|
traces(options);
|
|
24
|
+
metrics(measurements());
|
|
23
25
|
this.ready = Ready.create();
|
|
24
26
|
}
|
|
25
|
-
aspect(locator) {
|
|
27
|
+
aspect(locator, declaration) {
|
|
26
28
|
const logs = this.createLogs(locator);
|
|
27
29
|
const span = new Span(locator);
|
|
28
|
-
|
|
30
|
+
const metrics = new Metrics(locator, declaration ?? {});
|
|
31
|
+
return [logs, span, metrics];
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
34
|
* The probe answers for the process, so it is the process it belongs to — and not whichever
|
|
@@ -55,6 +58,27 @@ export class Factory {
|
|
|
55
58
|
* `extensions/exposition/source/Factory.ts` says the same thing for the gateway process,
|
|
56
59
|
* which boots without this extension.
|
|
57
60
|
*/
|
|
61
|
+
/**
|
|
62
|
+
* What the series say they came from. The metric names are the same in every deployment, so what
|
|
63
|
+
* tells two products apart in one backend is the resource: the context is the namespace, and the
|
|
64
|
+
* environment is beside it.
|
|
65
|
+
*
|
|
66
|
+
* Nothing when the annotation is absent, which is what turns measuring off: there is no console
|
|
67
|
+
* exporter for this signal, so a local run measures only where it was asked to.
|
|
68
|
+
*/
|
|
69
|
+
function measurements() {
|
|
70
|
+
const env = environment.get(METRICS_ENV);
|
|
71
|
+
if (env === undefined)
|
|
72
|
+
return undefined;
|
|
73
|
+
const options = JSON.parse(env);
|
|
74
|
+
options.prefix ??= 'toa';
|
|
75
|
+
if (options.exporters?.otlp !== undefined) {
|
|
76
|
+
const resource = (options.exporters.otlp.resource ??= {});
|
|
77
|
+
resource['service.namespace'] ??= environment.get('TOA_CONTEXT');
|
|
78
|
+
resource['deployment.environment.name'] ??= environment.get('TOA_ENV');
|
|
79
|
+
}
|
|
80
|
+
return options;
|
|
81
|
+
}
|
|
58
82
|
function development() {
|
|
59
83
|
const local = environment.get('TOA_DEV') === '1' || environment.get('TOA_BOOT_TRACE') === '1';
|
|
60
84
|
return local ? { exporters: { console: {} } } : {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../source/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../source/extension.ts"],"names":[],"mappings":"AAAA,OAAO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