How to use the diagnostic-channel.channel.publish function in diagnostic-channel

To help you get started, we’ve selected a few diagnostic-channel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / ApplicationInsights-node.js / Tests / AutoCollection / Console.tests.ts View on Github external
const trackExceptionStub = sinon.stub(AppInsights.defaultClient, "trackException");
            const trackTraceStub = sinon.stub(AppInsights.defaultClient, "trackTrace");

            disable();
            enable(true, AppInsights.defaultClient);
            const logEvent: console.IConsoleData = {
                message: "test log",
                stderr: true // should log as MessageData regardless of this setting
            };
            const dummyError = new Error("test error");
            const errorEvent: console.IConsoleData = {
                message: dummyError as any,
                stderr: false, // log() should still log as ExceptionData
            };

            channel.publish("console", logEvent);
            assert.ok(trackExceptionStub.notCalled);
            assert.ok(trackTraceStub.calledOnce);
            assert.deepEqual(trackTraceStub.args[0][0].message, "test log");
            trackExceptionStub.reset();
            trackTraceStub.reset();

            channel.publish("console", errorEvent);
            assert.ok(trackExceptionStub.calledOnce);
            assert.ok(trackTraceStub.notCalled);
            assert.deepEqual(trackExceptionStub.args[0][0].exception, dummyError);

            disable();
            trackExceptionStub.restore();
            trackTraceStub.restore();
        });
    });
github microsoft / ApplicationInsights-node.js / Tests / AutoCollection / Console.tests.ts View on Github external
stderr: true // should log as MessageData regardless of this setting
            };
            const dummyError = new Error("test error");
            const errorEvent: console.IConsoleData = {
                message: dummyError as any,
                stderr: false, // log() should still log as ExceptionData
            };

            channel.publish("console", logEvent);
            assert.ok(trackExceptionStub.notCalled);
            assert.ok(trackTraceStub.calledOnce);
            assert.deepEqual(trackTraceStub.args[0][0].message, "test log");
            trackExceptionStub.reset();
            trackTraceStub.reset();

            channel.publish("console", errorEvent);
            assert.ok(trackExceptionStub.calledOnce);
            assert.ok(trackTraceStub.notCalled);
            assert.deepEqual(trackExceptionStub.args[0][0].exception, dummyError);

            disable();
            trackExceptionStub.restore();
            trackTraceStub.restore();
        });
    });
github microsoft / node-diagnostic-channel / src / diagnostic-channel-publishers / src / pg.pub.ts View on Github external
const trackingCallback = channel.bindToContext(function(err: Error, res: IPostgresResult): any {
                const end = process.hrtime(start);
                data.result = res && { rowCount: res.rowCount, command: res.command };
                data.error = err;
                data.duration = Math.ceil((end[0] * 1e3) + (end[1] / 1e6));
                channel.publish("postgres", data);

                // emulate weird internal behavior in pg@6
                // on success, the callback is called *before* query events are emitted
                // on failure, the callback is called *instead of* the query emitting events
                // with no events, that means no promises (since the promise is resolved/rejected in an event handler)
                // since we are always inserting ourselves as a callback, we have to restore the original
                // behavior if the user didn't provide one themselves
                if (err) {
                    if (cb) {
                        return cb.apply(this, arguments);
                    } else if (queryResult && queryResult instanceof EventEmitter) {
                        queryResult.emit("error", err);
                    }
                } else if (cb) {
                    cb.apply(this, arguments);
                }
github microsoft / node-diagnostic-channel / src / diagnostic-channel-publishers / src / mysql.pub.ts View on Github external
return function(err) {
            const hrDuration = process.hrtime(resultContainer.startTime);
            /* tslint:disable-next-line:no-bitwise */
            const duration = (hrDuration[0] * 1e3 + hrDuration[1] / 1e6) | 0;
            channel.publish("mysql", {query: resultContainer.result, callbackArgs: arguments, err, duration});
            cb.apply(this, arguments);
        };
    });
github microsoft / node-diagnostic-channel / src / diagnostic-channel-publishers / src / redis.pub.ts View on Github external
commandObj.callback = channel.bindToContext(function(err, result) {
                    const hrDuration = process.hrtime(startTime);
                    /* tslint:disable-next-line:no-bitwise */
                    const duration = (hrDuration[0] * 1e3 + hrDuration[1] / 1e6) | 0;
                    channel.publish("redis", {duration, address, commandObj, err, result});

                    if (typeof cb === "function") {
                        cb.apply(this, arguments);
                    }
                });
                commandObj.callback.pubsubBound = true;
github microsoft / node-diagnostic-channel / src / diagnostic-channel-publishers / src / winston.pub.ts View on Github external
const loggingFilter = (level, message, meta) => {
        let levelKind: string;
        if (curLevels === originalWinston.config.npm.levels) {
            levelKind = "npm";
        } else if (curLevels === originalWinston.config.syslog.levels) {
            levelKind = "syslog";
        } else {
            levelKind = "unknown";
        }
        channel.publish("winston", {level, message, meta, levelKind});
        return message;
    };
github microsoft / node-diagnostic-channel / src / diagnostic-channel-publishers / src / azure-coretracing.pub.ts View on Github external
public onEnd(span: coreTracingTypes.Span): void {
        channel.publish("azure-coretracing", span);
    }
github microsoft / node-diagnostic-channel / src / diagnostic-channel-publishers / src / bunyan.pub.ts View on Github external
originalBunyan.prototype._emit = function(rec, noemit) {
        const ret = originalEmit.apply(this, arguments);
        if (!noemit) {
            let str = ret;
            if (!str) {
                str = originalEmit.call(this, rec, true);
            }
            channel.publish("bunyan", {level: rec.level, result: str});
        }
        return ret;
    };
github microsoft / node-diagnostic-channel / src / diagnostic-channel-publishers / src / mongodb.pub.ts View on Github external
            contextMap[event.requestId](() => channel.publish("mongodb", {startedData, event, succeeded: false}));
            delete contextMap[event.requestId];
github microsoft / node-diagnostic-channel / src / diagnostic-channel-publishers / src / tedious.pub.ts View on Github external
return channel.bindToContext(function(err: Error | null, rowCount?: number | null, rows?: any) {
                const end = process.hrtime(start);
                data = { ...data,
                    database: {
                        host: this.connection.config.server,
                        port: this.connection.config.options.port,
                    },
                    result: !err && { rowCount, rows },
                    query: {
                        text: this.parametersByName.statement.value,
                    },
                    error: err,
                    duration: Math.ceil((end[0] * 1e3) + (end[1] / 1e6)),
                };
                channel.publish("tedious", data);
                origCallback.call(this, err, rowCount, rows);
            });
        }

diagnostic-channel

Provides a context-saving pub/sub channel to connect diagnostic event publishers and subscribers

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis

Similar packages