@boxyhq/metrics 0.2.2 → 0.2.3

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 CHANGED
@@ -3,3 +3,14 @@
3
3
  <a href="https://www.npmjs.com/package/@boxyhq/metrics"><img src="https://img.shields.io/npm/v/@boxyhq/metrics.svg" alt="npm" ></a>
4
4
 
5
5
  Package for OTel instrumentation
6
+
7
+ ## Running Tests
8
+
9
+ Tests helps us to ensure that the telemetry export works as expected after every OTEL dependency update.
10
+
11
+ ```shell
12
+ npm i
13
+ # Copy test/.env.example to test/.env and set the values
14
+ cp test/.env.example test/.env
15
+ npm run test:manual
16
+ ```
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@boxyhq/metrics",
3
+ "version": "0.2.3",
4
+ "description": "Internal SDK for OTel instrumentation",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc -p tsconfig.json",
12
+ "prepublishOnly": "npm run build",
13
+ "lint": "eslint -c .eslintrc.json --ext .ts ./",
14
+ "test:manual": "env-cmd -f ./test/.env ts-node --project tsconfig.json test/index.ts"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/boxyhq/metrics.git"
19
+ },
20
+ "keywords": [
21
+ "otel",
22
+ "telemetry"
23
+ ],
24
+ "license": "Apache-2.0",
25
+ "bugs": {
26
+ "url": "https://github.com/boxyhq/metrics/issues"
27
+ },
28
+ "homepage": "https://github.com/boxyhq/metrics#readme",
29
+ "dependencies": {
30
+ "@opentelemetry/api": "1.4.1",
31
+ "@opentelemetry/exporter-metrics-otlp-grpc": "0.40.0",
32
+ "@opentelemetry/exporter-metrics-otlp-http": "0.40.0",
33
+ "@opentelemetry/resources": "1.14.0",
34
+ "@opentelemetry/sdk-metrics": "1.14.0",
35
+ "@opentelemetry/semantic-conventions": "1.14.0"
36
+ },
37
+ "devDependencies": {
38
+ "@tsconfig/recommended": "1.0.2",
39
+ "@typescript-eslint/eslint-plugin": "5.58.0",
40
+ "@typescript-eslint/parser": "5.58.0",
41
+ "env-cmd": "10.1.0",
42
+ "eslint": "8.38.0",
43
+ "eslint-config-prettier": "8.8.0",
44
+ "prettier": "2.8.8",
45
+ "ts-node": "10.9.1",
46
+ "typescript": "5.0.4"
47
+ }
48
+ }
@@ -28,14 +28,17 @@ function initializeMetrics(serviceInfo) {
28
28
  else {
29
29
  metricExporter = new exporter_metrics_otlp_http_1.OTLPMetricExporter();
30
30
  }
31
+ /** exportIntervalMillis must be greater than exportTimeoutMillis */
32
+ const exportIntervalMillis = Number(process.env.OTEL_EXPORT_INTERVAL_MS) || 60000;
33
+ const exportTimeoutMillis = Number(process.env.OTEL_EXPORT_INTERVAL_MS) - 1000 || 30000;
31
34
  meterProvider.addMetricReader(new sdk_metrics_1.PeriodicExportingMetricReader({
32
35
  exporter: metricExporter,
33
- exportIntervalMillis: 60000,
36
+ exportIntervalMillis,
37
+ exportTimeoutMillis,
34
38
  }));
35
39
  api_1.metrics.setGlobalMeterProvider(meterProvider);
36
40
  }
37
41
  if (process.env.OTEL_EXPORTER_DEBUG) {
38
- api_1.diag.disable();
39
42
  api_1.diag.setLogger(new api_1.DiagConsoleLogger(), api_1.DiagLogLevel.DEBUG);
40
43
  }
41
44
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const src_1 = require("../src");
16
+ const package_json_1 = __importDefault(require("../package.json"));
17
+ const promises_1 = require("timers/promises");
18
+ const SERVICE_NAME = '@boxyhq/metrics';
19
+ (0, src_1.initializeMetrics)({ name: SERVICE_NAME, version: package_json_1.default.version });
20
+ const METER = 'meter';
21
+ function testInstruments() {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ (0, src_1.incrementCounter)({
24
+ meter: METER,
25
+ name: 'test.counter',
26
+ counterOptions: { description: 'Test counter' },
27
+ });
28
+ console.log(`Operation for counter metric ... DONE`);
29
+ (0, src_1.observeGauge)({
30
+ meter: METER,
31
+ name: 'test.gauge',
32
+ gaugeOptions: { description: 'Test gauge', unit: 'm/s' },
33
+ val: 100,
34
+ });
35
+ console.log(`Operation for gauge metric ... DONE`);
36
+ (0, src_1.recordHistogram)({
37
+ meter: METER,
38
+ name: 'test.histogram',
39
+ histogramOptions: { description: 'Test histogram' },
40
+ val: 200,
41
+ });
42
+ console.log(`Operation for histogram metric ... DONE`);
43
+ yield (0, src_1.instrument)({
44
+ meter: METER,
45
+ name: 'test.instrument',
46
+ delegate: () => Promise.resolve(),
47
+ });
48
+ console.log(`Operation for function instrumentation ... DONE`);
49
+ /** Essential to set a timeout below that is more than the export interval*/
50
+ const waitTime = Number(process.env.OTEL_EXPORT_INTERVAL_MS) + 1000 || 61000;
51
+ console.log(`Waiting for ${waitTime}ms to complete export ....`);
52
+ yield (0, promises_1.setTimeout)(waitTime);
53
+ console.log(`Export operation ... COMPLETE, please check the configured OTEL service for recorded values`);
54
+ });
55
+ }
56
+ testInstruments();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boxyhq/metrics",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Internal SDK for OTel instrumentation",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -10,7 +10,8 @@
10
10
  "scripts": {
11
11
  "build": "tsc -p tsconfig.json",
12
12
  "prepublishOnly": "npm run build",
13
- "lint": "eslint -c .eslintrc.json --ext .ts ./"
13
+ "lint": "eslint -c .eslintrc.json --ext .ts ./",
14
+ "test:manual": "env-cmd -f ./test/.env ts-node --project tsconfig.json test/index.ts"
14
15
  },
15
16
  "repository": {
16
17
  "type": "git",
@@ -27,19 +28,21 @@
27
28
  "homepage": "https://github.com/boxyhq/metrics#readme",
28
29
  "dependencies": {
29
30
  "@opentelemetry/api": "1.4.1",
30
- "@opentelemetry/exporter-metrics-otlp-grpc": "0.37.0",
31
- "@opentelemetry/exporter-metrics-otlp-http": "0.37.0",
32
- "@opentelemetry/resources": "1.11.0",
33
- "@opentelemetry/sdk-metrics": "1.11.0",
34
- "@opentelemetry/semantic-conventions": "1.11.0"
31
+ "@opentelemetry/exporter-metrics-otlp-grpc": "0.40.0",
32
+ "@opentelemetry/exporter-metrics-otlp-http": "0.40.0",
33
+ "@opentelemetry/resources": "1.14.0",
34
+ "@opentelemetry/sdk-metrics": "1.14.0",
35
+ "@opentelemetry/semantic-conventions": "1.14.0"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@tsconfig/recommended": "1.0.2",
38
39
  "@typescript-eslint/eslint-plugin": "5.58.0",
39
40
  "@typescript-eslint/parser": "5.58.0",
41
+ "env-cmd": "10.1.0",
40
42
  "eslint": "8.38.0",
41
43
  "eslint-config-prettier": "8.8.0",
42
- "prettier": "2.8.7",
44
+ "prettier": "2.8.8",
45
+ "ts-node": "10.9.1",
43
46
  "typescript": "5.0.4"
44
47
  }
45
48
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes