@twin.org/telemetry-connector-opentelemetry 0.0.3-next.10
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/README.md +21 -0
- package/dist/es/index.js +9 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IOpenTelemetryPrometheusReaderConfig.js +2 -0
- package/dist/es/models/IOpenTelemetryPrometheusReaderConfig.js.map +1 -0
- package/dist/es/models/IOpenTelemetryReaderConfig.js +3 -0
- package/dist/es/models/IOpenTelemetryReaderConfig.js.map +1 -0
- package/dist/es/models/IOpenTelemetryTelemetryConnectorConfig.js +2 -0
- package/dist/es/models/IOpenTelemetryTelemetryConnectorConfig.js.map +1 -0
- package/dist/es/models/IOpenTelemetryTelemetryConnectorConstructorOptions.js +2 -0
- package/dist/es/models/IOpenTelemetryTelemetryConnectorConstructorOptions.js.map +1 -0
- package/dist/es/models/openTelemetryReaderTypes.js +13 -0
- package/dist/es/models/openTelemetryReaderTypes.js.map +1 -0
- package/dist/es/openTelemetryTelemetryConnector.js +307 -0
- package/dist/es/openTelemetryTelemetryConnector.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/models/IOpenTelemetryPrometheusReaderConfig.d.ts +31 -0
- package/dist/types/models/IOpenTelemetryReaderConfig.d.ts +6 -0
- package/dist/types/models/IOpenTelemetryTelemetryConnectorConfig.d.ts +24 -0
- package/dist/types/models/IOpenTelemetryTelemetryConnectorConstructorOptions.d.ts +27 -0
- package/dist/types/models/openTelemetryReaderTypes.d.ts +13 -0
- package/dist/types/openTelemetryTelemetryConnector.d.ts +122 -0
- package/docs/changelog.md +100 -0
- package/docs/examples.md +172 -0
- package/docs/reference/classes/OpenTelemetryTelemetryConnector.md +364 -0
- package/docs/reference/index.md +20 -0
- package/docs/reference/interfaces/IOpenTelemetryPrometheusReaderConfig.md +63 -0
- package/docs/reference/interfaces/IOpenTelemetryTelemetryConnectorConfig.md +45 -0
- package/docs/reference/interfaces/IOpenTelemetryTelemetryConnectorConstructorOptions.md +50 -0
- package/docs/reference/type-aliases/IOpenTelemetryReaderConfig.md +6 -0
- package/docs/reference/type-aliases/OpenTelemetryReaderTypes.md +5 -0
- package/docs/reference/variables/OpenTelemetryReaderTypes.md +13 -0
- package/locales/en.json +13 -0
- package/package.json +70 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { type ITelemetryConnector, type ITelemetryMetric, type ITelemetryMetricValue, MetricCounterOperation, MetricType } from "@twin.org/telemetry-models";
|
|
2
|
+
import type { IOpenTelemetryTelemetryConnectorConstructorOptions } from "./models/IOpenTelemetryTelemetryConnectorConstructorOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Class for performing telemetry operations using OpenTelemetry instruments.
|
|
5
|
+
* Metric definitions and value history are persisted via an internal
|
|
6
|
+
* EntityStorageTelemetryConnector instance created at construction time.
|
|
7
|
+
* Call `start()` to initialise the MeterProvider and exporters; metrics can be
|
|
8
|
+
* created and queried before start() — OTEL forwarding is simply skipped until
|
|
9
|
+
* the MeterProvider is running.
|
|
10
|
+
*/
|
|
11
|
+
export declare class OpenTelemetryTelemetryConnector implements ITelemetryConnector {
|
|
12
|
+
/**
|
|
13
|
+
* The namespace supported by the telemetry connector.
|
|
14
|
+
*/
|
|
15
|
+
static readonly NAMESPACE: string;
|
|
16
|
+
/**
|
|
17
|
+
* Runtime name for the class.
|
|
18
|
+
*/
|
|
19
|
+
static readonly CLASS_NAME: string;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new instance of OpenTelemetryTelemetryConnector.
|
|
22
|
+
* Eagerly constructs the inner EntityStorageTelemetryConnector — if the required
|
|
23
|
+
* entity storage types are not registered this constructor will throw (fail fast).
|
|
24
|
+
* @param options The options for the connector.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options?: IOpenTelemetryTelemetryConnectorConstructorOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Returns the class name of the component.
|
|
29
|
+
* @returns The class name of the component.
|
|
30
|
+
*/
|
|
31
|
+
className(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Initialise the MeterProvider and configured exporters.
|
|
34
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
35
|
+
* @returns Nothing.
|
|
36
|
+
*/
|
|
37
|
+
start(nodeLoggingComponentType?: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Shut down the MeterProvider and release resources.
|
|
40
|
+
* Calling stop() on a connector that has not been started is a no-op.
|
|
41
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
42
|
+
* @returns Nothing.
|
|
43
|
+
*/
|
|
44
|
+
stop(nodeLoggingComponentType?: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Create a new metric.
|
|
47
|
+
* The definition is always persisted via the inner entity-storage connector.
|
|
48
|
+
* If the MeterProvider is running the corresponding OTEL instrument is also registered.
|
|
49
|
+
* @param metric The metric details.
|
|
50
|
+
* @returns Nothing.
|
|
51
|
+
*/
|
|
52
|
+
createMetric(metric: ITelemetryMetric): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Get the metric details and its most recent value.
|
|
55
|
+
* @param id The metric id.
|
|
56
|
+
* @returns The metric details and its most recent value.
|
|
57
|
+
*/
|
|
58
|
+
getMetric(id: string): Promise<{
|
|
59
|
+
metric: ITelemetryMetric;
|
|
60
|
+
value: ITelemetryMetricValue;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Update the metric metadata.
|
|
64
|
+
* Note: OpenTelemetry instrument descriptors are immutable once created.
|
|
65
|
+
* This method updates the persisted metadata mirror; the description/unit changes
|
|
66
|
+
* are NOT propagated to the registered MeterProvider and will not appear at the
|
|
67
|
+
* OTEL backend (Prometheus, OTLP, etc.).
|
|
68
|
+
* @param metric The metric details (type cannot be changed).
|
|
69
|
+
* @returns Nothing.
|
|
70
|
+
*/
|
|
71
|
+
updateMetric(metric: Omit<ITelemetryMetric, "type">): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Record a metric value.
|
|
74
|
+
* Entity storage always receives the value first and performs all validation.
|
|
75
|
+
* If the MeterProvider is running the measurement is also forwarded to the OTEL instrument.
|
|
76
|
+
* Counter accepts positive integers or "inc".
|
|
77
|
+
* UpDownCounter accepts integers (positive or negative) or "inc"/"dec".
|
|
78
|
+
* Gauge accepts any number.
|
|
79
|
+
* @param id The id of the metric.
|
|
80
|
+
* @param value The value for the operation.
|
|
81
|
+
* @param customData Optional custom data forwarded as OTEL attributes.
|
|
82
|
+
* @returns The id of the new metric value entry.
|
|
83
|
+
*/
|
|
84
|
+
addMetricValue(id: string, value: MetricCounterOperation | number, customData?: {
|
|
85
|
+
[key: string]: unknown;
|
|
86
|
+
}): Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Remove a metric and its persisted value history.
|
|
89
|
+
* Note: OpenTelemetry exposes no API to deregister an instrument from a Meter,
|
|
90
|
+
* so the underlying Counter/UpDownCounter/Gauge remains resident for the lifetime
|
|
91
|
+
* of the process. Re-creating a metric with the same id but a different MetricType
|
|
92
|
+
* is therefore not safe.
|
|
93
|
+
* @param id The id of the metric.
|
|
94
|
+
* @returns Nothing.
|
|
95
|
+
*/
|
|
96
|
+
removeMetric(id: string): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Query the registered metrics, optionally filtered by type.
|
|
99
|
+
* @param type The type of the metric.
|
|
100
|
+
* @param cursor The cursor to request the next page.
|
|
101
|
+
* @param limit Limit the number of entities to return.
|
|
102
|
+
* @returns The matching metrics and an optional cursor for the next page.
|
|
103
|
+
*/
|
|
104
|
+
query(type?: MetricType, cursor?: string, limit?: number): Promise<{
|
|
105
|
+
entities: ITelemetryMetric[];
|
|
106
|
+
cursor?: string;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Query the recorded values for a metric, ordered by most recent first.
|
|
110
|
+
* @param id The id of the metric.
|
|
111
|
+
* @param timeStart The inclusive start time (epoch ms).
|
|
112
|
+
* @param timeEnd The inclusive end time (epoch ms).
|
|
113
|
+
* @param cursor The cursor returned by the previous call.
|
|
114
|
+
* @param limit Limit the number of values to return.
|
|
115
|
+
* @returns The metric details, matching values, and an optional cursor for the next page.
|
|
116
|
+
*/
|
|
117
|
+
queryValues(id: string, timeStart?: number, timeEnd?: number, cursor?: string, limit?: number): Promise<{
|
|
118
|
+
metric: ITelemetryMetric;
|
|
119
|
+
entities: ITelemetryMetricValue[];
|
|
120
|
+
cursor?: string;
|
|
121
|
+
}>;
|
|
122
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.10](https://github.com/iotaledger/twin-telemetry/compare/telemetry-connector-opentelemetry-v0.0.3-next.9...telemetry-connector-opentelemetry-v0.0.3-next.10) (2026-05-20)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **telemetry-connector-opentelemetry:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/telemetry-connector-entity-storage bumped from 0.0.3-next.9 to 0.0.3-next.10
|
|
16
|
+
* @twin.org/telemetry-models bumped from 0.0.3-next.9 to 0.0.3-next.10
|
|
17
|
+
|
|
18
|
+
## [0.0.3-next.9](https://github.com/iotaledger/twin-telemetry/compare/telemetry-connector-opentelemetry-v0.0.3-next.8...telemetry-connector-opentelemetry-v0.0.3-next.9) (2026-05-20)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* add helper and command types ([7166013](https://github.com/iotaledger/twin-telemetry/commit/7166013f8a0693a1d92101cb600c37a1aba66417))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Dependencies
|
|
27
|
+
|
|
28
|
+
* The following workspace dependencies were updated
|
|
29
|
+
* dependencies
|
|
30
|
+
* @twin.org/telemetry-connector-entity-storage bumped from 0.0.3-next.8 to 0.0.3-next.9
|
|
31
|
+
* @twin.org/telemetry-models bumped from 0.0.3-next.8 to 0.0.3-next.9
|
|
32
|
+
|
|
33
|
+
## [0.0.3-next.8](https://github.com/iotaledger/twin-telemetry/compare/telemetry-connector-opentelemetry-v0.0.3-next.7...telemetry-connector-opentelemetry-v0.0.3-next.8) (2026-05-19)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Miscellaneous Chores
|
|
37
|
+
|
|
38
|
+
* **telemetry-connector-opentelemetry:** Synchronize repo versions
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Dependencies
|
|
42
|
+
|
|
43
|
+
* The following workspace dependencies were updated
|
|
44
|
+
* dependencies
|
|
45
|
+
* @twin.org/telemetry-connector-entity-storage bumped from 0.0.3-next.7 to 0.0.3-next.8
|
|
46
|
+
* @twin.org/telemetry-models bumped from 0.0.3-next.7 to 0.0.3-next.8
|
|
47
|
+
|
|
48
|
+
## [0.0.3-next.7](https://github.com/iotaledger/twin-telemetry/compare/telemetry-connector-opentelemetry-v0.0.3-next.6...telemetry-connector-opentelemetry-v0.0.3-next.7) (2026-05-19)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### Features
|
|
52
|
+
|
|
53
|
+
* add metrics producer infrastructure ([#30](https://github.com/iotaledger/twin-telemetry/issues/30)) ([8990b99](https://github.com/iotaledger/twin-telemetry/commit/8990b990d22f331d44562c2781c9b6ddf846db88))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Dependencies
|
|
57
|
+
|
|
58
|
+
* The following workspace dependencies were updated
|
|
59
|
+
* dependencies
|
|
60
|
+
* @twin.org/telemetry-connector-entity-storage bumped from 0.0.3-next.6 to 0.0.3-next.7
|
|
61
|
+
* @twin.org/telemetry-models bumped from 0.0.3-next.6 to 0.0.3-next.7
|
|
62
|
+
|
|
63
|
+
## [0.0.3-next.6](https://github.com/iotaledger/twin-telemetry/compare/telemetry-connector-opentelemetry-v0.0.3-next.5...telemetry-connector-opentelemetry-v0.0.3-next.6) (2026-05-11)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### Features
|
|
67
|
+
|
|
68
|
+
* improve open telemetry config ([8803201](https://github.com/iotaledger/twin-telemetry/commit/8803201611b1799a00cd657e0675f85596c4edce))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Dependencies
|
|
72
|
+
|
|
73
|
+
* The following workspace dependencies were updated
|
|
74
|
+
* dependencies
|
|
75
|
+
* @twin.org/telemetry-connector-entity-storage bumped from 0.0.3-next.5 to 0.0.3-next.6
|
|
76
|
+
* @twin.org/telemetry-models bumped from 0.0.3-next.5 to 0.0.3-next.6
|
|
77
|
+
|
|
78
|
+
## [0.0.3-next.5](https://github.com/iotaledger/twin-telemetry/compare/telemetry-connector-opentelemetry-v0.0.3-next.4...telemetry-connector-opentelemetry-v0.0.3-next.5) (2026-05-11)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### Features
|
|
82
|
+
|
|
83
|
+
* add OpenTelemetry connector, tests and a graphana example ([#22](https://github.com/iotaledger/twin-telemetry/issues/22)) ([ae3e08f](https://github.com/iotaledger/twin-telemetry/commit/ae3e08f459cb20ff5d2a149982676de8c2f90ae1))
|
|
84
|
+
* typescript 6 update ([0acecc2](https://github.com/iotaledger/twin-telemetry/commit/0acecc2692b174fbaec6a8a89bd9277fa3530b5f))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Bug Fixes
|
|
88
|
+
|
|
89
|
+
* docs ([acc23a6](https://github.com/iotaledger/twin-telemetry/commit/acc23a674e75752e3817e2717d6b029d0b1404ff))
|
|
90
|
+
* open-telemetry config options ([c35ee76](https://github.com/iotaledger/twin-telemetry/commit/c35ee764ccad9168985fcac6efc3461422884ce4))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Dependencies
|
|
94
|
+
|
|
95
|
+
* The following workspace dependencies were updated
|
|
96
|
+
* dependencies
|
|
97
|
+
* @twin.org/telemetry-connector-entity-storage bumped from 0.0.3-next.2 to 0.0.3-next.5
|
|
98
|
+
* @twin.org/telemetry-models bumped from 0.0.3-next.2 to 0.0.3-next.5
|
|
99
|
+
|
|
100
|
+
## Changelog
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Telemetry Connector OpenTelemetry Examples
|
|
2
|
+
|
|
3
|
+
These examples show how to wire the connector to an OpenTelemetry SDK provider, record metrics, and connect to a Grafana/Prometheus stack.
|
|
4
|
+
|
|
5
|
+
## Prometheus Metric Naming
|
|
6
|
+
|
|
7
|
+
When using the Prometheus exporter, the OTEL SDK appends the `unit` field to the metric
|
|
8
|
+
name following the OpenMetrics convention. If you set `unit: "requests"` on a counter
|
|
9
|
+
named `api_requests`, Prometheus will expose it as `api_requests_requests_total` — which
|
|
10
|
+
may not be what you want. Omit the `unit` field (or leave it empty) to get clean names:
|
|
11
|
+
|
|
12
|
+
- `api_requests` (Counter, no unit) → `api_requests_total`
|
|
13
|
+
- `active_connections` (UpDownCounter, no unit) → `active_connections`
|
|
14
|
+
- `cpu_temperature` (Gauge, no unit) → `cpu_temperature`
|
|
15
|
+
|
|
16
|
+
> This only applies to the Prometheus exporter. OTLP exporters (e.g. Grafana Agent,
|
|
17
|
+
> Tempo, OTEL Collector) preserve the unit as metadata and are not affected.
|
|
18
|
+
|
|
19
|
+
## Basic Setup with Prometheus Exporter
|
|
20
|
+
|
|
21
|
+
Install the optional Prometheus exporter peer dependency alongside the connector:
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
npm install @opentelemetry/exporter-prometheus
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Pass a `readers` config map to the connector constructor. The connector instantiates the
|
|
28
|
+
exporter internally when `start()` is called — no manual `MeterProvider` wiring is needed.
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
|
|
32
|
+
import { MemoryEntityStorageConnector } from '@twin.org/entity-storage-connector-memory';
|
|
33
|
+
import { TelemetryConnectorFactory } from '@twin.org/telemetry-models';
|
|
34
|
+
import {
|
|
35
|
+
OpenTelemetryTelemetryConnector,
|
|
36
|
+
initSchema,
|
|
37
|
+
type TelemetryMetric,
|
|
38
|
+
type TelemetryMetricValue
|
|
39
|
+
} from '@twin.org/telemetry-connector-opentelemetry';
|
|
40
|
+
|
|
41
|
+
// Register entity storage so the connector can persist metric definitions and history.
|
|
42
|
+
initSchema();
|
|
43
|
+
EntityStorageConnectorFactory.register(
|
|
44
|
+
'telemetry-metric',
|
|
45
|
+
() => new MemoryEntityStorageConnector<TelemetryMetric>({ entitySchema: 'TelemetryMetric' })
|
|
46
|
+
);
|
|
47
|
+
EntityStorageConnectorFactory.register(
|
|
48
|
+
'telemetry-metric-value',
|
|
49
|
+
() =>
|
|
50
|
+
new MemoryEntityStorageConnector<TelemetryMetricValue>({ entitySchema: 'TelemetryMetricValue' })
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const connector = new OpenTelemetryTelemetryConnector({
|
|
54
|
+
config: {
|
|
55
|
+
meterName: 'my-service',
|
|
56
|
+
meterVersion: '1.0.0',
|
|
57
|
+
readers: {
|
|
58
|
+
prometheus: { type: 'prometheus', port: 9464 }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await connector.start();
|
|
64
|
+
|
|
65
|
+
TelemetryConnectorFactory.register('telemetry', () => connector);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Creating and Recording Metrics
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { MetricType } from '@twin.org/telemetry-models';
|
|
72
|
+
import { OpenTelemetryTelemetryConnector } from '@twin.org/telemetry-connector-opentelemetry';
|
|
73
|
+
|
|
74
|
+
const connector = new OpenTelemetryTelemetryConnector();
|
|
75
|
+
|
|
76
|
+
console.log(connector.className()); // OpenTelemetryTelemetryConnector
|
|
77
|
+
|
|
78
|
+
await connector.createMetric({
|
|
79
|
+
id: 'api-requests',
|
|
80
|
+
label: 'API Requests',
|
|
81
|
+
description: 'Total number of API requests received',
|
|
82
|
+
unit: 'requests',
|
|
83
|
+
type: MetricType.Counter
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
await connector.createMetric({
|
|
87
|
+
id: 'active-connections',
|
|
88
|
+
label: 'Active Connections',
|
|
89
|
+
description: 'Number of currently active WebSocket connections',
|
|
90
|
+
unit: 'connections',
|
|
91
|
+
type: MetricType.IncDecCounter
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
await connector.createMetric({
|
|
95
|
+
id: 'cpu-temperature',
|
|
96
|
+
label: 'CPU Temperature',
|
|
97
|
+
description: 'Current CPU temperature reading',
|
|
98
|
+
unit: 'celsius',
|
|
99
|
+
type: MetricType.Gauge
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Counter: increment only
|
|
103
|
+
await connector.addMetricValue('api-requests', 'inc');
|
|
104
|
+
await connector.addMetricValue('api-requests', 10, { route: '/api/health', statusCode: 200 });
|
|
105
|
+
|
|
106
|
+
// IncDecCounter: increment and decrement
|
|
107
|
+
await connector.addMetricValue('active-connections', 'inc');
|
|
108
|
+
await connector.addMetricValue('active-connections', 'dec');
|
|
109
|
+
|
|
110
|
+
// Gauge: absolute value
|
|
111
|
+
await connector.addMetricValue('cpu-temperature', 72.4);
|
|
112
|
+
await connector.addMetricValue('cpu-temperature', 68.1, { node: 'edge-1' });
|
|
113
|
+
|
|
114
|
+
const latest = await connector.getMetric('cpu-temperature');
|
|
115
|
+
console.log(latest.value.value); // 68.1
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Querying the Local Registry
|
|
119
|
+
|
|
120
|
+
The connector keeps an in-memory mirror of all recorded values so you can read back metrics without a separate query backend.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { MetricType } from '@twin.org/telemetry-models';
|
|
124
|
+
import { OpenTelemetryTelemetryConnector } from '@twin.org/telemetry-connector-opentelemetry';
|
|
125
|
+
|
|
126
|
+
const connector = new OpenTelemetryTelemetryConnector();
|
|
127
|
+
|
|
128
|
+
// List all metrics of a given type
|
|
129
|
+
const counters = await connector.query(MetricType.Counter, undefined, 25);
|
|
130
|
+
console.log(counters.entities.length);
|
|
131
|
+
|
|
132
|
+
// Paginate through value history
|
|
133
|
+
const page1 = await connector.queryValues(
|
|
134
|
+
'api-requests',
|
|
135
|
+
Date.now() - 3_600_000,
|
|
136
|
+
Date.now(),
|
|
137
|
+
undefined,
|
|
138
|
+
20
|
|
139
|
+
);
|
|
140
|
+
console.log(page1.entities.length);
|
|
141
|
+
|
|
142
|
+
if (page1.cursor) {
|
|
143
|
+
const page2 = await connector.queryValues('api-requests', undefined, undefined, page1.cursor, 20);
|
|
144
|
+
console.log(page2.entities.length);
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Updating and Removing Metrics
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import { OpenTelemetryTelemetryConnector } from '@twin.org/telemetry-connector-opentelemetry';
|
|
152
|
+
|
|
153
|
+
const connector = new OpenTelemetryTelemetryConnector();
|
|
154
|
+
|
|
155
|
+
await connector.updateMetric({
|
|
156
|
+
id: 'api-requests',
|
|
157
|
+
label: 'API Requests Total',
|
|
158
|
+
description: 'Cumulative count of all API requests',
|
|
159
|
+
unit: 'requests'
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
await connector.removeMetric('api-requests');
|
|
163
|
+
|
|
164
|
+
const result = await connector.query(undefined, undefined, 10);
|
|
165
|
+
console.log(result.entities.length); // 0
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Connecting to Grafana via OTLP
|
|
169
|
+
|
|
170
|
+
> OTLP exporter support is planned for a future release. The `readers` config map currently
|
|
171
|
+
> supports `type: "prometheus"` only. Additional reader types (OTLP HTTP, OTLP gRPC, etc.)
|
|
172
|
+
> will be added as further discriminated-union members of `IOpenTelemetryReaderConfig`.
|