Skip to content

Commit e0bcc1f

Browse files
author
Jakub Ner
committed
Add insights
1 parent e2a2fa1 commit e0bcc1f

File tree

4 files changed

+372
-0
lines changed

4 files changed

+372
-0
lines changed

main/js/lib/insights.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use strict";
2+
3+
const applicationinsights = require('applicationinsights');
4+
5+
// private attribtues
6+
const ctx = Symbol('context');
7+
8+
// private functions
9+
const checkInit = Symbol('checkInit');
10+
11+
/**
12+
* Wires up functionality we use throughout.
13+
*
14+
* Module returns this class as object all wired-up. Before you can use the methods you must "init" the object
15+
* somewhere at process start.
16+
*
17+
* Leverages node's module system for a sort of context & dependency injection, so order of requiring and initializing
18+
* these sorts of libraries matters.
19+
*/
20+
class Insights {
21+
constructor() {
22+
this[ctx] = null;
23+
}
24+
25+
// ensure this is initialized
26+
[checkInit]() {
27+
if (! this[ctx]) throw new Error('library not initialized, call "init" when wiring up app first');
28+
}
29+
30+
/**
31+
* Initialize this library: this must be the first method called somewhere from where you're doing context & dependency
32+
* injection.
33+
*
34+
* @param {string} insights_key - insights key
35+
* @returns {Insights} this
36+
*/
37+
init({insights_key} = {}) {
38+
if (insights_key == null) {
39+
return;
40+
}
41+
42+
this[ctx] = {
43+
insights_key: insights_key
44+
};
45+
46+
applicationinsights.setup(insights_key).start();
47+
48+
return this;
49+
}
50+
}
51+
52+
module.exports = (new Insights());

main/js/overhide-ethereum.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const DEBUG = process.env.DEBUG || process.env.npm_config_DEBUG || process.env.n
2020
const SALT = process.env.SALT || process.env.npm_config_SALT || process.env.npm_package_config_SALT;
2121
const TOKEN_URL = process.env.TOKEN_URL || process.env.npm_config_TOKEN_URL || process.env.npm_package_config_TOKEN_URL;
2222
const ISPROD = process.env.ISPROD || process.env.npm_config_ISPROD || process.env.npm_package_config_ISPROD || false;
23+
const INSIGHTS_KEY = process.env.INSIGHTS_KEY || process.env.npm_config_INSIGHTS_KEY || process.env.npm_package_config_INSIGHTS_KEY
2324
const INTERNAL_TOKEN = process.env.INTERNAL_TOKEN || process.env.npm_config_INTERNAL_TOKEN || process.env.npm_package_config_INTERNAL_TOKEN;
2425
const WEB3_URI = process.env.WEB3_URI || process.env.npm_config_WEB3_URI || process.env.npm_package_config_WEB3_URI;
2526
const ETHERSCAN_KEY = process.env.ETHERSCAN_KEY || process.env.npm_config_ETHERSCAN_KEY || process.env.npm_package_config_ETHERSCAN_KEY;
@@ -55,6 +56,7 @@ const ctx_config = {
5556
tokenUrl: TOKEN_URL,
5657
isProd: ISPROD && /true/i.test(ISPROD),
5758
isTest: !(!!ISPROD && /true/i.test(ISPROD)),
59+
insights_key: INSIGHTS_KEY,
5860
etherscan_key: ETHERSCAN_KEY,
5961
ethereum_network: NETWORK_TYPE,
6062
web3_uri: WEB3_URI,
@@ -80,6 +82,7 @@ const ctx_config = {
8082
};
8183
const log = require('./lib/log.js').init(ctx_config).fn("app");
8284
const debug = require('./lib/log.js').init(ctx_config).debug_fn("app");
85+
const insights_key = require('./lib/insights.js').init(ctx_config);
8386
const crypto = require('./lib/crypto.js').init(ctx_config);
8487
const eth = require('./lib/eth-chain.js').init(ctx_config);
8588
const etherscan = require('./lib/etherscan.js').init(ctx_config);
@@ -90,6 +93,7 @@ const throttle = require('./lib/throttle.js').init(ctx_config);
9093
const normalizer = require('./lib/normalizer.js').init(ctx_config);
9194
const tallyCache = require('./lib/tally-cache.js').init(ctx_config);
9295
log("CONFIG:\n%O", ((cfg) => {
96+
cfg.insights_key = cfg.insights_key ? cfg.insights_key.replace(/.(?=.{2})/g,'*') : null;
9397
cfg.web3_uri = cfg.web3_uri.replace(/.(?=.{2})/g,'*');
9498
cfg.etherscan_key = cfg.etherscan_key.replace(/.(?=.{2})/g,'*');
9599
cfg.pgpassword = cfg.pgpassword.replace(/.(?=.{2})/g,'*');

0 commit comments

Comments
 (0)