Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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);
// 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);
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"));
beforeEach((done) => {
channel.subscribe("postgres", listener);
client = new pg.Client(dbSettings);
client.connect(done);
});
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
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);
}
}
}