@netlify/opentelemetry-sdk-setup 1.0.1 → 1.0.2

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.
package/lib/bin.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import process from 'node:process';
2
+ import { setGlobalContext } from '@netlify/opentelemetry-utils';
2
3
  import { diag } from '@opentelemetry/api';
3
4
  import argsParser from 'yargs-parser';
4
5
  import { startTracing, stopTracing } from './sdk-setup.js';
5
- import { findExecutablePackageJSON, setGlobalContext } from './util.js';
6
+ import { findExecutablePackageJSON } from './util.js';
6
7
  const DEFAULT_OTEL_TRACING_PORT = 4317;
7
8
  const DEFAULT_OTEL_ENDPOINT_PROTOCOL = 'http';
8
9
  const defaultOptions = {
@@ -23,10 +23,3 @@ export type TracingOptions = {
23
23
  export declare const startTracing: (options: TracingOptions, packageJson: PackageJson) => Promise<import("@opentelemetry/api").Context | undefined>;
24
24
  /** Stops the tracing service if there's one running. This will flush any ongoing events */
25
25
  export declare const stopTracing: () => Promise<void>;
26
- /** Sets attributes to be propagated across child spans under the current active context
27
- * TODO this method will be removed from this package once we move it to a dedicated one to be shared between build,
28
- * this setup and any other node module which might use our open telemetry setup
29
- * */
30
- export declare const setMultiSpanAttributes: (attributes: {
31
- [key: string]: string;
32
- }) => import("@opentelemetry/api").Context;
package/lib/sdk-setup.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { HoneycombSDK } from '@honeycombio/opentelemetry-node';
2
- import { trace, diag, context, propagation, DiagLogLevel, TraceFlags } from '@opentelemetry/api';
2
+ import { setMultiSpanAttributes } from '@netlify/opentelemetry-utils';
3
+ import { trace, diag, context, DiagLogLevel, TraceFlags } from '@opentelemetry/api';
3
4
  import { Resource } from '@opentelemetry/resources';
4
5
  import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
5
6
  import { getDiagLogger, loadBaggageFromFile } from './util.js';
@@ -59,16 +60,3 @@ export const stopTracing = async function () {
59
60
  diag.error(e);
60
61
  }
61
62
  };
62
- /** Sets attributes to be propagated across child spans under the current active context
63
- * TODO this method will be removed from this package once we move it to a dedicated one to be shared between build,
64
- * this setup and any other node module which might use our open telemetry setup
65
- * */
66
- export const setMultiSpanAttributes = function (attributes) {
67
- const currentBaggage = propagation.getBaggage(context.active());
68
- // Create a baggage if there's none
69
- let baggage = currentBaggage === undefined ? propagation.createBaggage() : currentBaggage;
70
- Object.entries(attributes).forEach(([key, value]) => {
71
- baggage = baggage.setEntry(key, { value });
72
- });
73
- return propagation.setBaggage(context.active(), baggage);
74
- };
package/lib/util.d.ts CHANGED
@@ -1,19 +1,10 @@
1
- import { DiagLogger, Context } from '@opentelemetry/api';
1
+ import { DiagLogger } from '@opentelemetry/api';
2
2
  import { PackageJson } from 'read-pkg-up';
3
3
  /** Given a simple logging function return a `DiagLogger`. Used to setup our system logger as the diag logger.*/
4
4
  export declare const getDiagLogger: (debug: boolean, systemLogFile?: number) => DiagLogger;
5
+ /** Loads the baggage attributes from a baggage file which follows W3C Baggage specification */
5
6
  export declare const loadBaggageFromFile: (baggageFilePath?: string) => Promise<Record<string, string>>;
6
7
  /**
7
8
  * Given a path to a node executable (potentially a symlink) get the module packageJson
8
9
  */
9
10
  export declare const findExecutablePackageJSON: (path: string) => Promise<PackageJson>;
10
- /**
11
- * Sets global context to be used when initialising our root span
12
- * TODO this will move to a shared package (opentelemetry-utils) to scope the usage of this global property there
13
- */
14
- export declare const setGlobalContext: (ctx: Context) => void;
15
- /**
16
- * Gets the global context to be used when initialising our root span
17
- * TODO this will move to a shared package (opentelemetry-utils) to scope the usage of this global property there
18
- */
19
- export declare const getGlobalContext: () => Context;
package/lib/util.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createWriteStream } from 'node:fs';
2
2
  import { realpath, readFile } from 'node:fs/promises';
3
- import { diag, context } from '@opentelemetry/api';
3
+ import { diag } from '@opentelemetry/api';
4
4
  import { parseKeyPairsIntoRecord } from '@opentelemetry/core/build/src/baggage/utils.js';
5
5
  import { readPackageUp } from 'read-pkg-up';
6
6
  /**
@@ -50,7 +50,7 @@ systemLogFile) {
50
50
  warn: otelLogger,
51
51
  };
52
52
  };
53
- //** Loads the baggage attributes from a baggage file which follows W3C Baggage specification */
53
+ /** Loads the baggage attributes from a baggage file which follows W3C Baggage specification */
54
54
  export const loadBaggageFromFile = async function (baggageFilePath) {
55
55
  if (baggageFilePath === undefined || baggageFilePath.length === 0) {
56
56
  diag.warn('No baggage file path provided, no context loaded');
@@ -91,20 +91,3 @@ export const findExecutablePackageJSON = async function (path) {
91
91
  return {};
92
92
  }
93
93
  };
94
- /**
95
- * Sets global context to be used when initialising our root span
96
- * TODO this will move to a shared package (opentelemetry-utils) to scope the usage of this global property there
97
- */
98
- export const setGlobalContext = function (ctx) {
99
- global['NETLIFY_GLOBAL_CONTEXT'] = ctx;
100
- };
101
- /**
102
- * Gets the global context to be used when initialising our root span
103
- * TODO this will move to a shared package (opentelemetry-utils) to scope the usage of this global property there
104
- */
105
- export const getGlobalContext = function () {
106
- if (global['NETLIFY_GLOBAL_CONTEXT'] === undefined) {
107
- return context.active();
108
- }
109
- return global['NETLIFY_GLOBAL_CONTEXT'];
110
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/opentelemetry-sdk-setup",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Opentelemetry SDK setup script",
5
5
  "type": "module",
6
6
  "bin": {
@@ -30,6 +30,7 @@
30
30
  "author": "Netlify Inc.",
31
31
  "dependencies": {
32
32
  "@honeycombio/opentelemetry-node": "^0.6.0",
33
+ "@netlify/opentelemetry-utils": "^1.0.1",
33
34
  "@opentelemetry/api": "~1.6.0",
34
35
  "@opentelemetry/core": "^1.17.1",
35
36
  "@opentelemetry/resources": "^1.18.1",
@@ -47,5 +48,5 @@
47
48
  "engines": {
48
49
  "node": ">=18.0.0"
49
50
  },
50
- "gitHead": "5aef135bf29606313b5e2547c4c7d77c8ff64d56"
51
+ "gitHead": "9c4fb7ba7f7cecedfbeced71de24e01ef0828b90"
51
52
  }