How to use the diagnostic-channel.channel.subscribe 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 / node-diagnostic-channel / src / subs / mongodb-sub / mongodb.sub.ts View on Github external
name: event.data.event.commandName,
                data: event.data.event.commandName,
                duration: event.data.event.duration,
                success: event.data.succeeded,
                // TODO: transmit result code from mongo
                resultCode: event.data.succeeded ? "0" : "1",
                dependencyTypeName: "mongodb"});

        if (!event.data.succeeded) {
            ApplicationInsights.defaultClient
                .trackException({exception: new Error(event.data.event.failure)});
        }
    }
};

channel.subscribe("mongodb", subscriber);
github microsoft / node-diagnostic-channel / src / subs / mysql-sub / mysql.sub.ts View on Github external
const connection = queryObj._connection || {};
        const connectionConfig = connection.config || {};
        const dbName = connectionConfig.socketPath ? connectionConfig.socketPath : `${connectionConfig.host || "localhost"}:${connectionConfig.port}`;
        ApplicationInsights.defaultClient.trackDependency({
                target: dbName,
                name: sqlString,
                data: sqlString,
                duration: event.data.duration,
                success: success,
                // TODO: transmit result code from mysql
                resultCode: success ? "0" : "1",
                dependencyTypeName: "mysql"});
    }
};

channel.subscribe("mysql", subscriber);
github microsoft / node-diagnostic-channel / src / subs / redis-sub / redis.sub.ts View on Github external
// We don't want to report 'info', it's irrelevant
            return;
        }

        ApplicationInsights.defaultClient.trackDependency({
            target: event.data.address,
            name: event.data.commandObj.command,
            data: event.data.commandObj.command,
            duration: event.data.duration,
            success: !event.data.err,
            resultCode: event.data.err ? "1" : "0",
            dependencyTypeName: "redis"});
    }
};

channel.subscribe("redis", subscriber);
github microsoft / node-diagnostic-channel / src / publisher-legacy-tests / mongo3.0.5 / mongo3.0.5.spec.ts View on Github external
it("should fire events when we communicate with a collection, and preserve context", function(done) {
        channel.addContextPreservation((cb) => Zone.current.wrap(cb, "context preservation"));

        const events: Array> = [];
        channel.subscribe("mongodb", function(event) {
            events.push(event);
        });

        const mongodb = require("mongodb");

        const z1 = Zone.current.fork({name: "1"});
        z1.run(() =>
        mongodb.MongoClient.connect("mongodb://localhost:27017", { useNewUrlParser: true }, function(err, client) {
            if (err) {
                done(err);
            }

            const collection = client.db("testdb").collection("documents");

            if (Zone.current !== z1) {
                return done(new Error("Context not preserved in connect"));
github microsoft / node-diagnostic-channel / src / publisher-legacy-tests / pg6 / pg6.spec.ts View on Github external
beforeEach((done) => {
        channel.subscribe("postgres", listener);
        client = new pg.Client(dbSettings);
        client.connect(done);
    });
github microsoft / ApplicationInsights-node.js / AutoCollection / diagnostic-channel / bunyan.sub.ts View on Github external
export function enable(enabled: boolean, client: TelemetryClient) {
    if (enabled) {
        if (clients.length === 0) {
            channel.subscribe("bunyan", subscriber);
        };
        clients.push(client);
    } else {
        clients = clients.filter((c) => c != client);
        if (clients.length === 0) {
            channel.unsubscribe("bunyan", subscriber);
        }
    }
}
github microsoft / ApplicationInsights-node.js / AutoCollection / diagnostic-channel / winston.sub.ts View on Github external
export function enable(enabled: boolean, client: TelemetryClient) {
    if (enabled) {
        if (clients.length === 0) {
            channel.subscribe("winston", subscriber);
        };
        clients.push(client);
    } else {
        clients = clients.filter((c) => c != client);
        if (clients.length === 0) {
            channel.unsubscribe("winston", subscriber);
        }
    }
}
github microsoft / ApplicationInsights-node.js / AutoCollection / diagnostic-channel / postgres.sub.ts View on Github external
export function enable(enabled: boolean, client: TelemetryClient) {
    if (enabled) {
        if (clients.length === 0) {
            channel.subscribe("postgres", subscriber);
        };
        clients.push(client);
    } else {
        clients = clients.filter((c) => c != client);
        if (clients.length === 0) {
            channel.unsubscribe("postgres", subscriber);
        }
    }
}
github microsoft / node-diagnostic-channel / src / subs / console-sub / console.sub.ts View on Github external
import ApplicationInsights = require("applicationinsights");

import {channel, IStandardEvent} from "diagnostic-channel";

import {console as consolePub} from "diagnostic-channel-publishers";

export const subscriber = (event: IStandardEvent) => {
    if (ApplicationInsights.defaultClient) {
        const severity = event.data.stderr
            ? ApplicationInsights.Contracts.SeverityLevel.Warning
            : ApplicationInsights.Contracts.SeverityLevel.Information;
        ApplicationInsights.defaultClient.trackTrace({message: event.data.message, severity: severity});
    }
};

channel.subscribe("console", subscriber);
github microsoft / ApplicationInsights-node.js / AutoCollection / diagnostic-channel / azure-coretracing.sub.ts View on Github external
export function enable(enabled: boolean, client: TelemetryClient) {
    if (enabled) {
        if (clients.length === 0) {
            channel.subscribe("azure-coretracing", subscriber);
        };
        clients.push(client);
    } else {
        clients = clients.filter((c) => c != client);
        if (clients.length === 0) {
            channel.unsubscribe("azure-coretracing", subscriber);
        }
    }
}

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