arvo-core 1.0.23 → 1.0.25

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/CHANGELOG.md CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
  - Fix a type bug in ArvoEvent creation
42
42
 
43
- ## [1.0.23] - 2024-09-07
43
+ ## [1.0.25] - 2024-09-08
44
44
 
45
45
  - Updated OpenTelemetry propagation and fixed propagation in the event factory
46
46
 
@@ -52,7 +52,7 @@ var createArvoEvent = function (event, extensions) {
52
52
  if (event.datacontenttype &&
53
53
  event.datacontenttype !== schema_1.ArvoDataContentType) {
54
54
  var warning = (0, utils_1.cleanString)("\n Warning! The provided datacontenttype(=".concat(event.datacontenttype, ")\n is not ArvoEvent compatible (=").concat(schema_1.ArvoDataContentType, "). There may \n be some limited functionality.\n "));
55
- (0, OpenTelemetry_1.logToSpan)(span, {
55
+ (0, OpenTelemetry_1.logToSpan)({
56
56
  level: 'WARNING',
57
57
  message: warning,
58
58
  });
@@ -75,7 +75,7 @@ var createArvoEvent = function (event, extensions) {
75
75
  }, event.data, extensions);
76
76
  }
77
77
  catch (error) {
78
- (0, OpenTelemetry_1.exceptionToSpan)(span, error);
78
+ (0, OpenTelemetry_1.exceptionToSpan)(error);
79
79
  span.setStatus({
80
80
  code: api_1.SpanStatusCode.ERROR,
81
81
  message: error.message,
@@ -65,7 +65,7 @@ var ArvoEventFactory = /** @class */ (function () {
65
65
  return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { type: _this.contract.accepts.type, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions);
66
66
  }
67
67
  catch (error) {
68
- (0, OpenTelemetry_1.exceptionToSpan)(span, error);
68
+ (0, OpenTelemetry_1.exceptionToSpan)(error);
69
69
  span.setStatus({
70
70
  code: api_1.SpanStatusCode.ERROR,
71
71
  message: error.message,
@@ -100,7 +100,7 @@ var ArvoEventFactory = /** @class */ (function () {
100
100
  return (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri, data: validationResult.data }), extensions);
101
101
  }
102
102
  catch (error) {
103
- (0, OpenTelemetry_1.exceptionToSpan)(span, error);
103
+ (0, OpenTelemetry_1.exceptionToSpan)(error);
104
104
  span.setStatus({
105
105
  code: api_1.SpanStatusCode.ERROR,
106
106
  message: error.message,
@@ -134,7 +134,7 @@ var ArvoEventFactory = /** @class */ (function () {
134
134
  }, datacontenttype: schema_1.ArvoDataContentType, dataschema: _this.contract.uri }), extensions);
135
135
  }
136
136
  catch (error) {
137
- (0, OpenTelemetry_1.exceptionToSpan)(span, error);
137
+ (0, OpenTelemetry_1.exceptionToSpan)(error);
138
138
  span.setStatus({
139
139
  code: api_1.SpanStatusCode.ERROR,
140
140
  message: error.message,
@@ -6,22 +6,27 @@ import { TelemetryLogLevel, OpenTelemetryHeaders } from './types';
6
6
  export declare const ArvoCoreTracer: import("@opentelemetry/api").Tracer;
7
7
  /**
8
8
  * Logs a message to a span with additional parameters.
9
- * @param span - The span to log the message to.
10
9
  * @param params - The parameters for the log message.
11
- * @param params.level - The log level.
12
- * @param params.message - The log message.
10
+ * @param params.level - The log level of the message.
11
+ * @param params.message - The main content of the log message.
12
+ * @param span - The span to log the message to. If not provided, the active span is used.
13
+ * If no active span is available, the message is logged to the console.
13
14
  */
14
- export declare const logToSpan: (span: Span, params: {
15
+ export declare const logToSpan: (params: {
16
+ /** The log level */
15
17
  level: TelemetryLogLevel;
18
+ /** The log message */
16
19
  message: string;
17
- }) => void;
20
+ /** Other log parameters */
21
+ [key: string]: string;
22
+ }, span?: Span | undefined) => void;
18
23
  /**
19
24
  * Logs an exception to a span and sets exception-related attributes.
20
- * @param span - The span to log the exception to.
21
- * @param level - The log level for the exception.
22
25
  * @param error - The error object to be logged.
26
+ * @param span - The span to log the exception to. If not provided, the active span is used.
27
+ * If no active span is available, the error is logged to the console.
23
28
  */
24
- export declare const exceptionToSpan: (span: Span, error: Error) => void;
29
+ export declare const exceptionToSpan: (error: Error, span?: Span | undefined) => void;
25
30
  /**
26
31
  * A constant representing a null or not applicable value in OpenTelemetry context.
27
32
  */
@@ -23,27 +23,41 @@ var pkg = (0, utils_1.getPackageInfo)();
23
23
  exports.ArvoCoreTracer = api_1.trace.getTracer(pkg.name, pkg.version);
24
24
  /**
25
25
  * Logs a message to a span with additional parameters.
26
- * @param span - The span to log the message to.
27
26
  * @param params - The parameters for the log message.
28
- * @param params.level - The log level.
29
- * @param params.message - The log message.
27
+ * @param params.level - The log level of the message.
28
+ * @param params.message - The main content of the log message.
29
+ * @param span - The span to log the message to. If not provided, the active span is used.
30
+ * If no active span is available, the message is logged to the console.
30
31
  */
31
- var logToSpan = function (span, params) {
32
- span.addEvent('log_message', __assign(__assign({}, params), { timestamp: performance.now() }));
32
+ var logToSpan = function (params, span) {
33
+ if (span === void 0) { span = api_1.trace.getActiveSpan(); }
34
+ var toLog = __assign(__assign({}, params), { timestamp: performance.now() });
35
+ if (span) {
36
+ span.addEvent('log_message', toLog);
37
+ }
38
+ else {
39
+ console.log(JSON.stringify(toLog, null, 2));
40
+ }
33
41
  };
34
42
  exports.logToSpan = logToSpan;
35
43
  /**
36
44
  * Logs an exception to a span and sets exception-related attributes.
37
- * @param span - The span to log the exception to.
38
- * @param level - The log level for the exception.
39
45
  * @param error - The error object to be logged.
46
+ * @param span - The span to log the exception to. If not provided, the active span is used.
47
+ * If no active span is available, the error is logged to the console.
40
48
  */
41
- var exceptionToSpan = function (span, error) {
42
- span.setAttributes({
43
- 'exception.type': error.name,
44
- 'exception.message': error.message,
45
- });
46
- span.recordException(error);
49
+ var exceptionToSpan = function (error, span) {
50
+ if (span === void 0) { span = api_1.trace.getActiveSpan(); }
51
+ if (span) {
52
+ span.setAttributes({
53
+ 'exception.type': error.name,
54
+ 'exception.message': error.message,
55
+ });
56
+ span.recordException(error);
57
+ }
58
+ else {
59
+ console.error(error);
60
+ }
47
61
  };
48
62
  exports.exceptionToSpan = exceptionToSpan;
49
63
  /**
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import ArvoEvent from './ArvoEvent';
2
2
  import { ArvoDataContentType } from './ArvoEvent/schema';
3
3
  import { createArvoEvent } from './ArvoEvent/helpers';
4
4
  import { CloudEventContext, CloudEventExtension, ArvoEventData, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent } from './ArvoEvent/types';
5
- import { exceptionToSpan, logToSpan, OTelNull } from './OpenTelemetry';
5
+ import { exceptionToSpan, logToSpan, OTelNull, currentOpenTelemetryHeaders } from './OpenTelemetry';
6
6
  import { OpenTelemetryHeaders, TelemetryLogLevel } from './OpenTelemetry/types';
7
7
  import { validateURI, cleanString } from './utils';
8
8
  import ArvoContract from './ArvoContract';
@@ -80,4 +80,4 @@ declare const ArvoEventSchemas: {
80
80
  tracestate: string | null;
81
81
  }>;
82
82
  };
83
- export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, InferArvoContract, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, };
83
+ export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, InferArvoContract, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ArvoErrorSchema = exports.createArvoEventFactory = exports.ArvoEventFactory = exports.createArvoContractLibrary = exports.ArvoContractLibrary = exports.ArvoContractValidators = exports.createArvoContract = exports.ArvoContract = exports.cleanString = exports.validateURI = exports.OTelNull = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchemas = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = void 0;
6
+ exports.currentOpenTelemetryHeaders = exports.ArvoErrorSchema = exports.createArvoEventFactory = exports.ArvoEventFactory = exports.createArvoContractLibrary = exports.ArvoContractLibrary = exports.ArvoContractValidators = exports.createArvoContract = exports.ArvoContract = exports.cleanString = exports.validateURI = exports.OTelNull = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchemas = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = void 0;
7
7
  var ArvoEvent_1 = __importDefault(require("./ArvoEvent"));
8
8
  exports.ArvoEvent = ArvoEvent_1.default;
9
9
  var schema_1 = require("./ArvoEvent/schema");
@@ -14,6 +14,7 @@ var OpenTelemetry_1 = require("./OpenTelemetry");
14
14
  Object.defineProperty(exports, "exceptionToSpan", { enumerable: true, get: function () { return OpenTelemetry_1.exceptionToSpan; } });
15
15
  Object.defineProperty(exports, "logToSpan", { enumerable: true, get: function () { return OpenTelemetry_1.logToSpan; } });
16
16
  Object.defineProperty(exports, "OTelNull", { enumerable: true, get: function () { return OpenTelemetry_1.OTelNull; } });
17
+ Object.defineProperty(exports, "currentOpenTelemetryHeaders", { enumerable: true, get: function () { return OpenTelemetry_1.currentOpenTelemetryHeaders; } });
17
18
  var utils_1 = require("./utils");
18
19
  Object.defineProperty(exports, "validateURI", { enumerable: true, get: function () { return utils_1.validateURI; } });
19
20
  Object.defineProperty(exports, "cleanString", { enumerable: true, get: function () { return utils_1.cleanString; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "This core package contains all the core classes and components of the Arvo Event Driven System",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {