@mongodb-js/compass-logging
Advanced tools
Comparing version 0.0.0-next-80a9e175edd3eabee53daee876d77943872e4205 to 0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730
@@ -1,5 +0,3 @@ | ||
export { createLoggerAndTelemetry } from './logger'; | ||
export { createLoggerAndTelemetry as default } from './logger'; | ||
export type { LoggerAndTelemetry } from './logger'; | ||
export { useLoggerAndTelemetry, useTrackOnChange, withLoggerAndTelemetry, } from './react'; | ||
export { createLogger } from './ipc-logger'; | ||
export type { Logger } from './logger'; | ||
export { mongoLogId } from 'mongodb-log-writer'; | ||
@@ -6,0 +4,0 @@ import createDebug from 'debug'; |
@@ -6,11 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.debug = exports.mongoLogId = exports.withLoggerAndTelemetry = exports.useTrackOnChange = exports.useLoggerAndTelemetry = exports.default = exports.createLoggerAndTelemetry = void 0; | ||
var logger_1 = require("./logger"); | ||
Object.defineProperty(exports, "createLoggerAndTelemetry", { enumerable: true, get: function () { return logger_1.createLoggerAndTelemetry; } }); | ||
var logger_2 = require("./logger"); | ||
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return logger_2.createLoggerAndTelemetry; } }); | ||
var react_1 = require("./react"); | ||
Object.defineProperty(exports, "useLoggerAndTelemetry", { enumerable: true, get: function () { return react_1.useLoggerAndTelemetry; } }); | ||
Object.defineProperty(exports, "useTrackOnChange", { enumerable: true, get: function () { return react_1.useTrackOnChange; } }); | ||
Object.defineProperty(exports, "withLoggerAndTelemetry", { enumerable: true, get: function () { return react_1.withLoggerAndTelemetry; } }); | ||
exports.debug = exports.mongoLogId = exports.createLogger = void 0; | ||
var ipc_logger_1 = require("./ipc-logger"); | ||
Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return ipc_logger_1.createLogger; } }); | ||
var mongodb_log_writer_1 = require("mongodb-log-writer"); | ||
@@ -17,0 +11,0 @@ Object.defineProperty(exports, "mongoLogId", { enumerable: true, get: function () { return mongodb_log_writer_1.mongoLogId; } }); |
import { MongoLogWriter, mongoLogId } from 'mongodb-log-writer'; | ||
import createDebug from 'debug'; | ||
type TrackProps = Record<string, any> | (() => Record<string, any>); | ||
type TrackFunction = (event: string, properties?: TrackProps) => void; | ||
export type LoggerAndTelemetry = { | ||
export type Logger = { | ||
log: ReturnType<MongoLogWriter['bindComponent']>; | ||
mongoLogId: typeof mongoLogId; | ||
debug: ReturnType<typeof createDebug>; | ||
track: TrackFunction; | ||
}; | ||
export declare function createLoggerAndTelemetry(component: string): LoggerAndTelemetry; | ||
export default createLoggerAndTelemetry; | ||
export declare function createGenericLogger(component: string, emit: (event: string, arg: any) => void): Logger; | ||
//# sourceMappingURL=logger.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -29,21 +6,13 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLoggerAndTelemetry = void 0; | ||
exports.createGenericLogger = void 0; | ||
const mongodb_log_writer_1 = require("mongodb-log-writer"); | ||
const is_electron_renderer_1 = __importDefault(require("is-electron-renderer")); | ||
const debug_1 = __importDefault(require("debug")); | ||
let preferences; | ||
function emit(ipc, event, data) { | ||
var _a; | ||
void ((_a = ipc === null || ipc === void 0 ? void 0 : ipc.callQuiet) === null || _a === void 0 ? void 0 : _a.call(ipc, event, data)); | ||
if (typeof process !== 'undefined' && typeof process.emit === 'function') { | ||
process.emit(event, data); | ||
} | ||
} | ||
function createLoggerAndTelemetry(component) { | ||
const ipc = is_electron_renderer_1.default | ||
? require('hadron-ipc') | ||
: null; | ||
function createGenericLogger(component, emit) { | ||
// Do not create an actual Writable stream here, since the callback | ||
// logic in Node.js streams would mean that two writes from the | ||
// same event loop tick would not be written synchronously, | ||
// allowing another logger's write to be written out-of-order. | ||
const target = { | ||
write(line, callback) { | ||
emit(ipc, 'compass:log', { line }); | ||
emit('compass:log', { line }); | ||
callback(); | ||
@@ -57,47 +26,2 @@ }, | ||
const log = writer.bindComponent(component); | ||
const track = (...args) => { | ||
void Promise.resolve() | ||
.then(() => trackAsync(...args)) | ||
.catch((error) => debug('track failed', error)); | ||
}; | ||
const trackAsync = async (event, properties = {}) => { | ||
try { | ||
preferences !== null && preferences !== void 0 ? preferences : (preferences = (await Promise.resolve().then(() => __importStar(require('compass-preferences-model')))) | ||
.preferencesAccess); | ||
} | ||
catch (_a) { | ||
preferences !== null && preferences !== void 0 ? preferences : (preferences = { | ||
getPreferences() { | ||
return { trackUsageStatistics: true }; | ||
}, | ||
}); | ||
} | ||
const { trackUsageStatistics = true } = preferences === null || preferences === void 0 ? void 0 : preferences.getPreferences(); | ||
if (!trackUsageStatistics) { | ||
return; | ||
} | ||
const data = { | ||
event, | ||
properties, | ||
}; | ||
if (typeof properties === 'function') { | ||
try { | ||
data.properties = await properties(); | ||
} | ||
catch (error) { | ||
emit(ipc, 'compass:track', { | ||
event: 'Error Fetching Attributes', | ||
properties: { | ||
event_name: event, | ||
}, | ||
}); | ||
log.error((0, mongodb_log_writer_1.mongoLogId)(1001000190), 'Telemetry', 'Error computing event properties for telemetry', { | ||
event, | ||
error: error.stack, | ||
}); | ||
return; | ||
} | ||
} | ||
emit(ipc, 'compass:track', data); | ||
}; | ||
const debug = (0, debug_1.default)(`mongodb-compass:${component.toLowerCase()}`); | ||
@@ -116,7 +40,5 @@ writer.on('log', ({ s, ctx, msg, attr }) => { | ||
debug, | ||
track, | ||
}; | ||
} | ||
exports.createLoggerAndTelemetry = createLoggerAndTelemetry; | ||
exports.default = createLoggerAndTelemetry; | ||
exports.createGenericLogger = createGenericLogger; | ||
//# sourceMappingURL=logger.js.map |
@@ -16,3 +16,3 @@ { | ||
"homepage": "https://github.com/mongodb-js/compass", | ||
"version": "0.0.0-next-80a9e175edd3eabee53daee876d77943872e4205", | ||
"version": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730", | ||
"repository": { | ||
@@ -23,12 +23,15 @@ "type": "git", | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"provider.js" | ||
], | ||
"license": "SSPL", | ||
"peerDependencies": { | ||
"hadron-ipc": "^3.1.3" | ||
"main": "dist/index.js", | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./provider": "./dist/provider.js" | ||
}, | ||
"main": "dist/index.js", | ||
"compass:main": "src/index.ts", | ||
"compass:exports": { | ||
".": "./src/index.ts" | ||
".": "./src/index.ts", | ||
"./provider": "./src/provider.ts" | ||
}, | ||
@@ -43,3 +46,3 @@ "types": "./dist/index.d.ts", | ||
"lint": "npm run eslint . && npm run prettier -- --check .", | ||
"depcheck": "depcheck", | ||
"depcheck": "compass-scripts check-peer-deps && depcheck", | ||
"check": "npm run lint && npm run depcheck", | ||
@@ -51,15 +54,19 @@ "check-ci": "npm run check", | ||
"test-ci": "npm run test-cov", | ||
"reformat": "npm run prettier -- --write . && npm run eslint . --fix" | ||
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write ." | ||
}, | ||
"dependencies": { | ||
"debug": "^4.2.0", | ||
"debug": "^4.3.4", | ||
"hadron-app-registry": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730", | ||
"hadron-ipc": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730", | ||
"is-electron-renderer": "^2.0.1", | ||
"mongodb-log-writer": "^1.2.0" | ||
"mongodb-log-writer": "^1.4.2", | ||
"react": "^17.0.2" | ||
}, | ||
"devDependencies": { | ||
"@mongodb-js/eslint-config-compass": "0.0.0-next-80a9e175edd3eabee53daee876d77943872e4205", | ||
"@mongodb-js/mocha-config-compass": "0.0.0-next-80a9e175edd3eabee53daee876d77943872e4205", | ||
"@mongodb-js/prettier-config-compass": "0.0.0-next-80a9e175edd3eabee53daee876d77943872e4205", | ||
"@mongodb-js/tsconfig-compass": "0.0.0-next-80a9e175edd3eabee53daee876d77943872e4205", | ||
"@mongodb-js/eslint-config-compass": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730", | ||
"@mongodb-js/mocha-config-compass": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730", | ||
"@mongodb-js/prettier-config-compass": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730", | ||
"@mongodb-js/tsconfig-compass": "0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730", | ||
"@types/chai": "^4.2.21", | ||
"@types/debug": "^4.1.9", | ||
"@types/mocha": "^9.0.0", | ||
@@ -70,3 +77,2 @@ "@types/sinon-chai": "^3.2.5", | ||
"eslint": "^7.25.0", | ||
"hadron-ipc": "0.0.0-next-80a9e175edd3eabee53daee876d77943872e4205", | ||
"mocha": "^10.2.0", | ||
@@ -81,3 +87,3 @@ "nyc": "^15.1.0", | ||
}, | ||
"gitHead": "80a9e175edd3eabee53daee876d77943872e4205" | ||
"gitHead": "80f6ac0b3460eec09e5e7aa7f17b44a732ed5730" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18
24
205
47388
6
195
11
2
+ Addedhadron-app-registry@0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730
+ Addedhadron-ipc@0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730
+ Addedreact@^17.0.2
+ Added@babel/runtime@7.26.0(transitive)
+ Added@types/hoist-non-react-statics@3.3.5(transitive)
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@18.3.12(transitive)
+ Added@types/use-sync-external-store@0.0.3(transitive)
+ Addedasap@2.0.6(transitive)
+ Addedcore-js@1.2.7(transitive)
+ Addedcreate-react-class@15.7.0(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addedelectron@30.5.1(transitive)
+ Addedencoding@0.1.13(transitive)
+ Addedeventemitter3@1.2.04.0.7(transitive)
+ Addedfbjs@0.8.18(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhadron-app-registry@0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730(transitive)
+ Addedhadron-ipc@0.0.0-next-80f6ac0b3460eec09e5e7aa7f17b44a732ed5730(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhoist-non-react-statics@3.3.2(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisomorphic-fetch@2.2.1(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addednode-fetch@1.7.3(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedpromise@7.3.1(transitive)
+ Addedprop-types@15.8.1(transitive)
+ Addedreact@15.7.017.0.2(transitive)
+ Addedreact-is@16.13.118.3.1(transitive)
+ Addedreact-redux@8.1.3(transitive)
+ Addedredux@4.2.1(transitive)
+ Addedreflux@0.4.1(transitive)
+ Addedreflux-core@0.3.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsetimmediate@1.0.5(transitive)
+ Addedua-parser-js@0.7.39(transitive)
+ Addeduse-sync-external-store@1.2.2(transitive)
+ Addedwhatwg-fetch@3.6.20(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedelectron@32.2.6(transitive)
- Removedgopd@1.1.0(transitive)
- Removedhadron-ipc@3.2.27(transitive)
- Removedhas-proto@1.1.0(transitive)
- Removedset-function-length@1.2.2(transitive)
Updateddebug@^4.3.4
Updatedmongodb-log-writer@^1.4.2