@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.
Files changed (34) hide show
  1. package/README.md +21 -0
  2. package/dist/es/index.js +9 -0
  3. package/dist/es/index.js.map +1 -0
  4. package/dist/es/models/IOpenTelemetryPrometheusReaderConfig.js +2 -0
  5. package/dist/es/models/IOpenTelemetryPrometheusReaderConfig.js.map +1 -0
  6. package/dist/es/models/IOpenTelemetryReaderConfig.js +3 -0
  7. package/dist/es/models/IOpenTelemetryReaderConfig.js.map +1 -0
  8. package/dist/es/models/IOpenTelemetryTelemetryConnectorConfig.js +2 -0
  9. package/dist/es/models/IOpenTelemetryTelemetryConnectorConfig.js.map +1 -0
  10. package/dist/es/models/IOpenTelemetryTelemetryConnectorConstructorOptions.js +2 -0
  11. package/dist/es/models/IOpenTelemetryTelemetryConnectorConstructorOptions.js.map +1 -0
  12. package/dist/es/models/openTelemetryReaderTypes.js +13 -0
  13. package/dist/es/models/openTelemetryReaderTypes.js.map +1 -0
  14. package/dist/es/openTelemetryTelemetryConnector.js +307 -0
  15. package/dist/es/openTelemetryTelemetryConnector.js.map +1 -0
  16. package/dist/types/index.d.ts +6 -0
  17. package/dist/types/models/IOpenTelemetryPrometheusReaderConfig.d.ts +31 -0
  18. package/dist/types/models/IOpenTelemetryReaderConfig.d.ts +6 -0
  19. package/dist/types/models/IOpenTelemetryTelemetryConnectorConfig.d.ts +24 -0
  20. package/dist/types/models/IOpenTelemetryTelemetryConnectorConstructorOptions.d.ts +27 -0
  21. package/dist/types/models/openTelemetryReaderTypes.d.ts +13 -0
  22. package/dist/types/openTelemetryTelemetryConnector.d.ts +122 -0
  23. package/docs/changelog.md +100 -0
  24. package/docs/examples.md +172 -0
  25. package/docs/reference/classes/OpenTelemetryTelemetryConnector.md +364 -0
  26. package/docs/reference/index.md +20 -0
  27. package/docs/reference/interfaces/IOpenTelemetryPrometheusReaderConfig.md +63 -0
  28. package/docs/reference/interfaces/IOpenTelemetryTelemetryConnectorConfig.md +45 -0
  29. package/docs/reference/interfaces/IOpenTelemetryTelemetryConnectorConstructorOptions.md +50 -0
  30. package/docs/reference/type-aliases/IOpenTelemetryReaderConfig.md +6 -0
  31. package/docs/reference/type-aliases/OpenTelemetryReaderTypes.md +5 -0
  32. package/docs/reference/variables/OpenTelemetryReaderTypes.md +13 -0
  33. package/locales/en.json +13 -0
  34. package/package.json +70 -0
@@ -0,0 +1,364 @@
1
+ # Class: OpenTelemetryTelemetryConnector
2
+
3
+ Class for performing telemetry operations using OpenTelemetry instruments.
4
+ Metric definitions and value history are persisted via an internal
5
+ EntityStorageTelemetryConnector instance created at construction time.
6
+ Call `start()` to initialise the MeterProvider and exporters; metrics can be
7
+ created and queried before start() — OTEL forwarding is simply skipped until
8
+ the MeterProvider is running.
9
+
10
+ ## Implements
11
+
12
+ - `ITelemetryConnector`
13
+
14
+ ## Constructors
15
+
16
+ ### Constructor
17
+
18
+ > **new OpenTelemetryTelemetryConnector**(`options?`): `OpenTelemetryTelemetryConnector`
19
+
20
+ Create a new instance of OpenTelemetryTelemetryConnector.
21
+ Eagerly constructs the inner EntityStorageTelemetryConnector — if the required
22
+ entity storage types are not registered this constructor will throw (fail fast).
23
+
24
+ #### Parameters
25
+
26
+ ##### options?
27
+
28
+ [`IOpenTelemetryTelemetryConnectorConstructorOptions`](../interfaces/IOpenTelemetryTelemetryConnectorConstructorOptions.md)
29
+
30
+ The options for the connector.
31
+
32
+ #### Returns
33
+
34
+ `OpenTelemetryTelemetryConnector`
35
+
36
+ ## Properties
37
+
38
+ ### NAMESPACE {#namespace}
39
+
40
+ > `readonly` `static` **NAMESPACE**: `string` = `"opentelemetry"`
41
+
42
+ The namespace supported by the telemetry connector.
43
+
44
+ ***
45
+
46
+ ### CLASS\_NAME {#class_name}
47
+
48
+ > `readonly` `static` **CLASS\_NAME**: `string`
49
+
50
+ Runtime name for the class.
51
+
52
+ ## Methods
53
+
54
+ ### className() {#classname}
55
+
56
+ > **className**(): `string`
57
+
58
+ Returns the class name of the component.
59
+
60
+ #### Returns
61
+
62
+ `string`
63
+
64
+ The class name of the component.
65
+
66
+ #### Implementation of
67
+
68
+ `ITelemetryConnector.className`
69
+
70
+ ***
71
+
72
+ ### start() {#start}
73
+
74
+ > **start**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
75
+
76
+ Initialise the MeterProvider and configured exporters.
77
+
78
+ #### Parameters
79
+
80
+ ##### nodeLoggingComponentType?
81
+
82
+ `string`
83
+
84
+ The node logging component type.
85
+
86
+ #### Returns
87
+
88
+ `Promise`\<`void`\>
89
+
90
+ Nothing.
91
+
92
+ #### Implementation of
93
+
94
+ `ITelemetryConnector.start`
95
+
96
+ ***
97
+
98
+ ### stop() {#stop}
99
+
100
+ > **stop**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
101
+
102
+ Shut down the MeterProvider and release resources.
103
+ Calling stop() on a connector that has not been started is a no-op.
104
+
105
+ #### Parameters
106
+
107
+ ##### nodeLoggingComponentType?
108
+
109
+ `string`
110
+
111
+ The node logging component type.
112
+
113
+ #### Returns
114
+
115
+ `Promise`\<`void`\>
116
+
117
+ Nothing.
118
+
119
+ #### Implementation of
120
+
121
+ `ITelemetryConnector.stop`
122
+
123
+ ***
124
+
125
+ ### createMetric() {#createmetric}
126
+
127
+ > **createMetric**(`metric`): `Promise`\<`void`\>
128
+
129
+ Create a new metric.
130
+ The definition is always persisted via the inner entity-storage connector.
131
+ If the MeterProvider is running the corresponding OTEL instrument is also registered.
132
+
133
+ #### Parameters
134
+
135
+ ##### metric
136
+
137
+ `ITelemetryMetric`
138
+
139
+ The metric details.
140
+
141
+ #### Returns
142
+
143
+ `Promise`\<`void`\>
144
+
145
+ Nothing.
146
+
147
+ #### Implementation of
148
+
149
+ `ITelemetryConnector.createMetric`
150
+
151
+ ***
152
+
153
+ ### getMetric() {#getmetric}
154
+
155
+ > **getMetric**(`id`): `Promise`\<\{ `metric`: `ITelemetryMetric`; `value`: `ITelemetryMetricValue`; \}\>
156
+
157
+ Get the metric details and its most recent value.
158
+
159
+ #### Parameters
160
+
161
+ ##### id
162
+
163
+ `string`
164
+
165
+ The metric id.
166
+
167
+ #### Returns
168
+
169
+ `Promise`\<\{ `metric`: `ITelemetryMetric`; `value`: `ITelemetryMetricValue`; \}\>
170
+
171
+ The metric details and its most recent value.
172
+
173
+ #### Implementation of
174
+
175
+ `ITelemetryConnector.getMetric`
176
+
177
+ ***
178
+
179
+ ### updateMetric() {#updatemetric}
180
+
181
+ > **updateMetric**(`metric`): `Promise`\<`void`\>
182
+
183
+ Update the metric metadata.
184
+ Note: OpenTelemetry instrument descriptors are immutable once created.
185
+ This method updates the persisted metadata mirror; the description/unit changes
186
+ are NOT propagated to the registered MeterProvider and will not appear at the
187
+ OTEL backend (Prometheus, OTLP, etc.).
188
+
189
+ #### Parameters
190
+
191
+ ##### metric
192
+
193
+ `Omit`\<`ITelemetryMetric`, `"type"`\>
194
+
195
+ The metric details (type cannot be changed).
196
+
197
+ #### Returns
198
+
199
+ `Promise`\<`void`\>
200
+
201
+ Nothing.
202
+
203
+ #### Implementation of
204
+
205
+ `ITelemetryConnector.updateMetric`
206
+
207
+ ***
208
+
209
+ ### addMetricValue() {#addmetricvalue}
210
+
211
+ > **addMetricValue**(`id`, `value`, `customData?`): `Promise`\<`string`\>
212
+
213
+ Record a metric value.
214
+ Entity storage always receives the value first and performs all validation.
215
+ If the MeterProvider is running the measurement is also forwarded to the OTEL instrument.
216
+ Counter accepts positive integers or "inc".
217
+ UpDownCounter accepts integers (positive or negative) or "inc"/"dec".
218
+ Gauge accepts any number.
219
+
220
+ #### Parameters
221
+
222
+ ##### id
223
+
224
+ `string`
225
+
226
+ The id of the metric.
227
+
228
+ ##### value
229
+
230
+ `number` \| `MetricCounterOperation`
231
+
232
+ The value for the operation.
233
+
234
+ ##### customData?
235
+
236
+ Optional custom data forwarded as OTEL attributes.
237
+
238
+ #### Returns
239
+
240
+ `Promise`\<`string`\>
241
+
242
+ The id of the new metric value entry.
243
+
244
+ #### Implementation of
245
+
246
+ `ITelemetryConnector.addMetricValue`
247
+
248
+ ***
249
+
250
+ ### removeMetric() {#removemetric}
251
+
252
+ > **removeMetric**(`id`): `Promise`\<`void`\>
253
+
254
+ Remove a metric and its persisted value history.
255
+ Note: OpenTelemetry exposes no API to deregister an instrument from a Meter,
256
+ so the underlying Counter/UpDownCounter/Gauge remains resident for the lifetime
257
+ of the process. Re-creating a metric with the same id but a different MetricType
258
+ is therefore not safe.
259
+
260
+ #### Parameters
261
+
262
+ ##### id
263
+
264
+ `string`
265
+
266
+ The id of the metric.
267
+
268
+ #### Returns
269
+
270
+ `Promise`\<`void`\>
271
+
272
+ Nothing.
273
+
274
+ #### Implementation of
275
+
276
+ `ITelemetryConnector.removeMetric`
277
+
278
+ ***
279
+
280
+ ### query() {#query}
281
+
282
+ > **query**(`type?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: `ITelemetryMetric`[]; `cursor?`: `string`; \}\>
283
+
284
+ Query the registered metrics, optionally filtered by type.
285
+
286
+ #### Parameters
287
+
288
+ ##### type?
289
+
290
+ `MetricType`
291
+
292
+ The type of the metric.
293
+
294
+ ##### cursor?
295
+
296
+ `string`
297
+
298
+ The cursor to request the next page.
299
+
300
+ ##### limit?
301
+
302
+ `number`
303
+
304
+ Limit the number of entities to return.
305
+
306
+ #### Returns
307
+
308
+ `Promise`\<\{ `entities`: `ITelemetryMetric`[]; `cursor?`: `string`; \}\>
309
+
310
+ The matching metrics and an optional cursor for the next page.
311
+
312
+ #### Implementation of
313
+
314
+ `ITelemetryConnector.query`
315
+
316
+ ***
317
+
318
+ ### queryValues() {#queryvalues}
319
+
320
+ > **queryValues**(`id`, `timeStart?`, `timeEnd?`, `cursor?`, `limit?`): `Promise`\<\{ `metric`: `ITelemetryMetric`; `entities`: `ITelemetryMetricValue`[]; `cursor?`: `string`; \}\>
321
+
322
+ Query the recorded values for a metric, ordered by most recent first.
323
+
324
+ #### Parameters
325
+
326
+ ##### id
327
+
328
+ `string`
329
+
330
+ The id of the metric.
331
+
332
+ ##### timeStart?
333
+
334
+ `number`
335
+
336
+ The inclusive start time (epoch ms).
337
+
338
+ ##### timeEnd?
339
+
340
+ `number`
341
+
342
+ The inclusive end time (epoch ms).
343
+
344
+ ##### cursor?
345
+
346
+ `string`
347
+
348
+ The cursor returned by the previous call.
349
+
350
+ ##### limit?
351
+
352
+ `number`
353
+
354
+ Limit the number of values to return.
355
+
356
+ #### Returns
357
+
358
+ `Promise`\<\{ `metric`: `ITelemetryMetric`; `entities`: `ITelemetryMetricValue`[]; `cursor?`: `string`; \}\>
359
+
360
+ The metric details, matching values, and an optional cursor for the next page.
361
+
362
+ #### Implementation of
363
+
364
+ `ITelemetryConnector.queryValues`
@@ -0,0 +1,20 @@
1
+ # @twin.org/telemetry-connector-opentelemetry
2
+
3
+ ## Classes
4
+
5
+ - [OpenTelemetryTelemetryConnector](classes/OpenTelemetryTelemetryConnector.md)
6
+
7
+ ## Interfaces
8
+
9
+ - [IOpenTelemetryPrometheusReaderConfig](interfaces/IOpenTelemetryPrometheusReaderConfig.md)
10
+ - [IOpenTelemetryTelemetryConnectorConfig](interfaces/IOpenTelemetryTelemetryConnectorConfig.md)
11
+ - [IOpenTelemetryTelemetryConnectorConstructorOptions](interfaces/IOpenTelemetryTelemetryConnectorConstructorOptions.md)
12
+
13
+ ## Type Aliases
14
+
15
+ - [IOpenTelemetryReaderConfig](type-aliases/IOpenTelemetryReaderConfig.md)
16
+ - [OpenTelemetryReaderTypes](type-aliases/OpenTelemetryReaderTypes.md)
17
+
18
+ ## Variables
19
+
20
+ - [OpenTelemetryReaderTypes](variables/OpenTelemetryReaderTypes.md)
@@ -0,0 +1,63 @@
1
+ # Interface: IOpenTelemetryPrometheusReaderConfig
2
+
3
+ Configuration for a Prometheus scrape-endpoint reader.
4
+ The connector instantiates a PrometheusExporter from these options in start().
5
+
6
+ ## Properties
7
+
8
+ ### type {#type}
9
+
10
+ > **type**: `"prometheus"`
11
+
12
+ Type.
13
+
14
+ ***
15
+
16
+ ### port? {#port}
17
+
18
+ > `optional` **port?**: `number`
19
+
20
+ TCP port the Prometheus HTTP server listens on.
21
+
22
+ #### Default
23
+
24
+ ```ts
25
+ 9464
26
+ ```
27
+
28
+ ***
29
+
30
+ ### endpoint? {#endpoint}
31
+
32
+ > `optional` **endpoint?**: `string`
33
+
34
+ HTTP path that Prometheus scrapes.
35
+
36
+ #### Default
37
+
38
+ ```ts
39
+ /metrics
40
+ ```
41
+
42
+ ***
43
+
44
+ ### startServer? {#startserver}
45
+
46
+ > `optional` **startServer?**: `boolean`
47
+
48
+ Whether to start the built-in HTTP server automatically.
49
+ Set to false if you manage the server externally.
50
+
51
+ #### Default
52
+
53
+ ```ts
54
+ true
55
+ ```
56
+
57
+ ***
58
+
59
+ ### prefix? {#prefix}
60
+
61
+ > `optional` **prefix?**: `string`
62
+
63
+ Optional string prepended to every exported metric name.
@@ -0,0 +1,45 @@
1
+ # Interface: IOpenTelemetryTelemetryConnectorConfig
2
+
3
+ The options for the OpenTelemetry telemetry connector constructor.
4
+
5
+ ## Properties
6
+
7
+ ### meterName? {#metername}
8
+
9
+ > `optional` **meterName?**: `string`
10
+
11
+ The name of the OpenTelemetry meter used to create instruments.
12
+
13
+ #### Default
14
+
15
+ ```ts
16
+ twin-telemetry
17
+ ```
18
+
19
+ ***
20
+
21
+ ### meterVersion? {#meterversion}
22
+
23
+ > `optional` **meterVersion?**: `string`
24
+
25
+ The version reported by the OpenTelemetry meter.
26
+
27
+ #### Default
28
+
29
+ ```ts
30
+ 1.0.0
31
+ ```
32
+
33
+ ***
34
+
35
+ ### readers? {#readers}
36
+
37
+ > `optional` **readers?**: `object`
38
+
39
+ Named metric-reader configurations keyed by an arbitrary id.
40
+ Each entry's `type` field determines which exporter the connector instantiates
41
+ in start(). Omit or pass an empty object for a no-op provider (useful for tests).
42
+
43
+ #### Index Signature
44
+
45
+ \[`id`: `string`\]: [`IOpenTelemetryPrometheusReaderConfig`](IOpenTelemetryPrometheusReaderConfig.md)
@@ -0,0 +1,50 @@
1
+ # Interface: IOpenTelemetryTelemetryConnectorConstructorOptions
2
+
3
+ The options for the OpenTelemetry telemetry connector constructor.
4
+
5
+ ## Properties
6
+
7
+ ### loggingComponentType? {#loggingcomponenttype}
8
+
9
+ > `optional` **loggingComponentType?**: `string`
10
+
11
+ The component type to use for logging inside the connector and the inner
12
+ entity-storage connector. When omitted logging is disabled.
13
+
14
+ ***
15
+
16
+ ### telemetryMetricStorageConnectorType? {#telemetrymetricstorageconnectortype}
17
+
18
+ > `optional` **telemetryMetricStorageConnectorType?**: `string`
19
+
20
+ The entity storage connector type to use for storing metric definitions.
21
+ Must be registered in `EntityStorageConnectorFactory` before calling `start()`.
22
+
23
+ #### Default
24
+
25
+ ```ts
26
+ telemetry-metric
27
+ ```
28
+
29
+ ***
30
+
31
+ ### telemetryMetricValueStorageConnectorType? {#telemetrymetricvaluestorageconnectortype}
32
+
33
+ > `optional` **telemetryMetricValueStorageConnectorType?**: `string`
34
+
35
+ The entity storage connector type to use for storing metric values.
36
+ Must be registered in `EntityStorageConnectorFactory` before calling `start()`.
37
+
38
+ #### Default
39
+
40
+ ```ts
41
+ telemetry-metric-value
42
+ ```
43
+
44
+ ***
45
+
46
+ ### config? {#config}
47
+
48
+ > `optional` **config?**: [`IOpenTelemetryTelemetryConnectorConfig`](IOpenTelemetryTelemetryConnectorConfig.md)
49
+
50
+ The config for the telemetry connector.
@@ -0,0 +1,6 @@
1
+ # Type Alias: IOpenTelemetryReaderConfig
2
+
3
+ > **IOpenTelemetryReaderConfig** = [`IOpenTelemetryPrometheusReaderConfig`](../interfaces/IOpenTelemetryPrometheusReaderConfig.md)
4
+
5
+ Discriminated union of all supported metric-reader configurations.
6
+ Add new members here when additional exporter types are implemented.
@@ -0,0 +1,5 @@
1
+ # Type Alias: OpenTelemetryReaderTypes
2
+
3
+ > **OpenTelemetryReaderTypes** = *typeof* [`OpenTelemetryReaderTypes`](../variables/OpenTelemetryReaderTypes.md)\[keyof *typeof* [`OpenTelemetryReaderTypes`](../variables/OpenTelemetryReaderTypes.md)\]
4
+
5
+ The types of readers.
@@ -0,0 +1,13 @@
1
+ # Variable: OpenTelemetryReaderTypes
2
+
3
+ > `const` **OpenTelemetryReaderTypes**: `object`
4
+
5
+ The types of readers.
6
+
7
+ ## Type Declaration
8
+
9
+ ### Prometheus {#prometheus}
10
+
11
+ > `readonly` **Prometheus**: `"prometheus"` = `"prometheus"`
12
+
13
+ Prometheus.
@@ -0,0 +1,13 @@
1
+ {
2
+ "error": {
3
+ "openTelemetryTelemetryConnector": {
4
+ "unknownReaderType": "The reader type \"{type}\" is not supported, valid values are: prometheus"
5
+ }
6
+ },
7
+ "info": {
8
+ "openTelemetryTelemetryConnector": {
9
+ "connectorStarted": "The connector was started with \"{readerCount}\" metric reader(s)",
10
+ "connectorStopped": "The connector was stopped"
11
+ }
12
+ }
13
+ }
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@twin.org/telemetry-connector-opentelemetry",
3
+ "version": "0.0.3-next.10",
4
+ "description": "OpenTelemetry connector for pushing telemetry metrics to OTEL-compatible backends.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/iotaledger/telemetry.git",
8
+ "directory": "packages/telemetry-connector-opentelemetry"
9
+ },
10
+ "author": "adrian.sanchez.sequeira@iota.org",
11
+ "license": "Apache-2.0",
12
+ "type": "module",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "dependencies": {
17
+ "@opentelemetry/api": "1.9.1",
18
+ "@opentelemetry/sdk-metrics": "2.7.1",
19
+ "@twin.org/core": "next",
20
+ "@twin.org/entity-storage-models": "next",
21
+ "@twin.org/logging-models": "next",
22
+ "@twin.org/nameof": "next",
23
+ "@twin.org/telemetry-connector-entity-storage": "0.0.3-next.10",
24
+ "@twin.org/telemetry-models": "0.0.3-next.10"
25
+ },
26
+ "peerDependencies": {
27
+ "@opentelemetry/exporter-prometheus": ">=0.200.0"
28
+ },
29
+ "peerDependenciesMeta": {
30
+ "@opentelemetry/exporter-prometheus": {
31
+ "optional": true
32
+ }
33
+ },
34
+ "main": "./dist/es/index.js",
35
+ "types": "./dist/types/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/types/index.d.ts",
39
+ "import": "./dist/es/index.js",
40
+ "default": "./dist/es/index.js"
41
+ },
42
+ "./locales/*.json": "./locales/*.json"
43
+ },
44
+ "files": [
45
+ "dist/es",
46
+ "dist/types",
47
+ "locales",
48
+ "docs"
49
+ ],
50
+ "keywords": [
51
+ "twin",
52
+ "trade",
53
+ "iota",
54
+ "framework",
55
+ "blockchain",
56
+ "telemetry",
57
+ "opentelemetry",
58
+ "otel",
59
+ "metrics",
60
+ "grafana",
61
+ "prometheus",
62
+ "connector",
63
+ "adapter",
64
+ "integration"
65
+ ],
66
+ "bugs": {
67
+ "url": "git+https://github.com/iotaledger/telemetry/issues"
68
+ },
69
+ "homepage": "https://twindev.org"
70
+ }