@netlify/opentelemetry-sdk-setup 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/bin.js +21 -12
  2. package/package.json +2 -2
package/lib/bin.js CHANGED
@@ -10,8 +10,11 @@ const defaultOptions = {
10
10
  httpProtocol: DEFAULT_OTEL_ENDPOINT_PROTOCOL,
11
11
  host: 'locahost',
12
12
  port: DEFAULT_OTEL_TRACING_PORT,
13
+ // defaults to always sample
13
14
  sampleRate: 1,
14
15
  baggageFilePath: '',
16
+ // tracing.apiKey defaults to '-' else we'll get warning logs if not using
17
+ // honeycomb directly - https://github.com/honeycombio/honeycomb-opentelemetry-node/issues/201
15
18
  apiKey: '-',
16
19
  parentSpanId: '',
17
20
  traceId: '',
@@ -28,20 +31,26 @@ const options = Object.entries(defaultOptions)
28
31
  })
29
32
  .reduce((acc, prop) => ({ ...acc, ...prop }), {});
30
33
  const executablePath = args._[1];
31
- try {
32
- const pkg = await findExecutablePackageJSON(executablePath);
33
- const rootCtx = await startTracing(options, pkg);
34
- if (rootCtx !== undefined) {
35
- diag.debug('Setting global root context imported from bagage file');
36
- setGlobalContext(rootCtx);
34
+ const run = async function () {
35
+ try {
36
+ // If tracing is disabled just skip the initialisation altogether
37
+ if (!options.preloadingEnabled)
38
+ return;
39
+ const pkg = await findExecutablePackageJSON(executablePath);
40
+ const rootCtx = await startTracing(options, pkg);
41
+ if (rootCtx !== undefined) {
42
+ diag.debug('Setting global root context imported from bagage file');
43
+ setGlobalContext(rootCtx);
44
+ }
45
+ else {
46
+ diag.debug('Root context undefined, skip setting global root context');
47
+ }
37
48
  }
38
- else {
39
- diag.debug('Root context undefined, skip setting global root context');
49
+ catch {
50
+ // don't blow up the execution in case something fails
40
51
  }
41
- }
42
- catch {
43
- // don't blow up the execution in case something fails
44
- }
52
+ };
45
53
  //TODO handle `stopTracing` via `process` event emitter for all the other cases such as
46
54
  //SIGINT and SIGTERM signals and potential uncaught exceptions
47
55
  process.on('beforeExit', async () => await stopTracing());
56
+ await run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/opentelemetry-sdk-setup",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Opentelemetry SDK setup script",
5
5
  "type": "module",
6
6
  "bin": {
@@ -47,5 +47,5 @@
47
47
  "engines": {
48
48
  "node": ">=18.0.0"
49
49
  },
50
- "gitHead": "9c8c452edb6d062ac7f03eaa64e9a23e0791ad7c"
50
+ "gitHead": "5aef135bf29606313b5e2547c4c7d77c8ff64d56"
51
51
  }