Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tags.set(methodKey, { value: 'REPL' });
tags.set(statusKey, { value: 'OK' });
globalStats.record([{
measure: mLineLengths,
value: processedLine.length
}], tags);
globalStats.record([{
measure: mLatencyMs,
value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
}], tags);
} catch (err) {
console.log(err);
const errTags = new TagMap();
errTags.set(methodKey, { value: 'repl' });
errTags.set(statusKey, { value: 'ERROR' });
globalStats.record([{
measure: mLatencyMs,
value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
}], errTags);
}
// Restarts the start time for the REPL
startNanoseconds = endNanoseconds;
});tags.set(methodKey, { value: 'REPL' });
tags.set(statusKey, { value: 'OK' });
globalStats.record([{
measure: mLineLengths,
value: processedLine.length
}], tags);
globalStats.record([{
measure: mLatencyMs,
value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
}], tags);
} catch (err) {
console.log(err);
const errTags = new TagMap();
errTags.set(methodKey, { value: 'repl' });
errTags.set(statusKey, { value: 'ERROR' });
globalStats.record([{
measure: mLatencyMs,
value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
}], errTags);
}
// Restarts the start time for the REPL
startNanoseconds = endNanoseconds;
});lineReader.on('line', function (line) {
// Read
try {
const processedLine = processLine(line); // Evaluate
console.log(processedLine); // Print
// Registers the end of our REPL
[_, endNanoseconds] = process.hrtime();
const tags = new TagMap();
tags.set(methodKey, { value: 'REPL' });
tags.set(statusKey, { value: 'OK' });
globalStats.record([{
measure: mLineLengths,
value: processedLine.length
}], tags);
globalStats.record([{
measure: mLatencyMs,
value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
}], tags);
} catch (err) {
console.log(err);
const errTags = new TagMap();value: 1
}], tags);
tags.set(tagPhase, { value: valueTLSNegotiation });
globalStats.record([{
measure: mLatencyMs,
value: 1
}], tags);
tags.set(tagPhase, { value: valueLoad });
globalStats.record([{
measure: mLatencyMs,
value: 1
}], tags);
const tags1 = new TagMap();
tags1.set(tagClient, { value: valueWeb });
globalStats.record([{
measure: mClickCount,
value: 1
}], tags1);
res.status(200).send("Received").end();
console.log('Competed recording metrics');
} catch (err) {
console.log(`Could not save stats: ${err}`);
res.status(500).send("Error saving stats").end();
}
// [END web_client_monitoring_record]
});lineReader.on('line', function (line) {
// Read
try {
const processedLine = processLine(line); // Evaluate
console.log(processedLine); // Print
// Registers the end of our REPL
[_, endNanoseconds] = process.hrtime();
const tags = new TagMap();
tags.set(methodKey, { value: 'REPL' });
tags.set(statusKey, { value: 'OK' });
globalStats.record([{
measure: mLineLengths,
value: processedLine.length
}], tags);
globalStats.record([{
measure: mLatencyMs,
value: sinceInMilliseconds(endNanoseconds, startNanoseconds)
}], tags);
} catch (err) {
console.log(err);
const errTags = new TagMap();err.message
);
} else {
span.setStatus(CanonicalCode.OK);
span.addAttribute(
GrpcPlugin.ATTRIBUTE_GRPC_STATUS_CODE,
grpcTypes.status.OK.toString()
);
}
span.addMessageEvent(MessageEventType.SENT, 1);
// record stats: new RPCs on client-side inherit the tag context from
// the current Context.
const parentTagCtx = plugin.stats
? plugin.stats.getCurrentTagContext()
: new TagMap();
if (parentTagCtx.tags.size > 0) {
GrpcPlugin.setTagContext(metadata, parentTagCtx);
}
parentTagCtx.set(
clientStats.GRPC_CLIENT_METHOD,
{ value: span.name },
UNLIMITED_PROPAGATION_MD
);
GrpcPlugin.recordStats(
span.kind,
parentTagCtx,
originalArgs,
res,
Date.now() - startTime
);rootSpan.addAttribute(
GrpcPlugin.ATTRIBUTE_GRPC_ERROR_MESSAGE,
err.message
);
} else {
rootSpan.setStatus(CanonicalCode.OK);
rootSpan.addAttribute(
GrpcPlugin.ATTRIBUTE_GRPC_STATUS_CODE,
grpcTypes.status.OK.toString()
);
}
rootSpan.addMessageEvent(MessageEventType.RECEIVED, 1);
// record stats
const parentTagCtx =
GrpcPlugin.getTagContext(call.metadata) || new TagMap();
parentTagCtx.set(
serverStats.GRPC_SERVER_METHOD,
{ value: rootSpan.name },
UNLIMITED_PROPAGATION_MD
);
const req = call.hasOwnProperty('request') ? call.request : {};
GrpcPlugin.recordStats(
rootSpan.kind,
parentTagCtx,
value,
req,
Date.now() - startTime
);
rootSpan.end();
return callback(err, value, trailer, flags);function main () {
const tags1 = new TagMap();
tags1.set(K1, V1);
globalStats.withTagContext(tags1, () => {
console.log('Enter Scope 1');
printMap('Add Tags', tags1.tags);
printMap('Current Tags == Default + tags1:',
globalStats.getCurrentTagContext().tags);
const tags2 = new TagMap();
tags2.set(K2, V2);
globalStats.withTagContext(tags2, () => {
console.log('Enter Scope 2');
printMap('Add Tags', tags2.tags);
printMap('Current Tags == Default + tags1 + tags2:', globalStats.getCurrentTagContext().tags);
const measurement = { measure: mLatencyMs, value: 10 };globalStats.withTagContext(tags1, () => {
console.log('Enter Scope 1');
printMap('Add Tags', tags1.tags);
printMap('Current Tags == Default + tags1:',
globalStats.getCurrentTagContext().tags);
const tags2 = new TagMap();
tags2.set(K2, V2);
globalStats.withTagContext(tags2, () => {
console.log('Enter Scope 2');
printMap('Add Tags', tags2.tags);
printMap('Current Tags == Default + tags1 + tags2:', globalStats.getCurrentTagContext().tags);
const measurement = { measure: mLatencyMs, value: 10 };
globalStats.record([measurement]);
console.log('Close Scope 2');
});
printMap('Current Tags == Default + tags1:', globalStats.getCurrentTagContext().tags);
console.log('Close Scope 1');
});
}