Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import logging from '@fbcnms/logging';
import tracing from '@opencensus/nodejs';
import {B3Format} from '@opencensus/propagation-b3';
import {JaegerTraceExporter} from '@opencensus/exporter-jaeger';
import {PrometheusStatsExporter} from '@opencensus/exporter-prometheus';
import {globalStats} from '@opencensus/core';
import {registerAllViews} from '@opencensus/instrumentation-http';
import {runMigrations} from './runMigrations';
const {sequelize} = require('@fbcnms/sequelize-models');
const logger = logging.getLogger(module);
const port = parseInt(process.env.PORT || 80);
// Configure metrics
const prometheusExporter = new PrometheusStatsExporter({
startServer: true,
logger,
});
globalStats.registerExporter(prometheusExporter);
registerAllViews(globalStats);
let jaegerExporter = null;
if (process.env.TELEMETRY_TRACE_EXPORTER == 'jaeger') {
if (
!process.env.JAEGER_AGENT_ENDPOINT &&
!process.env.JAEGER_COLLECTOR_ENDPOINT
) {
throw new Error(
'When using TELEMETRY_TRACE_EXPORTER = "jaeger", you ' +
'must set either JAEGER_AGENT_ENDPOINT or JAEGER_COLLECTOR_ENDPOINT',
);
*/
/**
* This is an example of exporting a custom metric from
* OpenCensus to Prometheus.
*/
const { globalStats, MeasureUnit, AggregationType, TagMap } = require('@opencensus/core');
const { PrometheusStatsExporter } = require('@opencensus/exporter-prometheus');
const fs = require('fs');
const readline = require('readline');
// [START setup_exporter]
// Enable OpenCensus exporters to export metrics to Prometheus Monitoring.
const exporter = new PrometheusStatsExporter({
// Metrics will be exported on https://localhost:{port}/metrics
port: 9464,
startServer: true
});
// Pass the created exporter to global Stats
globalStats.registerExporter(exporter);
// [END setup_exporter]
// The latency in milliseconds
const mLatencyMs = globalStats.createMeasureDouble(
'repl/latency',
MeasureUnit.MS,
'The latency in milliseconds per REPL loop'
);
host: jaeger_host,
port: jaeger_port,
serviceName: service_name,
});
tracing.start({
propagation: b3,
samplingRate: 1.0,
exporter: exporter
});
// Set up Prometheus
const prometheus = require('@opencensus/exporter-prometheus');
const prometheusExporter = new prometheus.PrometheusStatsExporter({
startServer: true
})
// Set up custom stats
const stats = new opencensus.Stats()
const tags = {ServiceName: service_name};
const tagKeys = Object.keys(tags);
const fibCount = stats.createMeasureInt64('fib function invocation', '1')
stats.createView('fib_count', fibCount, 0, tagKeys,'number of fib functions calls over time', null)
stats.registerExporter(prometheusExporter)
// End of OpenCensus setup ----------------------------------------------------------------------------