@atlaspack/logger 2.13.1-canary.3631 → 2.13.1-canary.3632

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/lib/Logger.js CHANGED
@@ -4,6 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.PluginLogger = exports.INTERNAL_ORIGINAL_CONSOLE = void 0;
7
+ Object.defineProperty(exports, "instrument", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _tracer.instrument;
11
+ }
12
+ });
13
+ Object.defineProperty(exports, "instrumentAsync", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _tracer.instrumentAsync;
17
+ }
18
+ });
7
19
  exports.patchConsole = patchConsole;
8
20
  exports.unpatchConsole = unpatchConsole;
9
21
  function _events() {
@@ -27,6 +39,7 @@ function _diagnostic() {
27
39
  };
28
40
  return data;
29
41
  }
42
+ var _tracer = require("./tracer");
30
43
  class Logger {
31
44
  #logEmitter /*: ValueEmitter<LogEvent> */ = new (_events().ValueEmitter)();
32
45
  onLog(cb) {
package/lib/tracer.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.instrument = instrument;
7
+ exports.instrumentAsync = instrumentAsync;
8
+ exports.tracer = void 0;
9
+ function _rust() {
10
+ const data = require("@atlaspack/rust");
11
+ _rust = function () {
12
+ return data;
13
+ };
14
+ return data;
15
+ }
16
+ const tracer = exports.tracer = new (_rust().AtlaspackTracer)();
17
+ function instrument(label, fn) {
18
+ const span = tracer.enter(label);
19
+ try {
20
+ const result = fn();
21
+ return result;
22
+ } finally {
23
+ tracer.exit(span);
24
+ }
25
+ }
26
+ async function instrumentAsync(label, fn) {
27
+ const span = tracer.enter(label);
28
+ try {
29
+ const result = await fn();
30
+ return result;
31
+ } finally {
32
+ tracer.exit(span);
33
+ }
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/logger",
3
- "version": "2.13.1-canary.3631+64cd5e9ae",
3
+ "version": "2.13.1-canary.3632+a3f9df155",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -22,8 +22,9 @@
22
22
  "node": ">= 16.0.0"
23
23
  },
24
24
  "dependencies": {
25
- "@atlaspack/diagnostic": "2.13.1-canary.3631+64cd5e9ae",
26
- "@atlaspack/events": "2.13.1-canary.3631+64cd5e9ae"
25
+ "@atlaspack/diagnostic": "2.13.1-canary.3632+a3f9df155",
26
+ "@atlaspack/events": "2.13.1-canary.3632+a3f9df155",
27
+ "@atlaspack/rust": "2.13.1-canary.3632+a3f9df155"
27
28
  },
28
- "gitHead": "64cd5e9ae573dbf0bee64488c7cf2026f991a1ed"
29
+ "gitHead": "a3f9df155a5d81828bb6e68e7b9aa40d0e4fd917"
29
30
  }
package/src/Logger.js CHANGED
@@ -15,6 +15,8 @@ import {ValueEmitter} from '@atlaspack/events';
15
15
  import {inspect} from 'util';
16
16
  import {errorToDiagnostic, anyToDiagnostic} from '@atlaspack/diagnostic';
17
17
 
18
+ export {instrument, instrumentAsync} from './tracer';
19
+
18
20
  class Logger {
19
21
  #logEmitter /*: ValueEmitter<LogEvent> */ = new ValueEmitter();
20
22
 
package/src/tracer.js ADDED
@@ -0,0 +1,28 @@
1
+ // @flow strict-local
2
+
3
+ import {AtlaspackTracer} from '@atlaspack/rust';
4
+
5
+ export const tracer: AtlaspackTracer = new AtlaspackTracer();
6
+
7
+ export function instrument<T>(label: string, fn: () => T): T {
8
+ const span = tracer.enter(label);
9
+ try {
10
+ const result = fn();
11
+ return result;
12
+ } finally {
13
+ tracer.exit(span);
14
+ }
15
+ }
16
+
17
+ export async function instrumentAsync<T>(
18
+ label: string,
19
+ fn: () => Promise<T>,
20
+ ): Promise<T> {
21
+ const span = tracer.enter(label);
22
+ try {
23
+ const result = await fn();
24
+ return result;
25
+ } finally {
26
+ tracer.exit(span);
27
+ }
28
+ }