@prairielearn/opentelemetry 2.1.14 → 2.1.15

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @prairielearn/opentelemetry
2
2
 
3
+ ## 2.1.15
4
+
5
+ ### Patch Changes
6
+
7
+ - be4444e: Upgrade all JavaScript dependencies
8
+
3
9
  ## 2.1.14
4
10
 
5
11
  ### Patch Changes
@@ -1,9 +1,7 @@
1
1
  import {} from '@opentelemetry/api';
2
2
  import { AggregationTemporality, InMemoryMetricExporter, MeterProvider, PeriodicExportingMetricReader, } from '@opentelemetry/sdk-metrics';
3
- import { assert, use as chaiUse } from 'chai';
4
- import chaiAsPromised from 'chai-as-promised';
3
+ import { afterEach, assert, beforeEach, describe, expect, it } from 'vitest';
5
4
  import { instrumentedWithMetrics } from './metrics.js';
6
- chaiUse(chaiAsPromised);
7
5
  async function waitForMetricsExport(exporter) {
8
6
  while (exporter.getMetrics().length === 0) {
9
7
  await new Promise((resolve) => setTimeout(resolve, 50));
@@ -43,9 +41,9 @@ describe('instrumentedWithMetrics', () => {
43
41
  assert.equal(histogramMetric.dataPoints[0].value.count, 1);
44
42
  });
45
43
  it('records an error count', async () => {
46
- await assert.isRejected(instrumentedWithMetrics(meter, 'test', async () => {
44
+ await expect(instrumentedWithMetrics(meter, 'test', async () => {
47
45
  throw new Error('error for test');
48
- }), 'error for test');
46
+ })).rejects.toThrow('error for test');
49
47
  await waitForMetricsExport(exporter);
50
48
  const exportedMetrics = exporter.getMetrics();
51
49
  const { metrics, scope } = exportedMetrics[0].scopeMetrics[0];
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.test.js","sourceRoot":"","sources":["../src/metrics.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,sBAAsB,EAEtB,sBAAsB,EACtB,aAAa,EACb,6BAA6B,GAC9B,MAA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zB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC5B,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,GAAG,OAAO,CAAC;QAEjD,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;QACjB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAEjC,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;QACzB,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC1D,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAEnD,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;QAC3B,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAC/D,MAAM,CAAC,KAAK,CAAE,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAmB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { type Meter } from '@opentelemetry/api';\nimport {\n AggregationTemporality,\n type Histogram,\n InMemoryMetricExporter,\n MeterProvider,\n PeriodicExportingMetricReader,\n} from '@opentelemetry/sdk-metrics';\nimport { assert, use as chaiUse } from 'chai';\nimport chaiAsPromised from 'chai-as-promised';\n\nimport { instrumentedWithMetrics } from './metrics.js';\n\nchaiUse(chaiAsPromised);\n\nasync function waitForMetricsExport(exporter: InMemoryMetricExporter) {\n while (exporter.getMetrics().length === 0) {\n await new Promise((resolve) => setTimeout(resolve, 50));\n }\n}\n\ndescribe('instrumentedWithMetrics', () => {\n let exporter: InMemoryMetricExporter;\n let metricReader: PeriodicExportingMetricReader;\n let meter: Meter;\n\n beforeEach(async () => {\n const meterProvider = new MeterProvider();\n meter = meterProvider.getMeter('test');\n exporter = new InMemoryMetricExporter(AggregationTemporality.DELTA);\n metricReader = new PeriodicExportingMetricReader({\n exporter,\n exportIntervalMillis: 50,\n });\n meterProvider.addMetricReader(metricReader);\n });\n\n afterEach(async () => {\n await exporter.shutdown();\n await metricReader.shutdown();\n });\n\n it('records a histogram for the function duration', async () => {\n await instrumentedWithMetrics(meter, 'test', async () => {});\n\n await waitForMetricsExport(exporter);\n const exportedMetrics = exporter.getMetrics();\n const { scope, metrics } = exportedMetrics[0].scopeMetrics[0];\n\n // We won't see an exported metric for the error counter because the\n // Metrics SDK no longer exports metrics with no data points.\n // https://github.com/open-telemetry/opentelemetry-js/pull/4135\n assert.lengthOf(metrics, 1);\n const [histogramMetric] = metrics;\n\n assert.equal(scope.name, 'test');\n\n assert.ok(histogramMetric);\n assert.equal(histogramMetric.descriptor.name, 'test.duration');\n assert.equal((histogramMetric.dataPoints[0].value as Histogram).count, 1);\n });\n\n it('records an error count', async () => {\n await assert.isRejected(\n instrumentedWithMetrics(meter, 'test', async () => {\n throw new Error('error for test');\n }),\n 'error for test',\n );\n\n await waitForMetricsExport(exporter);\n const exportedMetrics = exporter.getMetrics();\n const { metrics, scope } = exportedMetrics[0].scopeMetrics[0];\n\n // An error was reported above, so there will be both the error counter\n // and histogram metrics.\n assert.lengthOf(metrics, 2);\n const [counterMetric, histogramMetric] = metrics;\n\n assert.ok(scope);\n assert.equal(scope.name, 'test');\n\n assert.ok(counterMetric);\n assert.equal(counterMetric.descriptor.name, 'test.error');\n assert.equal(counterMetric.dataPoints[0].value, 1);\n\n assert.ok(histogramMetric);\n assert.equal(histogramMetric.descriptor.name, 'test.duration');\n assert.equal((histogramMetric.dataPoints[0].value as Histogram).count, 1);\n });\n});\n"]}
1
+ {"version":3,"file":"metrics.test.js","sourceRoot":"","sources":["../src/metrics.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,oBAAoB,CAAC;AAChD,OAAO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C,CAAC,CAAC;QAE9D,uEAAuE;QACvE,yBAAyB;QACzB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC5B,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,GAAG,OAAO,CAAC;QAEjD,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;QACjB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAEjC,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;QACzB,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC1D,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAEnD,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;QAC3B,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAC/D,MAAM,CAAC,KAAK,CAAE,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAmB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { type Meter } from '@opentelemetry/api';\nimport {\n AggregationTemporality,\n type Histogram,\n InMemoryMetricExporter,\n MeterProvider,\n PeriodicExportingMetricReader,\n} from '@opentelemetry/sdk-metrics';\nimport { afterEach, assert, beforeEach, describe, expect, it } from 'vitest';\n\nimport { instrumentedWithMetrics } from './metrics.js';\n\nasync function waitForMetricsExport(exporter: InMemoryMetricExporter) {\n while (exporter.getMetrics().length === 0) {\n await new Promise((resolve) => setTimeout(resolve, 50));\n }\n}\n\ndescribe('instrumentedWithMetrics', () => {\n let exporter: InMemoryMetricExporter;\n let metricReader: PeriodicExportingMetricReader;\n let meter: Meter;\n\n beforeEach(async () => {\n const meterProvider = new MeterProvider();\n meter = meterProvider.getMeter('test');\n exporter = new InMemoryMetricExporter(AggregationTemporality.DELTA);\n metricReader = new PeriodicExportingMetricReader({\n exporter,\n exportIntervalMillis: 50,\n });\n meterProvider.addMetricReader(metricReader);\n });\n\n afterEach(async () => {\n await exporter.shutdown();\n await metricReader.shutdown();\n });\n\n it('records a histogram for the function duration', async () => {\n await instrumentedWithMetrics(meter, 'test', async () => {});\n\n await waitForMetricsExport(exporter);\n const exportedMetrics = exporter.getMetrics();\n const { scope, metrics } = exportedMetrics[0].scopeMetrics[0];\n\n // We won't see an exported metric for the error counter because the\n // Metrics SDK no longer exports metrics with no data points.\n // https://github.com/open-telemetry/opentelemetry-js/pull/4135\n assert.lengthOf(metrics, 1);\n const [histogramMetric] = metrics;\n\n assert.equal(scope.name, 'test');\n\n assert.ok(histogramMetric);\n assert.equal(histogramMetric.descriptor.name, 'test.duration');\n assert.equal((histogramMetric.dataPoints[0].value as Histogram).count, 1);\n });\n\n it('records an error count', async () => {\n await expect(\n instrumentedWithMetrics(meter, 'test', async () => {\n throw new Error('error for test');\n }),\n ).rejects.toThrow('error for test');\n\n await waitForMetricsExport(exporter);\n const exportedMetrics = exporter.getMetrics();\n const { metrics, scope } = exportedMetrics[0].scopeMetrics[0];\n\n // An error was reported above, so there will be both the error counter\n // and histogram metrics.\n assert.lengthOf(metrics, 2);\n const [counterMetric, histogramMetric] = metrics;\n\n assert.ok(scope);\n assert.equal(scope.name, 'test');\n\n assert.ok(counterMetric);\n assert.equal(counterMetric.descriptor.name, 'test.error');\n assert.equal(counterMetric.dataPoints[0].value, 1);\n\n assert.ok(histogramMetric);\n assert.equal(histogramMetric.descriptor.name, 'test.duration');\n assert.equal((histogramMetric.dataPoints[0].value as Histogram).count, 1);\n });\n});\n"]}
@@ -1,12 +1,12 @@
1
1
  import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
2
2
  import { tracing } from '@opentelemetry/sdk-node';
3
- import { assert } from 'chai';
3
+ import { afterEach, assert, beforeAll, beforeEach, describe, it } from 'vitest';
4
4
  import { SpanStatusCode, context, init, instrumented, trace } from './index.js';
5
5
  describe('instrumented', () => {
6
6
  let contextManager;
7
7
  const exporter = new tracing.InMemorySpanExporter();
8
8
  const spanProcessor = new tracing.SimpleSpanProcessor(exporter);
9
- before(async () => {
9
+ beforeAll(async () => {
10
10
  await init({
11
11
  openTelemetryEnabled: true,
12
12
  openTelemetryExporter: exporter,
@@ -1 +1 @@
1
- {"version":3,"file":"tracing.test.js","sourceRoot":"","sources":["../src/tracing.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEhF,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,cAAwC,CAAC;IAC7C,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IACpD,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAEhE,MAAM,CAAC,KAAK,IAAI,EAAE;QAChB,MAAM,IAAI,CAAC;YACT,oBAAoB,EAAE,IAAI;YAC1B,qBAAqB,EAAE,QAAQ;YAC/B,wBAAwB,EAAE,WAAW;YACrC,0BAA0B,EAAE,aAAa;SAC1C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,cAAc,GAAG,IAAI,wBAAwB,EAAE,CAAC;QAChD,OAAO,CAAC,uBAAuB,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH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ourcesContent":["import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';\nimport { tracing } from '@opentelemetry/sdk-node';\nimport { assert } from 'chai';\n\nimport { SpanStatusCode, context, init, instrumented, trace } from './index.js';\n\ndescribe('instrumented', () => {\n let contextManager: AsyncHooksContextManager;\n const exporter = new tracing.InMemorySpanExporter();\n const spanProcessor = new tracing.SimpleSpanProcessor(exporter);\n\n before(async () => {\n await init({\n openTelemetryEnabled: true,\n openTelemetryExporter: exporter,\n openTelemetrySamplerType: 'always-on',\n openTelemetrySpanProcessor: spanProcessor,\n });\n });\n\n beforeEach(async () => {\n contextManager = new AsyncHooksContextManager();\n context.setGlobalContextManager(contextManager.enable());\n });\n\n afterEach(async () => {\n await spanProcessor.forceFlush();\n exporter.reset();\n context.disable();\n });\n\n it('returns the value from the function', async () => {\n const res = await instrumented('test', () => 'foo');\n assert.equal(res, 'foo');\n });\n\n it('records a span on success', async () => {\n await instrumented('test-success', () => 'foo');\n\n await spanProcessor.forceFlush();\n const spans = exporter.getFinishedSpans();\n assert.lengthOf(spans, 1);\n assert.equal(spans[0].name, 'test-success');\n assert.equal(spans[0].status.code, SpanStatusCode.OK);\n });\n\n it('records a span on failure', async () => {\n let maybeError: Error | null = null;\n\n try {\n await instrumented('test-failure', () => {\n throw new Error('foo');\n });\n } catch (err: any) {\n maybeError = err;\n }\n\n // Ensure the error was propagated back to the caller.\n assert.equal(maybeError?.message, 'foo');\n\n // Ensure the correct span was recorded.\n await spanProcessor.forceFlush();\n const spans = exporter.getFinishedSpans();\n assert.lengthOf(spans, 1);\n assert.equal(spans[0].name, 'test-failure');\n assert.equal(spans[0].status.code, SpanStatusCode.ERROR);\n assert.equal(spans[0].status.message, 'foo');\n assert.equal(spans[0].events[0].name, 'exception');\n });\n\n it('sets up context correctly', async () => {\n const tracer = trace.getTracer('default');\n const parentSpan = tracer.startSpan('parentSpan');\n const parentContext = trace.setSpan(context.active(), parentSpan);\n\n await instrumented('test', async () => {\n const childContext = context.active();\n ass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AM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC1B,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QAC5C,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC7C,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QACzC,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QAClD,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC;QAElE,MAAM,YAAY,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE;YACpC,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YACtC,MAAM,CAAC,cAAc,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';\nimport { tracing } from '@opentelemetry/sdk-node';\nimport { afterEach, assert, beforeAll, beforeEach, describe, it } from 'vitest';\n\nimport { SpanStatusCode, context, init, instrumented, trace } from './index.js';\n\ndescribe('instrumented', () => {\n let contextManager: AsyncHooksContextManager;\n const exporter = new tracing.InMemorySpanExporter();\n const spanProcessor = new tracing.SimpleSpanProcessor(exporter);\n\n beforeAll(async () => {\n await init({\n openTelemetryEnabled: true,\n openTelemetryExporter: exporter,\n openTelemetrySamplerType: 'always-on',\n openTelemetrySpanProcessor: spanProcessor,\n });\n });\n\n beforeEach(async () => {\n contextManager = new AsyncHooksContextManager();\n context.setGlobalContextManager(contextManager.enable());\n });\n\n afterEach(async () => {\n await spanProcessor.forceFlush();\n exporter.reset();\n context.disable();\n });\n\n it('returns the value from the function', async () => {\n const res = await instrumented('test', () => 'foo');\n assert.equal(res, 'foo');\n });\n\n it('records a span on success', async () => {\n await instrumented('test-success', () => 'foo');\n\n await spanProcessor.forceFlush();\n const spans = exporter.getFinishedSpans();\n assert.lengthOf(spans, 1);\n assert.equal(spans[0].name, 'test-success');\n assert.equal(spans[0].status.code, SpanStatusCode.OK);\n });\n\n it('records a span on failure', async () => {\n let maybeError: Error | null = null;\n\n try {\n await instrumented('test-failure', () => {\n throw new Error('foo');\n });\n } catch (err: any) {\n maybeError = err;\n }\n\n // Ensure the error was propagated back to the caller.\n assert.equal(maybeError?.message, 'foo');\n\n // Ensure the correct span was recorded.\n await spanProcessor.forceFlush();\n const spans = exporter.getFinishedSpans();\n assert.lengthOf(spans, 1);\n assert.equal(spans[0].name, 'test-failure');\n assert.equal(spans[0].status.code, SpanStatusCode.ERROR);\n assert.equal(spans[0].status.message, 'foo');\n assert.equal(spans[0].events[0].name, 'exception');\n });\n\n it('sets up context correctly', async () => {\n const tracer = trace.getTracer('default');\n const parentSpan = tracer.startSpan('parentSpan');\n const parentContext = trace.setSpan(context.active(), parentSpan);\n\n await instrumented('test', async () => {\n const childContext = context.active();\n assert.notStrictEqual(childContext, parentContext);\n });\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prairielearn/opentelemetry",
3
- "version": "2.1.14",
3
+ "version": "2.1.15",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,10 +11,10 @@
11
11
  "scripts": {
12
12
  "build": "tsc",
13
13
  "dev": "tsc --watch --preserveWatchOutput",
14
- "test": "c8 mocha src/**/*.test.ts"
14
+ "test": "vitest run --coverage"
15
15
  },
16
16
  "dependencies": {
17
- "@grpc/grpc-js": "^1.13.3",
17
+ "@grpc/grpc-js": "^1.13.4",
18
18
  "@opentelemetry/api": "^1.9.0",
19
19
  "@opentelemetry/core": "^1.30.1",
20
20
  "@opentelemetry/exporter-metrics-otlp-grpc": "^0.57.2",
@@ -40,25 +40,10 @@
40
40
  "devDependencies": {
41
41
  "@opentelemetry/context-async-hooks": "^1.30.1",
42
42
  "@prairielearn/tsconfig": "^0.0.0",
43
- "@types/chai": "^5.2.1",
44
- "@types/mocha": "^10.0.10",
45
- "@types/node": "^20.17.32",
46
- "c8": "^10.1.3",
47
- "chai": "^5.2.0",
48
- "chai-as-promised": "^8.0.1",
49
- "mocha": "^11.1.0",
43
+ "@types/node": "^20.17.57",
44
+ "@vitest/coverage-v8": "^3.1.4",
50
45
  "tsx": "^4.19.4",
51
- "typescript": "^5.8.3"
52
- },
53
- "c8": {
54
- "reporter": [
55
- "html",
56
- "text-summary",
57
- "cobertura"
58
- ],
59
- "all": true,
60
- "include": [
61
- "src/**"
62
- ]
46
+ "typescript": "^5.8.3",
47
+ "vitest": "^3.1.4"
63
48
  }
64
49
  }
@@ -6,13 +6,10 @@ import {
6
6
  MeterProvider,
7
7
  PeriodicExportingMetricReader,
8
8
  } from '@opentelemetry/sdk-metrics';
9
- import { assert, use as chaiUse } from 'chai';
10
- import chaiAsPromised from 'chai-as-promised';
9
+ import { afterEach, assert, beforeEach, describe, expect, it } from 'vitest';
11
10
 
12
11
  import { instrumentedWithMetrics } from './metrics.js';
13
12
 
14
- chaiUse(chaiAsPromised);
15
-
16
13
  async function waitForMetricsExport(exporter: InMemoryMetricExporter) {
17
14
  while (exporter.getMetrics().length === 0) {
18
15
  await new Promise((resolve) => setTimeout(resolve, 50));
@@ -61,12 +58,11 @@ describe('instrumentedWithMetrics', () => {
61
58
  });
62
59
 
63
60
  it('records an error count', async () => {
64
- await assert.isRejected(
61
+ await expect(
65
62
  instrumentedWithMetrics(meter, 'test', async () => {
66
63
  throw new Error('error for test');
67
64
  }),
68
- 'error for test',
69
- );
65
+ ).rejects.toThrow('error for test');
70
66
 
71
67
  await waitForMetricsExport(exporter);
72
68
  const exportedMetrics = exporter.getMetrics();
@@ -1,6 +1,6 @@
1
1
  import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
2
2
  import { tracing } from '@opentelemetry/sdk-node';
3
- import { assert } from 'chai';
3
+ import { afterEach, assert, beforeAll, beforeEach, describe, it } from 'vitest';
4
4
 
5
5
  import { SpanStatusCode, context, init, instrumented, trace } from './index.js';
6
6
 
@@ -9,7 +9,7 @@ describe('instrumented', () => {
9
9
  const exporter = new tracing.InMemorySpanExporter();
10
10
  const spanProcessor = new tracing.SimpleSpanProcessor(exporter);
11
11
 
12
- before(async () => {
12
+ beforeAll(async () => {
13
13
  await init({
14
14
  openTelemetryEnabled: true,
15
15
  openTelemetryExporter: exporter,
package/tsconfig.json CHANGED
@@ -3,6 +3,6 @@
3
3
  "compilerOptions": {
4
4
  "outDir": "./dist",
5
5
  "rootDir": "./src",
6
- "types": ["mocha", "node"]
6
+ "types": ["node"]
7
7
  }
8
8
  }
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ coverage: {
6
+ reporter: ['html', 'text-summary', 'cobertura'],
7
+ all: true,
8
+ include: ['src/**'],
9
+ },
10
+ },
11
+ });