@3sixty/telemetry-connector-opentelemetry 0.20.0-next.0 → 0.20.0-next.2
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/dist/es/index.js.map +1 -1
- package/dist/es/models/IOpenTelemetryOtlpHttpReaderConfig.js.map +1 -1
- package/dist/es/models/IOpenTelemetryPrometheusReaderConfig.js.map +1 -1
- package/dist/es/models/IOpenTelemetryReaderConfig.js.map +1 -1
- package/dist/es/models/IOpenTelemetryTelemetryConnectorConfig.js.map +1 -1
- package/dist/es/models/IOpenTelemetryTelemetryConnectorConstructorOptions.js.map +1 -1
- package/dist/es/models/openTelemetryReaderTypes.js.map +1 -1
- package/dist/es/openTelemetryTelemetryConnector.js.map +1 -1
- package/docs/changelog.md +32 -0
- package/docs/reference/classes/OpenTelemetryTelemetryConnector.md +2 -0
- package/package.json +10 -9
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,gDAAgD,CAAC;AAC/D,cAAc,kDAAkD,CAAC;AACjE,cAAc,wCAAwC,CAAC;AACvD,cAAc,oDAAoD,CAAC;AACnE,cAAc,gEAAgE,CAAC;AAC/E,cAAc,sCAAsC,CAAC;AACrD,cAAc,sCAAsC,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./models/IOpenTelemetryOtlpHttpReaderConfig.js\";\nexport * from \"./models/IOpenTelemetryPrometheusReaderConfig.js\";\nexport * from \"./models/IOpenTelemetryReaderConfig.js\";\nexport * from \"./models/IOpenTelemetryTelemetryConnectorConfig.js\";\nexport * from \"./models/IOpenTelemetryTelemetryConnectorConstructorOptions.js\";\nexport * from \"./models/openTelemetryReaderTypes.js\";\nexport * from \"./openTelemetryTelemetryConnector.js\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOpenTelemetryOtlpHttpReaderConfig.js","
|
|
1
|
+
{"version":3,"file":"IOpenTelemetryOtlpHttpReaderConfig.js","sources":["../../../src/models/IOpenTelemetryOtlpHttpReaderConfig.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { OpenTelemetryReaderTypes } from \"./openTelemetryReaderTypes.js\";\n\n/**\n * Configuration for an OTLP HTTP push exporter reader.\n * The connector instantiates an OTLPMetricExporter wrapped in a PeriodicExportingMetricReader.\n */\nexport interface IOpenTelemetryOtlpHttpReaderConfig {\n\t/**\n\t * Type.\n\t */\n\ttype: typeof OpenTelemetryReaderTypes.OtlpHttp;\n\n\t/**\n\t * The OTLP HTTP endpoint URL to push metrics to.\n\t * @default http://localhost:4318/v1/metrics\n\t */\n\turl?: string;\n\n\t/**\n\t * How often metrics are exported, in milliseconds.\n\t * @default 60000\n\t */\n\texportIntervalMs?: number;\n\n\t/**\n\t * Optional HTTP headers included in every export request.\n\t */\n\theaders?: { [key: string]: string };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOpenTelemetryPrometheusReaderConfig.js","
|
|
1
|
+
{"version":3,"file":"IOpenTelemetryPrometheusReaderConfig.js","sources":["../../../src/models/IOpenTelemetryPrometheusReaderConfig.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { OpenTelemetryReaderTypes } from \"./openTelemetryReaderTypes.js\";\n\n/**\n * Configuration for a Prometheus scrape-endpoint reader.\n * The connector instantiates a PrometheusExporter from these options in start().\n */\nexport interface IOpenTelemetryPrometheusReaderConfig {\n\t/**\n\t * Type.\n\t */\n\ttype: typeof OpenTelemetryReaderTypes.Prometheus;\n\n\t/**\n\t * TCP port the Prometheus HTTP server listens on.\n\t * @default 9464\n\t */\n\tport?: number;\n\n\t/**\n\t * HTTP path that Prometheus scrapes.\n\t * @default /metrics\n\t */\n\tendpoint?: string;\n\n\t/**\n\t * Whether to start the built-in HTTP server automatically.\n\t * Set to false if you manage the server externally.\n\t * @default true\n\t */\n\tstartServer?: boolean;\n\n\t/**\n\t * Optional string prepended to every exported metric name.\n\t */\n\tprefix?: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOpenTelemetryReaderConfig.js","
|
|
1
|
+
{"version":3,"file":"IOpenTelemetryReaderConfig.js","sources":["../../../src/models/IOpenTelemetryReaderConfig.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IOpenTelemetryOtlpHttpReaderConfig } from \"./IOpenTelemetryOtlpHttpReaderConfig.js\";\nimport type { IOpenTelemetryPrometheusReaderConfig } from \"./IOpenTelemetryPrometheusReaderConfig.js\";\n\n/**\n * Discriminated union of all supported metric-reader configurations.\n * Add new members here when additional exporter types are implemented.\n */\nexport type IOpenTelemetryReaderConfig =\n\tIOpenTelemetryPrometheusReaderConfig | IOpenTelemetryOtlpHttpReaderConfig;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOpenTelemetryTelemetryConnectorConfig.js","
|
|
1
|
+
{"version":3,"file":"IOpenTelemetryTelemetryConnectorConfig.js","sources":["../../../src/models/IOpenTelemetryTelemetryConnectorConfig.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IOpenTelemetryReaderConfig } from \"./IOpenTelemetryReaderConfig.js\";\n\n/**\n * The options for the OpenTelemetry telemetry connector constructor.\n */\nexport interface IOpenTelemetryTelemetryConnectorConfig {\n\t/**\n\t * The name of the OpenTelemetry meter used to create instruments.\n\t * @default twin-telemetry\n\t */\n\tmeterName?: string;\n\n\t/**\n\t * The version reported by the OpenTelemetry meter.\n\t * @default 1.0.0\n\t */\n\tmeterVersion?: string;\n\n\t/**\n\t * Named metric-reader configurations keyed by an arbitrary id.\n\t * Each entry's `type` field determines which exporter the connector instantiates\n\t * in start(). Omit or pass an empty object for a no-op provider (useful for tests).\n\t */\n\treaders?: { [id: string]: IOpenTelemetryReaderConfig };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOpenTelemetryTelemetryConnectorConstructorOptions.js","
|
|
1
|
+
{"version":3,"file":"IOpenTelemetryTelemetryConnectorConstructorOptions.js","sources":["../../../src/models/IOpenTelemetryTelemetryConnectorConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IOpenTelemetryTelemetryConnectorConfig } from \"./IOpenTelemetryTelemetryConnectorConfig.js\";\n\n/**\n * The options for the OpenTelemetry telemetry connector constructor.\n */\nexport interface IOpenTelemetryTelemetryConnectorConstructorOptions {\n\t/**\n\t * The config for the telemetry connector.\n\t */\n\tconfig?: IOpenTelemetryTelemetryConnectorConfig;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openTelemetryReaderTypes.js","
|
|
1
|
+
{"version":3,"file":"openTelemetryReaderTypes.js","sources":["../../../src/models/openTelemetryReaderTypes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC;;OAEG;IACH,UAAU,EAAE,YAAY;IACxB;;OAEG;IACH,QAAQ,EAAE,WAAW;CACZ,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The types of readers.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const OpenTelemetryReaderTypes = {\n\t/**\n\t * Prometheus.\n\t */\n\tPrometheus: \"prometheus\",\n\t/**\n\t * OTLP HTTP push exporter.\n\t */\n\tOtlpHttp: \"otlp-http\"\n} as const;\n\n/**\n * The types of readers.\n */\nexport type OpenTelemetryReaderTypes =\n\t(typeof OpenTelemetryReaderTypes)[keyof typeof OpenTelemetryReaderTypes];\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openTelemetryTelemetryConnector.js","sourceRoot":"","sources":["../../src/openTelemetryTelemetryConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAoB,MAAM,iBAAiB,CAAC;AAClF,OAAO,EACN,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,aAAa,EACb,YAAY,EACZ,MAAM,cAAc,CAAC;AAGtB,OAAO,EAIN,sBAAsB,EACtB,UAAU,EACV,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EACN,aAAa,EACb,6BAA6B,EAE7B,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAEhF;;;;GAIG;AACH,MAAM,OAAO,+BAA+B;IAC3C;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,gBAAgB,CAAC;IAE5D;;OAEG;IACI,MAAM,CAAU,UAAU,qCAAqD;IAEtF;;;OAGG;IACc,OAAO,CAAyC;IAEjE;;;OAGG;IACK,QAAQ,CAAU;IAE1B;;;;;OAKG;IACc,UAAU,CAQzB;IAEF;;;OAGG;IACc,WAAW,CAE1B;IAEF;;;;OAIG;IACH,YAAY,OAA4D;QACvE,IAAI,CAAC,OAAO,GAAG,OA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GAAG,CAAC,GAAG,GAAG,CAAC;gBACvB,CAAC;qBAAM,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;oBAChE,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;gBACvB,CAAC;qBAAM,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;oBAClE,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;gBACvB,CAAC;qBAAM,CAAC;oBACP,UAAU,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;gBACvC,CAAC;YACF,CAAC;iBAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC/B,UAAU,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACvC,CAAC;QACF,CAAC;QACD,OAAO,UAAU,CAAC;IACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ContextIdKeys, ContextIdStore, type IContextIds } from \"@3sixty/context\";\nimport {\n\tAlreadyExistsError,\n\tBaseError,\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tNotFoundError,\n\tRandomHelper\n} from \"@3sixty/core\";\nimport type { ILoggingComponent } from \"@3sixty/logging-models\";\nimport { nameof } from \"@3sixty/nameof\";\nimport {\n\ttype ITelemetryConnector,\n\ttype ITelemetryMetric,\n\ttype ITelemetryMetricValueEntry,\n\tMetricCounterOperation,\n\tMetricType\n} from \"@3sixty/telemetry-models\";\nimport type { Attributes, Counter, Gauge, Meter, UpDownCounter } from \"@opentelemetry/api\";\nimport { OTLPMetricExporter } from \"@opentelemetry/exporter-metrics-otlp-http\";\nimport { PrometheusExporter } from \"@opentelemetry/exporter-prometheus\";\nimport { resourceFromAttributes } from \"@opentelemetry/resources\";\nimport {\n\tMeterProvider,\n\tPeriodicExportingMetricReader,\n\ttype MetricReader\n} from \"@opentelemetry/sdk-metrics\";\nimport type { IOpenTelemetryTelemetryConnectorConfig } from \"./models/IOpenTelemetryTelemetryConnectorConfig.js\";\nimport type { IOpenTelemetryTelemetryConnectorConstructorOptions } from \"./models/IOpenTelemetryTelemetryConnectorConstructorOptions.js\";\nimport { OpenTelemetryReaderTypes } from \"./models/openTelemetryReaderTypes.js\";\n\n/**\n * Class for performing telemetry operations using OpenTelemetry instruments.\n * Metric definitions are held in memory. Persistence and querying are not supported;\n * use a multi-connector with an EntityStorageTelemetryConnector for those capabilities.\n */\nexport class OpenTelemetryTelemetryConnector implements ITelemetryConnector {\n\t/**\n\t * The namespace supported by the telemetry connector.\n\t */\n\tpublic static readonly NAMESPACE: string = \"open-telemetry\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<OpenTelemetryTelemetryConnector>();\n\n\t/**\n\t * Config options stored so provider creation can initialise readers and meter identity.\n\t * @internal\n\t */\n\tprivate readonly _config: IOpenTelemetryTelemetryConnectorConfig;\n\n\t/**\n\t * Whether start() has been called. Drives OTEL forwarding on/off.\n\t * @internal\n\t */\n\tprivate _started: boolean;\n\n\t/**\n\t * Cache of MeterProvider+Meter+instruments keyed by \"nodeId/tenantId\".\n\t * Providers are created on demand when the first metric measurement arrives\n\t * for a given tenant/node pair.\n\t * @internal\n\t */\n\tprivate readonly _providers: {\n\t\t[key: string]: {\n\t\t\tmeterProvider: MeterProvider;\n\t\t\tmeter: Meter;\n\t\t\tinstruments: {\n\t\t\t\t[id: string]: { metricType: MetricType; instrument: Counter | UpDownCounter | Gauge };\n\t\t\t};\n\t\t};\n\t};\n\n\t/**\n\t * In-memory metric definition registry keyed by metric id.\n\t * @internal\n\t */\n\tprivate readonly _metricDefs: {\n\t\t[id: string]: { type: MetricType; label: string; description?: string; unit?: string };\n\t};\n\n\t/**\n\t * Create a new instance of OpenTelemetryTelemetryConnector.\n\t * @param options The options for the connector.\n\t * @throws GuardError When a reader config specifies an unsupported type.\n\t */\n\tconstructor(options?: IOpenTelemetryTelemetryConnectorConstructorOptions) {\n\t\tthis._config = options?.config ?? {};\n\n\t\tfor (const [, readerConfig] of Object.entries(this._config.readers ?? {})) {\n\t\t\tGuards.arrayOneOf(\n\t\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\t\tnameof(readerConfig.type),\n\t\t\t\treaderConfig.type,\n\t\t\t\tObject.values(OpenTelemetryReaderTypes)\n\t\t\t);\n\t\t}\n\n\t\tthis._started = false;\n\t\tthis._providers = {};\n\t\tthis._metricDefs = {};\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn OpenTelemetryTelemetryConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Enable OTEL forwarding. Subsequent calls to addMetricValue will create\n\t * per-tenant/node MeterProviders on demand.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when OTEL forwarding is enabled.\n\t */\n\tpublic async start(nodeLoggingComponentType?: string): Promise<void> {\n\t\tif (this._started) {\n\t\t\treturn;\n\t\t}\n\t\tthis._started = true;\n\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\t\tawait nodeLogging?.log({\n\t\t\tsource: OpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\tmessage: \"connectorStarted\",\n\t\t\tlevel: \"info\",\n\t\t\tdata: { readerCount: Object.keys(this._config.readers ?? {}).length }\n\t\t});\n\t}\n\n\t/**\n\t * Shut down all cached MeterProviders and disable OTEL forwarding.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when all MeterProviders have shut down.\n\t */\n\tpublic async stop(nodeLoggingComponentType?: string): Promise<void> {\n\t\tif (this._started) {\n\t\t\tfor (const { meterProvider } of Object.values(this._providers)) {\n\t\t\t\tawait meterProvider.shutdown();\n\t\t\t}\n\t\t\tfor (const key of Object.keys(this._providers)) {\n\t\t\t\tdelete this._providers[key];\n\t\t\t}\n\t\t\tthis._started = false;\n\n\t\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tsource: OpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\t\tmessage: \"connectorStopped\",\n\t\t\t\tlevel: \"info\",\n\t\t\t\tdata: {}\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Register one or more metric definitions. If the connector is already started,\n\t * the OTEL instrument is registered immediately for the current context.\n\t * @param metric The metric details, or the details of several metrics.\n\t * @returns A promise that resolves when the metrics have been registered.\n\t */\n\tpublic async createMetric(metric: ITelemetryMetric | ITelemetryMetric[]): Promise<void> {\n\t\tif (Is.array<ITelemetryMetric>(metric)) {\n\t\t\t// An array declares the set that should exist, so the ones already registered are\n\t\t\t// left alone. The definitions are held in memory, there is nothing to batch into.\n\t\t\tfor (const entry of metric) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.createMetric(entry);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tif (!BaseError.isErrorName(err, AlreadyExistsError.CLASS_NAME)) {\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tGuards.object<ITelemetryMetric>(\n\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\tnameof(metric),\n\t\t\tmetric\n\t\t);\n\t\tGuards.stringValue(OpenTelemetryTelemetryConnector.CLASS_NAME, nameof(metric.id), metric.id);\n\t\tGuards.stringValue(\n\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\tnameof(metric.label),\n\t\t\tmetric.label\n\t\t);\n\n\t\tthis._metricDefs[metric.id] = {\n\t\t\ttype: metric.type,\n\t\t\tlabel: metric.label,\n\t\t\tdescription: metric.description,\n\t\t\tunit: metric.unit\n\t\t};\n\n\t\tif (this._started) {\n\t\t\tconst contextIds = (await ContextIdStore.getContextIds()) ?? {};\n\t\t\tconst { meter, instruments } = this.getOrCreateProvider(contextIds);\n\t\t\tthis.registerInstrument(\n\t\t\t\tmetric.id,\n\t\t\t\tmetric.type,\n\t\t\t\tmetric.description,\n\t\t\t\tmetric.unit,\n\t\t\t\tmeter,\n\t\t\t\tinstruments\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Update the in-memory metadata for a registered metric.\n\t * OpenTelemetry instrument descriptors are immutable once created; only the\n\t * cached label, description and unit are updated.\n\t * @param metric The metric details (type cannot be changed).\n\t * @returns A promise that resolves when the metadata has been updated.\n\t */\n\tpublic async updateMetric(metric: Omit<ITelemetryMetric, \"type\">): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(\n\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\tnameof(metric),\n\t\t\tmetric\n\t\t);\n\t\tGuards.stringValue(OpenTelemetryTelemetryConnector.CLASS_NAME, nameof(metric.id), metric.id);\n\n\t\tconst def = this._metricDefs[metric.id];\n\t\tif (Is.undefined(def)) {\n\t\t\tthrow new NotFoundError(\n\t\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\t\t\"metricNotFound\",\n\t\t\t\tmetric.id\n\t\t\t);\n\t\t}\n\n\t\tthis._metricDefs[metric.id] = {\n\t\t\ttype: def.type,\n\t\t\tlabel: metric.label,\n\t\t\tdescription: metric.description,\n\t\t\tunit: metric.unit\n\t\t};\n\t}\n\n\t/**\n\t * Record a metric value and forward it to the appropriate OTEL instrument.\n\t * The current tenant and node IDs are read from `ContextIdStore` and used to\n\t * select (or create) the matching per-tenant/node `MeterProvider`.\n\t * @param id The id of the metric.\n\t * @param value The value for the operation.\n\t * @param customData Optional custom data forwarded as OTEL attributes.\n\t * @returns A generated 32-character hex id for the recorded value.\n\t */\n\tpublic async addMetricValue(\n\t\tid: string,\n\t\tvalue: MetricCounterOperation | number,\n\t\tcustomData?: { [key: string]: unknown }\n\t): Promise<string> {\n\t\tGuards.stringValue(OpenTelemetryTelemetryConnector.CLASS_NAME, nameof(id), id);\n\t\tGuards.defined(OpenTelemetryTelemetryConnector.CLASS_NAME, nameof(value), value);\n\n\t\tconst def = this._metricDefs[id];\n\t\tif (Is.undefined(def)) {\n\t\t\tthrow new NotFoundError(OpenTelemetryTelemetryConnector.CLASS_NAME, \"metricNotFound\", id);\n\t\t}\n\n\t\tif (def.type === MetricType.Counter) {\n\t\t\tif (value !== MetricCounterOperation.Increment && (!Is.integer(value) || value <= 0)) {\n\t\t\t\tthrow new GeneralError(OpenTelemetryTelemetryConnector.CLASS_NAME, \"counterIncOnly\");\n\t\t\t}\n\t\t} else if (def.type === MetricType.Gauge) {\n\t\t\tif (!Is.number(value)) {\n\t\t\t\tthrow new GeneralError(OpenTelemetryTelemetryConnector.CLASS_NAME, \"gaugeNoIncDec\");\n\t\t\t}\n\t\t}\n\n\t\tconst valueId = Converter.bytesToHex(RandomHelper.generate(16));\n\n\t\tif (this._started) {\n\t\t\tconst contextIds = (await ContextIdStore.getContextIds()) ?? {};\n\t\t\tconst { meter, instruments } = this.getOrCreateProvider(contextIds);\n\n\t\t\tif (!(id in instruments)) {\n\t\t\t\tthis.registerInstrument(id, def.type, def.description, def.unit, meter, instruments);\n\t\t\t}\n\n\t\t\tconst entry = instruments[id];\n\t\t\tif (entry !== undefined) {\n\t\t\t\tconst attributes = this.toAttributes(customData);\n\t\t\t\tconst { metricType, instrument } = entry;\n\n\t\t\t\tif (metricType === MetricType.Counter) {\n\t\t\t\t\t(instrument as Counter).add(\n\t\t\t\t\t\tvalue === MetricCounterOperation.Increment ? 1 : (value as number),\n\t\t\t\t\t\tattributes\n\t\t\t\t\t);\n\t\t\t\t} else if (metricType === MetricType.IncDecCounter) {\n\t\t\t\t\tlet delta: number;\n\t\t\t\t\tif (value === MetricCounterOperation.Increment) {\n\t\t\t\t\t\tdelta = 1;\n\t\t\t\t\t} else if (value === MetricCounterOperation.Decrement) {\n\t\t\t\t\t\tdelta = -1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdelta = value;\n\t\t\t\t\t}\n\t\t\t\t\t(instrument as UpDownCounter).add(delta, attributes);\n\t\t\t\t} else {\n\t\t\t\t\t(instrument as Gauge).record(value as number, attributes);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn valueId;\n\t}\n\n\t/**\n\t * Add multiple metric values.\n\t * @param values The metric values to add.\n\t * @returns The created metric value ids, in the order the values were supplied.\n\t */\n\tpublic async addMetricValues(values: ITelemetryMetricValueEntry[]): Promise<string[]> {\n\t\tGuards.array<ITelemetryMetricValueEntry>(\n\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\tnameof(values),\n\t\t\tvalues\n\t\t);\n\n\t\t// The instruments are recorded one at a time, there is nothing to batch into.\n\t\tconst valueIds: string[] = [];\n\t\tfor (const entry of values) {\n\t\t\tvalueIds.push(await this.addMetricValue(entry.id, entry.value, entry.customData));\n\t\t}\n\t\treturn valueIds;\n\t}\n\n\t/**\n\t * Remove a metric from the in-memory registry and from all cached provider instrument maps.\n\t * @param id The id of the metric.\n\t * @returns A promise that resolves when the metric has been removed.\n\t */\n\tpublic async removeMetric(id: string): Promise<void> {\n\t\tGuards.stringValue(OpenTelemetryTelemetryConnector.CLASS_NAME, nameof(id), id);\n\n\t\tif (Is.undefined(this._metricDefs[id])) {\n\t\t\tthrow new NotFoundError(OpenTelemetryTelemetryConnector.CLASS_NAME, \"metricNotFound\", id);\n\t\t}\n\n\t\tfor (const { instruments } of Object.values(this._providers)) {\n\t\t\tdelete instruments[id];\n\t\t}\n\t\tdelete this._metricDefs[id];\n\t}\n\n\t/**\n\t * Return or create the MeterProvider for the given tenant/node pair.\n\t * @param contextIds The current execution context IDs.\n\t * @returns The cached or newly created provider entry.\n\t * @internal\n\t */\n\tprivate getOrCreateProvider(contextIds: IContextIds): {\n\t\tmeterProvider: MeterProvider;\n\t\tmeter: Meter;\n\t\tinstruments: {\n\t\t\t[id: string]: { metricType: MetricType; instrument: Counter | UpDownCounter | Gauge };\n\t\t};\n\t} {\n\t\tconst node = contextIds[ContextIdKeys.Node];\n\t\tconst tenantId = contextIds[ContextIdKeys.Tenant];\n\n\t\tconst key = `${node ?? \"\"}/${tenantId ?? \"\"}`;\n\n\t\tlet cached = this._providers[key];\n\t\tif (!Is.undefined(cached)) {\n\t\t\treturn cached;\n\t\t}\n\n\t\tconst readers = this.createReaders();\n\t\tconst resourcePrefix = \"service\";\n\t\tconst resourceAttrs: { [id: string]: string } = {};\n\t\tif (Is.stringValue(node)) {\n\t\t\tresourceAttrs[`${resourcePrefix}.instance.id`] = node;\n\t\t}\n\t\tif (Is.stringValue(tenantId)) {\n\t\t\tresourceAttrs[`${resourcePrefix}.namespace`] = tenantId;\n\t\t}\n\t\tconst resource =\n\t\t\tObject.keys(resourceAttrs).length > 0 ? resourceFromAttributes(resourceAttrs) : undefined;\n\t\tconst meterProvider = new MeterProvider({ readers, resource });\n\t\tconst meter = meterProvider.getMeter(\n\t\t\tthis._config.meterName ?? \"twin-telemetry\",\n\t\t\tthis._config.meterVersion ?? \"1.0.0\"\n\t\t);\n\t\tcached = { meterProvider, meter, instruments: {} };\n\t\tthis._providers[key] = cached;\n\n\t\treturn cached;\n\t}\n\n\t/**\n\t * Instantiate fresh MetricReader instances from the connector config.\n\t * @returns The list of reader instances.\n\t * @internal\n\t */\n\tprivate createReaders(): MetricReader[] {\n\t\tconst readers: MetricReader[] = [];\n\t\tfor (const [, config] of Object.entries(this._config.readers ?? {})) {\n\t\t\tif (config.type === OpenTelemetryReaderTypes.Prometheus) {\n\t\t\t\treaders.push(\n\t\t\t\t\tnew PrometheusExporter({\n\t\t\t\t\t\tport: config.port,\n\t\t\t\t\t\tendpoint: config.endpoint,\n\t\t\t\t\t\tpreventServerStart: !(config.startServer ?? true),\n\t\t\t\t\t\tprefix: config.prefix\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t} else if (config.type === OpenTelemetryReaderTypes.OtlpHttp) {\n\t\t\t\treaders.push(\n\t\t\t\t\tnew PeriodicExportingMetricReader({\n\t\t\t\t\t\texporter: new OTLPMetricExporter({\n\t\t\t\t\t\t\turl: config.url,\n\t\t\t\t\t\t\theaders: config.headers\n\t\t\t\t\t\t}),\n\t\t\t\t\t\texportIntervalMillis: config.exportIntervalMs\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn readers;\n\t}\n\n\t/**\n\t * Register an OTEL instrument on a provider's instruments map if not already present.\n\t * @param id The metric id.\n\t * @param type The metric type.\n\t * @param description The metric description.\n\t * @param unit The metric unit.\n\t * @param meter The meter to create instruments on.\n\t * @param instruments The per-provider instruments map to update.\n\t * @internal\n\t */\n\tprivate registerInstrument(\n\t\tid: string,\n\t\ttype: MetricType,\n\t\tdescription: string | undefined,\n\t\tunit: string | undefined,\n\t\tmeter: Meter,\n\t\tinstruments: {\n\t\t\t[id: string]: { metricType: MetricType; instrument: Counter | UpDownCounter | Gauge };\n\t\t}\n\t): void {\n\t\tif (id in instruments) {\n\t\t\treturn;\n\t\t}\n\t\tconst instrumentOptions = { description, unit };\n\t\tlet instrument: Counter | UpDownCounter | Gauge;\n\t\tif (type === MetricType.Counter) {\n\t\t\tinstrument = meter.createCounter(id, instrumentOptions);\n\t\t} else if (type === MetricType.IncDecCounter) {\n\t\t\tinstrument = meter.createUpDownCounter(id, instrumentOptions);\n\t\t} else {\n\t\t\tinstrument = meter.createGauge(id, instrumentOptions);\n\t\t}\n\t\tinstruments[id] = { metricType: type, instrument };\n\t}\n\n\t/**\n\t * Convert customData to OTEL-compatible Attributes.\n\t * @param customData The raw custom data map.\n\t * @returns An OTEL Attributes object.\n\t * @internal\n\t */\n\tprivate toAttributes(customData?: { [key: string]: unknown }): Attributes {\n\t\tif (Is.empty(customData)) {\n\t\t\treturn {};\n\t\t}\n\t\tconst attributes: Attributes = {};\n\t\tfor (const [key, val] of Object.entries(customData)) {\n\t\t\tif (Is.string(val) || Is.number(val) || Is.boolean(val)) {\n\t\t\t\tattributes[key] = val;\n\t\t\t} else if (Is.arrayValue(val)) {\n\t\t\t\tif (Is.string(val[0]) && val.every(el => Is.string(el))) {\n\t\t\t\t\tattributes[key] = val;\n\t\t\t\t} else if (Is.number(val[0]) && val.every(el => Is.number(el))) {\n\t\t\t\t\tattributes[key] = val;\n\t\t\t\t} else if (Is.boolean(val[0]) && val.every(el => Is.boolean(el))) {\n\t\t\t\t\tattributes[key] = val;\n\t\t\t\t} else {\n\t\t\t\t\tattributes[key] = JSON.stringify(val);\n\t\t\t\t}\n\t\t\t} else if (!Is.undefined(val)) {\n\t\t\t\tattributes[key] = JSON.stringify(val);\n\t\t\t}\n\t\t}\n\t\treturn attributes;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"openTelemetryTelemetryConnector.js","sources":["../../src/openTelemetryTelemetryConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAoB,MAAM,iBAAiB,CAAC;AAClF,OAAO,EACN,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,aAAa,EACb,YAAY,EACZ,MAAM,cAAc,CAAC;AAGtB,OAAO,EAIN,sBAAsB,EACtB,UAAU,EACV,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,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AAS,CAAC,GAAG,CAAC,CAAC;gBACvC,CAAC;YACF,CAAC;iBAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC/B,UAAU,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACvC,CAAC;QACF,CAAC;QACD,OAAO,UAAU,CAAC;IACnB,CAAC;CACD","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ContextIdKeys, ContextIdStore, type IContextIds } from \"@3sixty/context\";\nimport {\n\tAlreadyExistsError,\n\tBaseError,\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tNotFoundError,\n\tRandomHelper\n} from \"@3sixty/core\";\nimport type { ILoggingComponent } from \"@3sixty/logging-models\";\n\nimport {\n\ttype ITelemetryConnector,\n\ttype ITelemetryMetric,\n\ttype ITelemetryMetricValueEntry,\n\tMetricCounterOperation,\n\tMetricType\n} from \"@3sixty/telemetry-models\";\nimport type { Attributes, Counter, Gauge, Meter, UpDownCounter } from \"@opentelemetry/api\";\nimport { OTLPMetricExporter } from \"@opentelemetry/exporter-metrics-otlp-http\";\nimport { PrometheusExporter } from \"@opentelemetry/exporter-prometheus\";\nimport { resourceFromAttributes } from \"@opentelemetry/resources\";\nimport {\n\tMeterProvider,\n\tPeriodicExportingMetricReader,\n\ttype MetricReader\n} from \"@opentelemetry/sdk-metrics\";\nimport type { IOpenTelemetryTelemetryConnectorConfig } from \"./models/IOpenTelemetryTelemetryConnectorConfig.js\";\nimport type { IOpenTelemetryTelemetryConnectorConstructorOptions } from \"./models/IOpenTelemetryTelemetryConnectorConstructorOptions.js\";\nimport { OpenTelemetryReaderTypes } from \"./models/openTelemetryReaderTypes.js\";\n\n/**\n * Class for performing telemetry operations using OpenTelemetry instruments.\n * Metric definitions are held in memory. Persistence and querying are not supported;\n * use a multi-connector with an EntityStorageTelemetryConnector for those capabilities.\n */\nexport class OpenTelemetryTelemetryConnector implements ITelemetryConnector {\n\t/**\n\t * The namespace supported by the telemetry connector.\n\t */\n\tpublic static readonly NAMESPACE: string = \"open-telemetry\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"OpenTelemetryTelemetryConnector\";\n\n\t/**\n\t * Config options stored so provider creation can initialise readers and meter identity.\n\t * @internal\n\t */\n\tprivate readonly _config: IOpenTelemetryTelemetryConnectorConfig;\n\n\t/**\n\t * Whether start() has been called. Drives OTEL forwarding on/off.\n\t * @internal\n\t */\n\tprivate _started: boolean;\n\n\t/**\n\t * Cache of MeterProvider+Meter+instruments keyed by \"nodeId/tenantId\".\n\t * Providers are created on demand when the first metric measurement arrives\n\t * for a given tenant/node pair.\n\t * @internal\n\t */\n\tprivate readonly _providers: {\n\t\t[key: string]: {\n\t\t\tmeterProvider: MeterProvider;\n\t\t\tmeter: Meter;\n\t\t\tinstruments: {\n\t\t\t\t[id: string]: { metricType: MetricType; instrument: Counter | UpDownCounter | Gauge };\n\t\t\t};\n\t\t};\n\t};\n\n\t/**\n\t * In-memory metric definition registry keyed by metric id.\n\t * @internal\n\t */\n\tprivate readonly _metricDefs: {\n\t\t[id: string]: { type: MetricType; label: string; description?: string; unit?: string };\n\t};\n\n\t/**\n\t * Create a new instance of OpenTelemetryTelemetryConnector.\n\t * @param options The options for the connector.\n\t * @throws GuardError When a reader config specifies an unsupported type.\n\t */\n\tconstructor(options?: IOpenTelemetryTelemetryConnectorConstructorOptions) {\n\t\tthis._config = options?.config ?? {};\n\n\t\tfor (const [, readerConfig] of Object.entries(this._config.readers ?? {})) {\n\t\t\tGuards.arrayOneOf(\n\t\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\t\t\"readerConfig.type\",\n\t\t\t\treaderConfig.type,\n\t\t\t\tObject.values(OpenTelemetryReaderTypes)\n\t\t\t);\n\t\t}\n\n\t\tthis._started = false;\n\t\tthis._providers = {};\n\t\tthis._metricDefs = {};\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn OpenTelemetryTelemetryConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Enable OTEL forwarding. Subsequent calls to addMetricValue will create\n\t * per-tenant/node MeterProviders on demand.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when OTEL forwarding is enabled.\n\t */\n\tpublic async start(nodeLoggingComponentType?: string): Promise<void> {\n\t\tif (this._started) {\n\t\t\treturn;\n\t\t}\n\t\tthis._started = true;\n\n\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\t\tawait nodeLogging?.log({\n\t\t\tsource: OpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\tmessage: \"connectorStarted\",\n\t\t\tlevel: \"info\",\n\t\t\tdata: { readerCount: Object.keys(this._config.readers ?? {}).length }\n\t\t});\n\t}\n\n\t/**\n\t * Shut down all cached MeterProviders and disable OTEL forwarding.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when all MeterProviders have shut down.\n\t */\n\tpublic async stop(nodeLoggingComponentType?: string): Promise<void> {\n\t\tif (this._started) {\n\t\t\tfor (const { meterProvider } of Object.values(this._providers)) {\n\t\t\t\tawait meterProvider.shutdown();\n\t\t\t}\n\t\t\tfor (const key of Object.keys(this._providers)) {\n\t\t\t\tdelete this._providers[key];\n\t\t\t}\n\t\t\tthis._started = false;\n\n\t\t\tconst nodeLogging = ComponentFactory.getIfExists<ILoggingComponent>(nodeLoggingComponentType);\n\t\t\tawait nodeLogging?.log({\n\t\t\t\tsource: OpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\t\tmessage: \"connectorStopped\",\n\t\t\t\tlevel: \"info\",\n\t\t\t\tdata: {}\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Register one or more metric definitions. If the connector is already started,\n\t * the OTEL instrument is registered immediately for the current context.\n\t * @param metric The metric details, or the details of several metrics.\n\t * @returns A promise that resolves when the metrics have been registered.\n\t */\n\tpublic async createMetric(metric: ITelemetryMetric | ITelemetryMetric[]): Promise<void> {\n\t\tif (Is.array<ITelemetryMetric>(metric)) {\n\t\t\t// An array declares the set that should exist, so the ones already registered are\n\t\t\t// left alone. The definitions are held in memory, there is nothing to batch into.\n\t\t\tfor (const entry of metric) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.createMetric(entry);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tif (!BaseError.isErrorName(err, AlreadyExistsError.CLASS_NAME)) {\n\t\t\t\t\t\tthrow err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tGuards.object<ITelemetryMetric>(\n\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\t\"metric\",\n\t\t\tmetric\n\t\t);\n\t\tGuards.stringValue(OpenTelemetryTelemetryConnector.CLASS_NAME, \"metric.id\", metric.id);\n\t\tGuards.stringValue(\n\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\t\"metric.label\",\n\t\t\tmetric.label\n\t\t);\n\n\t\tthis._metricDefs[metric.id] = {\n\t\t\ttype: metric.type,\n\t\t\tlabel: metric.label,\n\t\t\tdescription: metric.description,\n\t\t\tunit: metric.unit\n\t\t};\n\n\t\tif (this._started) {\n\t\t\tconst contextIds = (await ContextIdStore.getContextIds()) ?? {};\n\t\t\tconst { meter, instruments } = this.getOrCreateProvider(contextIds);\n\t\t\tthis.registerInstrument(\n\t\t\t\tmetric.id,\n\t\t\t\tmetric.type,\n\t\t\t\tmetric.description,\n\t\t\t\tmetric.unit,\n\t\t\t\tmeter,\n\t\t\t\tinstruments\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Update the in-memory metadata for a registered metric.\n\t * OpenTelemetry instrument descriptors are immutable once created; only the\n\t * cached label, description and unit are updated.\n\t * @param metric The metric details (type cannot be changed).\n\t * @returns A promise that resolves when the metadata has been updated.\n\t */\n\tpublic async updateMetric(metric: Omit<ITelemetryMetric, \"type\">): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(\n\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\t\"metric\",\n\t\t\tmetric\n\t\t);\n\t\tGuards.stringValue(OpenTelemetryTelemetryConnector.CLASS_NAME, \"metric.id\", metric.id);\n\n\t\tconst def = this._metricDefs[metric.id];\n\t\tif (Is.undefined(def)) {\n\t\t\tthrow new NotFoundError(\n\t\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\t\t\"metricNotFound\",\n\t\t\t\tmetric.id\n\t\t\t);\n\t\t}\n\n\t\tthis._metricDefs[metric.id] = {\n\t\t\ttype: def.type,\n\t\t\tlabel: metric.label,\n\t\t\tdescription: metric.description,\n\t\t\tunit: metric.unit\n\t\t};\n\t}\n\n\t/**\n\t * Record a metric value and forward it to the appropriate OTEL instrument.\n\t * The current tenant and node IDs are read from `ContextIdStore` and used to\n\t * select (or create) the matching per-tenant/node `MeterProvider`.\n\t * @param id The id of the metric.\n\t * @param value The value for the operation.\n\t * @param customData Optional custom data forwarded as OTEL attributes.\n\t * @returns A generated 32-character hex id for the recorded value.\n\t */\n\tpublic async addMetricValue(\n\t\tid: string,\n\t\tvalue: MetricCounterOperation | number,\n\t\tcustomData?: { [key: string]: unknown }\n\t): Promise<string> {\n\t\tGuards.stringValue(OpenTelemetryTelemetryConnector.CLASS_NAME, \"id\", id);\n\t\tGuards.defined(OpenTelemetryTelemetryConnector.CLASS_NAME, \"value\", value);\n\n\t\tconst def = this._metricDefs[id];\n\t\tif (Is.undefined(def)) {\n\t\t\tthrow new NotFoundError(OpenTelemetryTelemetryConnector.CLASS_NAME, \"metricNotFound\", id);\n\t\t}\n\n\t\tif (def.type === MetricType.Counter) {\n\t\t\tif (value !== MetricCounterOperation.Increment && (!Is.integer(value) || value <= 0)) {\n\t\t\t\tthrow new GeneralError(OpenTelemetryTelemetryConnector.CLASS_NAME, \"counterIncOnly\");\n\t\t\t}\n\t\t} else if (def.type === MetricType.Gauge) {\n\t\t\tif (!Is.number(value)) {\n\t\t\t\tthrow new GeneralError(OpenTelemetryTelemetryConnector.CLASS_NAME, \"gaugeNoIncDec\");\n\t\t\t}\n\t\t}\n\n\t\tconst valueId = Converter.bytesToHex(RandomHelper.generate(16));\n\n\t\tif (this._started) {\n\t\t\tconst contextIds = (await ContextIdStore.getContextIds()) ?? {};\n\t\t\tconst { meter, instruments } = this.getOrCreateProvider(contextIds);\n\n\t\t\tif (!(id in instruments)) {\n\t\t\t\tthis.registerInstrument(id, def.type, def.description, def.unit, meter, instruments);\n\t\t\t}\n\n\t\t\tconst entry = instruments[id];\n\t\t\tif (entry !== undefined) {\n\t\t\t\tconst attributes = this.toAttributes(customData);\n\t\t\t\tconst { metricType, instrument } = entry;\n\n\t\t\t\tif (metricType === MetricType.Counter) {\n\t\t\t\t\t(instrument as Counter).add(\n\t\t\t\t\t\tvalue === MetricCounterOperation.Increment ? 1 : (value as number),\n\t\t\t\t\t\tattributes\n\t\t\t\t\t);\n\t\t\t\t} else if (metricType === MetricType.IncDecCounter) {\n\t\t\t\t\tlet delta: number;\n\t\t\t\t\tif (value === MetricCounterOperation.Increment) {\n\t\t\t\t\t\tdelta = 1;\n\t\t\t\t\t} else if (value === MetricCounterOperation.Decrement) {\n\t\t\t\t\t\tdelta = -1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tdelta = value;\n\t\t\t\t\t}\n\t\t\t\t\t(instrument as UpDownCounter).add(delta, attributes);\n\t\t\t\t} else {\n\t\t\t\t\t(instrument as Gauge).record(value as number, attributes);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn valueId;\n\t}\n\n\t/**\n\t * Add multiple metric values.\n\t * @param values The metric values to add.\n\t * @returns The created metric value ids, in the order the values were supplied.\n\t */\n\tpublic async addMetricValues(values: ITelemetryMetricValueEntry[]): Promise<string[]> {\n\t\tGuards.array<ITelemetryMetricValueEntry>(\n\t\t\tOpenTelemetryTelemetryConnector.CLASS_NAME,\n\t\t\t\"values\",\n\t\t\tvalues\n\t\t);\n\n\t\t// The instruments are recorded one at a time, there is nothing to batch into.\n\t\tconst valueIds: string[] = [];\n\t\tfor (const entry of values) {\n\t\t\tvalueIds.push(await this.addMetricValue(entry.id, entry.value, entry.customData));\n\t\t}\n\t\treturn valueIds;\n\t}\n\n\t/**\n\t * Remove a metric from the in-memory registry and from all cached provider instrument maps.\n\t * @param id The id of the metric.\n\t * @returns A promise that resolves when the metric has been removed.\n\t */\n\tpublic async removeMetric(id: string): Promise<void> {\n\t\tGuards.stringValue(OpenTelemetryTelemetryConnector.CLASS_NAME, \"id\", id);\n\n\t\tif (Is.undefined(this._metricDefs[id])) {\n\t\t\tthrow new NotFoundError(OpenTelemetryTelemetryConnector.CLASS_NAME, \"metricNotFound\", id);\n\t\t}\n\n\t\tfor (const { instruments } of Object.values(this._providers)) {\n\t\t\tdelete instruments[id];\n\t\t}\n\t\tdelete this._metricDefs[id];\n\t}\n\n\t/**\n\t * Return or create the MeterProvider for the given tenant/node pair.\n\t * @param contextIds The current execution context IDs.\n\t * @returns The cached or newly created provider entry.\n\t * @internal\n\t */\n\tprivate getOrCreateProvider(contextIds: IContextIds): {\n\t\tmeterProvider: MeterProvider;\n\t\tmeter: Meter;\n\t\tinstruments: {\n\t\t\t[id: string]: { metricType: MetricType; instrument: Counter | UpDownCounter | Gauge };\n\t\t};\n\t} {\n\t\tconst node = contextIds[ContextIdKeys.Node];\n\t\tconst tenantId = contextIds[ContextIdKeys.Tenant];\n\n\t\tconst key = `${node ?? \"\"}/${tenantId ?? \"\"}`;\n\n\t\tlet cached = this._providers[key];\n\t\tif (!Is.undefined(cached)) {\n\t\t\treturn cached;\n\t\t}\n\n\t\tconst readers = this.createReaders();\n\t\tconst resourcePrefix = \"service\";\n\t\tconst resourceAttrs: { [id: string]: string } = {};\n\t\tif (Is.stringValue(node)) {\n\t\t\tresourceAttrs[`${resourcePrefix}.instance.id`] = node;\n\t\t}\n\t\tif (Is.stringValue(tenantId)) {\n\t\t\tresourceAttrs[`${resourcePrefix}.namespace`] = tenantId;\n\t\t}\n\t\tconst resource =\n\t\t\tObject.keys(resourceAttrs).length > 0 ? resourceFromAttributes(resourceAttrs) : undefined;\n\t\tconst meterProvider = new MeterProvider({ readers, resource });\n\t\tconst meter = meterProvider.getMeter(\n\t\t\tthis._config.meterName ?? \"twin-telemetry\",\n\t\t\tthis._config.meterVersion ?? \"1.0.0\"\n\t\t);\n\t\tcached = { meterProvider, meter, instruments: {} };\n\t\tthis._providers[key] = cached;\n\n\t\treturn cached;\n\t}\n\n\t/**\n\t * Instantiate fresh MetricReader instances from the connector config.\n\t * @returns The list of reader instances.\n\t * @internal\n\t */\n\tprivate createReaders(): MetricReader[] {\n\t\tconst readers: MetricReader[] = [];\n\t\tfor (const [, config] of Object.entries(this._config.readers ?? {})) {\n\t\t\tif (config.type === OpenTelemetryReaderTypes.Prometheus) {\n\t\t\t\treaders.push(\n\t\t\t\t\tnew PrometheusExporter({\n\t\t\t\t\t\tport: config.port,\n\t\t\t\t\t\tendpoint: config.endpoint,\n\t\t\t\t\t\tpreventServerStart: !(config.startServer ?? true),\n\t\t\t\t\t\tprefix: config.prefix\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t} else if (config.type === OpenTelemetryReaderTypes.OtlpHttp) {\n\t\t\t\treaders.push(\n\t\t\t\t\tnew PeriodicExportingMetricReader({\n\t\t\t\t\t\texporter: new OTLPMetricExporter({\n\t\t\t\t\t\t\turl: config.url,\n\t\t\t\t\t\t\theaders: config.headers\n\t\t\t\t\t\t}),\n\t\t\t\t\t\texportIntervalMillis: config.exportIntervalMs\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn readers;\n\t}\n\n\t/**\n\t * Register an OTEL instrument on a provider's instruments map if not already present.\n\t * @param id The metric id.\n\t * @param type The metric type.\n\t * @param description The metric description.\n\t * @param unit The metric unit.\n\t * @param meter The meter to create instruments on.\n\t * @param instruments The per-provider instruments map to update.\n\t * @internal\n\t */\n\tprivate registerInstrument(\n\t\tid: string,\n\t\ttype: MetricType,\n\t\tdescription: string | undefined,\n\t\tunit: string | undefined,\n\t\tmeter: Meter,\n\t\tinstruments: {\n\t\t\t[id: string]: { metricType: MetricType; instrument: Counter | UpDownCounter | Gauge };\n\t\t}\n\t): void {\n\t\tif (id in instruments) {\n\t\t\treturn;\n\t\t}\n\t\tconst instrumentOptions = { description, unit };\n\t\tlet instrument: Counter | UpDownCounter | Gauge;\n\t\tif (type === MetricType.Counter) {\n\t\t\tinstrument = meter.createCounter(id, instrumentOptions);\n\t\t} else if (type === MetricType.IncDecCounter) {\n\t\t\tinstrument = meter.createUpDownCounter(id, instrumentOptions);\n\t\t} else {\n\t\t\tinstrument = meter.createGauge(id, instrumentOptions);\n\t\t}\n\t\tinstruments[id] = { metricType: type, instrument };\n\t}\n\n\t/**\n\t * Convert customData to OTEL-compatible Attributes.\n\t * @param customData The raw custom data map.\n\t * @returns An OTEL Attributes object.\n\t * @internal\n\t */\n\tprivate toAttributes(customData?: { [key: string]: unknown }): Attributes {\n\t\tif (Is.empty(customData)) {\n\t\t\treturn {};\n\t\t}\n\t\tconst attributes: Attributes = {};\n\t\tfor (const [key, val] of Object.entries(customData)) {\n\t\t\tif (Is.string(val) || Is.number(val) || Is.boolean(val)) {\n\t\t\t\tattributes[key] = val;\n\t\t\t} else if (Is.arrayValue(val)) {\n\t\t\t\tif (Is.string(val[0]) && val.every(el => Is.string(el))) {\n\t\t\t\t\tattributes[key] = val;\n\t\t\t\t} else if (Is.number(val[0]) && val.every(el => Is.number(el))) {\n\t\t\t\t\tattributes[key] = val;\n\t\t\t\t} else if (Is.boolean(val[0]) && val.every(el => Is.boolean(el))) {\n\t\t\t\t\tattributes[key] = val;\n\t\t\t\t} else {\n\t\t\t\t\tattributes[key] = JSON.stringify(val);\n\t\t\t\t}\n\t\t\t} else if (!Is.undefined(val)) {\n\t\t\t\tattributes[key] = JSON.stringify(val);\n\t\t\t}\n\t\t}\n\t\treturn attributes;\n\t}\n}\n"]}
|
package/docs/changelog.md
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.20.0-next.2](https://github.com/3sixtyglobal/telemetry/compare/telemetry-connector-opentelemetry-v0.20.0-next.1...telemetry-connector-opentelemetry-v0.20.0-next.2) (2026-10-26)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* release to next [skip ci] ([#22](https://github.com/3sixtyglobal/telemetry/issues/22)) ([274c07f](https://github.com/3sixtyglobal/telemetry/commit/274c07f0f0f405c55b73703933759223435e1f70))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @3sixty/telemetry-connector-entity-storage bumped from 0.20.0-next.1 to 0.20.0-next.2
|
|
16
|
+
* @3sixty/telemetry-models bumped from 0.20.0-next.1 to 0.20.0-next.2
|
|
17
|
+
|
|
18
|
+
## [0.20.0-next.1](https://github.com/3sixtyglobal/telemetry/compare/telemetry-connector-opentelemetry-v0.20.0-next.0...telemetry-connector-opentelemetry-v0.20.0-next.1) (2026-10-23)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* publish packages under the [@3sixty](https://github.com/3sixty) namespace ([e488a8c](https://github.com/3sixtyglobal/telemetry/commit/e488a8cbe26251de694077a0164af480cab61c3a))
|
|
24
|
+
* updated ts compile ([4490a7b](https://github.com/3sixtyglobal/telemetry/commit/4490a7b854bdea72a79946d2dbb708a47e81b56f))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Dependencies
|
|
28
|
+
|
|
29
|
+
* The following workspace dependencies were updated
|
|
30
|
+
* dependencies
|
|
31
|
+
* @3sixty/telemetry-connector-entity-storage bumped from 0.20.0-next.0 to 0.20.0-next.1
|
|
32
|
+
* @3sixty/telemetry-models bumped from 0.20.0-next.0 to 0.20.0-next.1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@3sixty/telemetry-connector-opentelemetry",
|
|
3
|
-
"version": "0.20.0-next.
|
|
3
|
+
"version": "0.20.0-next.2",
|
|
4
4
|
"description": "OpenTelemetry connector for pushing telemetry metrics to OTEL-compatible backends.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,21 +11,22 @@
|
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=24.0.0"
|
|
14
|
+
"node": ">=24.0.0",
|
|
15
|
+
"bun": ">=1.4.4"
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@opentelemetry/api": "1.9.1",
|
|
18
|
-
"@opentelemetry/exporter-metrics-otlp-http": "0.222.0",
|
|
19
|
-
"@opentelemetry/exporter-prometheus": "0.222.0",
|
|
20
|
-
"@opentelemetry/resources": "2.11.0",
|
|
21
|
-
"@opentelemetry/sdk-metrics": "2.11.0",
|
|
22
18
|
"@3sixty/context": "next",
|
|
23
19
|
"@3sixty/core": "next",
|
|
24
20
|
"@3sixty/entity-storage-models": "next",
|
|
25
21
|
"@3sixty/logging-models": "next",
|
|
26
22
|
"@3sixty/nameof": "next",
|
|
27
|
-
"@3sixty/telemetry-connector-entity-storage": "0.20.0-next.
|
|
28
|
-
"@3sixty/telemetry-models": "0.20.0-next.
|
|
23
|
+
"@3sixty/telemetry-connector-entity-storage": "0.20.0-next.2",
|
|
24
|
+
"@3sixty/telemetry-models": "0.20.0-next.2",
|
|
25
|
+
"@opentelemetry/api": "1.9.1",
|
|
26
|
+
"@opentelemetry/exporter-metrics-otlp-http": "0.223.0",
|
|
27
|
+
"@opentelemetry/exporter-prometheus": "0.223.0",
|
|
28
|
+
"@opentelemetry/resources": "2.12.0",
|
|
29
|
+
"@opentelemetry/sdk-metrics": "2.12.0"
|
|
29
30
|
},
|
|
30
31
|
"main": "./dist/es/index.js",
|
|
31
32
|
"types": "./dist/types/index.d.ts",
|