-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (59 loc) · 2.38 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const beeline = require('honeycomb-beeline');
const instrumentHTTP = require('./instrumentation/http');
/**
* @typedef {object} Options
* @property {string} APIKey
* @property {string | undefined} APIHost
* @property {string} TracingDataset
* @property {number} DesiredSampleRate
* @property {Record<string, unknown> | undefined} GlobalMetadata
* @property {(ev: { data: Record<string, unknown> }) => void | undefined} [presendHook]
*/
/**
* Configure honeycomb with our standard preferences
* @param {string} name the name of the service
* @param {string | "http"} process the type of process (e.g. "http" or "worker")
* @param {string} gitSha the git sha representing the version of the service
* @param {Options | "mock"} options configuration options, or the literal "mock" to use the mock backend
*
* @returns {beeline.Beeline}
*/
module.exports = function setup(name, gitSha, options, process = 'http') {
/** @type {beeline.BeelineOpts} */
const config = {
serviceName: name,
enabledInstrumentations: ['express', 'child_process'],
};
const globalMetadata = {};
if (options == 'mock') {
config.impl = 'mock';
} else {
// config.WriteKey must be set to a non-empty value, but when we use Refinery to aggregate all of our events
// and send them using its own WriteKey, we don't need to specify app-specific WriteKeys.
// The `beeline-go` package sets a default WriteKey (which is invalid as far as Honeycomb goes)
// to allow the tracing library to be initialized.
// https://github.com/honeycombio/beeline-go/blob/56c4f55d6efec3d417ba32748718fefd2e362a0f/beeline.go#L22
const defaultWriteKey = 'apikey-placeholder';
config.writeKey = options.APIKey || defaultWriteKey;
config.dataset = options.TracingDataset;
config.sampleRate = options.DesiredSampleRate;
/** @param {{ data: Record<string, unknown>}} ev */
config.presendHook = ev => {
ev.data.app_sha = gitSha;
ev.data['service.process'] = process;
Object.entries(globalMetadata).forEach(([k, v]) => {
ev.data[k] = v;
});
if (options.presendHook) {
options.presendHook(ev);
}
};
Object.assign(globalMetadata, options.GlobalMetadata);
if (options.APIHost) {
config.apiHost = options.APIHost;
}
}
// Apply our custom instrumentation before configuring the beeline
instrumentHTTP();
return beeline(config);
};