unnbound-logger-sdk 3.0.34 → 3.0.35
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/dist/axios.d.ts +10 -2
- package/dist/axios.js +23 -15
- package/dist/emf.d.ts +58 -0
- package/dist/emf.js +100 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +10 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +1 -0
- package/dist/logger.js +6 -7
- package/dist/middleware.d.ts +2 -2
- package/dist/middleware.js +4 -3
- package/dist/span.d.ts +1 -1
- package/dist/span.js +1 -1
- package/dist/storage.d.ts +1 -1
- package/dist/storage.js +2 -2
- package/dist/trace.d.ts +1 -0
- package/dist/trace.js +1 -0
- package/package.json +17 -18
- package/LICENSE +0 -21
package/dist/axios.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios';
|
|
2
|
-
import { HttpOptions } from './types';
|
|
2
|
+
import { type HttpOptions } from './types';
|
|
3
3
|
type GetPayload = (config: AxiosRequestConfig, res?: AxiosResponse) => object;
|
|
4
|
+
type RedactOptions = {
|
|
5
|
+
response?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type OnRequest = (config: AxiosRequestConfig, callback: (config: AxiosRequestConfig) => Promise<AxiosResponse<any>>) => Promise<AxiosResponse<any>>;
|
|
8
|
+
interface HttpClientOptions extends HttpOptions<GetPayload> {
|
|
9
|
+
onRequest?: OnRequest;
|
|
10
|
+
redact?: RedactOptions | boolean;
|
|
11
|
+
}
|
|
4
12
|
/**
|
|
5
13
|
* Wraps an axios instance to add tracing and span tracking
|
|
6
14
|
* @param axios - The axios instance to wrap
|
|
7
15
|
* @param options - Configuration options for HTTP tracing
|
|
8
16
|
* @returns The wrapped axios instance with span tracking
|
|
9
17
|
*/
|
|
10
|
-
export declare const traceAxios: (client: AxiosInstance, { ignoreTraceRoutes, traceHeaderKey, getPayload, }?:
|
|
18
|
+
export declare const traceAxios: (client: AxiosInstance, { ignoreTraceRoutes, traceHeaderKey, getPayload, onRequest, redact: redactOptions, }?: HttpClientOptions) => AxiosInstance;
|
|
11
19
|
export {};
|
package/dist/axios.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.traceAxios = void 0;
|
|
4
4
|
const axios_1 = require("axios");
|
|
5
|
-
const
|
|
5
|
+
const span_1 = require("./span");
|
|
6
6
|
const storage_1 = require("./storage");
|
|
7
|
+
const types_1 = require("./types");
|
|
7
8
|
const utils_1 = require("./utils");
|
|
8
|
-
const span_1 = require("./span");
|
|
9
9
|
const buildUrl = (baseUrl, url) => {
|
|
10
10
|
return url?.startsWith('http') ? url : [baseUrl, url].filter(Boolean).join('');
|
|
11
11
|
};
|
|
@@ -16,7 +16,7 @@ const extractQueryParams = (url, config) => {
|
|
|
16
16
|
keys.forEach((key) => object.searchParams.delete(key));
|
|
17
17
|
return { url: object.toString(), query: keys.length > 0 ? query : undefined };
|
|
18
18
|
};
|
|
19
|
-
const buildOutgoingHttpPayload = (config, res) => ({
|
|
19
|
+
const buildOutgoingHttpPayload = (config, res, redact) => ({
|
|
20
20
|
type: 'http',
|
|
21
21
|
http: {
|
|
22
22
|
...extractQueryParams(buildUrl(config.baseURL, config.url), config),
|
|
@@ -30,23 +30,26 @@ const buildOutgoingHttpPayload = (config, res) => ({
|
|
|
30
30
|
? {
|
|
31
31
|
headers: res?.headers,
|
|
32
32
|
status: res.status,
|
|
33
|
-
body: (0, utils_1.safeJsonParse)(res.data),
|
|
33
|
+
body: redact?.response ? '[Redacted]' : (0, utils_1.safeJsonParse)(res.data),
|
|
34
34
|
}
|
|
35
35
|
: undefined,
|
|
36
36
|
},
|
|
37
37
|
});
|
|
38
38
|
const getNoopPayload = () => ({});
|
|
39
|
+
const onNoopRequest = (config, callback) => callback(config);
|
|
39
40
|
/**
|
|
40
41
|
* Wraps an axios instance to add tracing and span tracking
|
|
41
42
|
* @param axios - The axios instance to wrap
|
|
42
43
|
* @param options - Configuration options for HTTP tracing
|
|
43
44
|
* @returns The wrapped axios instance with span tracking
|
|
44
45
|
*/
|
|
45
|
-
const traceAxios = (client, { ignoreTraceRoutes = types_1.defaultIgnoreTraceRoutes, traceHeaderKey = types_1.defaultTraceHeaderKey, getPayload = getNoopPayload, } = {
|
|
46
|
+
const traceAxios = (client, { ignoreTraceRoutes = types_1.defaultIgnoreTraceRoutes, traceHeaderKey = types_1.defaultTraceHeaderKey, getPayload = getNoopPayload, onRequest = onNoopRequest, redact: redactOptions, } = {
|
|
46
47
|
ignoreTraceRoutes: types_1.defaultIgnoreTraceRoutes,
|
|
47
48
|
traceHeaderKey: types_1.defaultTraceHeaderKey,
|
|
48
49
|
getPayload: getNoopPayload,
|
|
50
|
+
onRequest: onNoopRequest,
|
|
49
51
|
}) => {
|
|
52
|
+
const redact = typeof redactOptions === 'boolean' ? { response: redactOptions } : redactOptions;
|
|
50
53
|
const createSpanWrappedRequest = (originalMethod, method) => {
|
|
51
54
|
const { headers: defaultHeaders, ...partialDefaultConfig } = client.defaults;
|
|
52
55
|
const headers = { ...defaultHeaders.common, ...(method && defaultHeaders[method]) };
|
|
@@ -59,16 +62,21 @@ const traceAxios = (client, { ignoreTraceRoutes = types_1.defaultIgnoreTraceRout
|
|
|
59
62
|
return originalMethod(config);
|
|
60
63
|
const traceId = storage_1.storage.getStore()?.traceId;
|
|
61
64
|
config = { ...config, headers: { ...config.headers, [traceHeaderKey]: traceId } };
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
?
|
|
67
|
-
? options.error
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
return onRequest(config, (config) => {
|
|
66
|
+
// Execute the request within a span
|
|
67
|
+
return (0, span_1.startSpan)('Outgoing HTTP request', () => originalMethod(config), (options) => {
|
|
68
|
+
const response = options
|
|
69
|
+
? options.error
|
|
70
|
+
? (0, axios_1.isAxiosError)(options.error)
|
|
71
|
+
? options.error.response
|
|
72
|
+
: undefined
|
|
73
|
+
: options.result
|
|
74
|
+
: undefined;
|
|
75
|
+
return {
|
|
76
|
+
...buildOutgoingHttpPayload(config, response, redact),
|
|
77
|
+
...getPayload(config, response),
|
|
78
|
+
};
|
|
79
|
+
});
|
|
72
80
|
});
|
|
73
81
|
};
|
|
74
82
|
};
|
package/dist/emf.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CloudWatch Embedded Metric Format (EMF) support.
|
|
3
|
+
*
|
|
4
|
+
* EMF allows you to embed metrics within structured log events.
|
|
5
|
+
* CloudWatch automatically extracts these as CloudWatch Metrics.
|
|
6
|
+
*
|
|
7
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html
|
|
8
|
+
*/
|
|
9
|
+
export type MetricUnit = 'Seconds' | 'Microseconds' | 'Milliseconds' | 'Bytes' | 'Kilobytes' | 'Megabytes' | 'Gigabytes' | 'Terabytes' | 'Bits' | 'Kilobits' | 'Megabits' | 'Gigabits' | 'Terabits' | 'Percent' | 'Count' | 'Bytes/Second' | 'Kilobytes/Second' | 'Megabytes/Second' | 'Gigabytes/Second' | 'Terabytes/Second' | 'Bits/Second' | 'Kilobits/Second' | 'Megabits/Second' | 'Gigabits/Second' | 'Terabits/Second' | 'Count/Second' | 'None';
|
|
10
|
+
export interface MetricDefinition {
|
|
11
|
+
name: string;
|
|
12
|
+
unit?: MetricUnit;
|
|
13
|
+
value: number;
|
|
14
|
+
}
|
|
15
|
+
export interface EmitMetricOptions {
|
|
16
|
+
/** CloudWatch namespace (default: 'Unnbound') */
|
|
17
|
+
namespace?: string;
|
|
18
|
+
/** Dimension names to use for grouping (keys from dimensions object) */
|
|
19
|
+
dimensionKeys?: string[];
|
|
20
|
+
/** Additional properties to include in the log */
|
|
21
|
+
properties?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Emit a metric via CloudWatch EMF format.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* // Simple counter
|
|
29
|
+
* emitMetric(
|
|
30
|
+
* { name: 'workflow.created', unit: 'Count', value: 1 },
|
|
31
|
+
* { workflowId: 'wf_123', environment: 'prod' }
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* // Duration histogram
|
|
35
|
+
* emitMetric(
|
|
36
|
+
* { name: 'deployment.duration', unit: 'Seconds', value: 12.5 },
|
|
37
|
+
* { workflowId: 'wf_123', status: 'success' },
|
|
38
|
+
* { dimensionKeys: ['workflowId', 'status'] }
|
|
39
|
+
* );
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function emitMetric(metric: MetricDefinition, dimensions: Record<string, string>, options?: EmitMetricOptions): void;
|
|
43
|
+
/**
|
|
44
|
+
* Emit multiple metrics in a single EMF log event.
|
|
45
|
+
* All metrics share the same dimensions.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* emitMetrics(
|
|
50
|
+
* [
|
|
51
|
+
* { name: 'execution.duration', unit: 'Seconds', value: 1.5 },
|
|
52
|
+
* { name: 'execution.payload_size', unit: 'Bytes', value: 2048 },
|
|
53
|
+
* ],
|
|
54
|
+
* { workflowId: 'wf_123', triggerType: 'http' }
|
|
55
|
+
* );
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function emitMetrics(metrics: MetricDefinition[], dimensions: Record<string, string>, options?: EmitMetricOptions): void;
|
package/dist/emf.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emitMetric = emitMetric;
|
|
4
|
+
exports.emitMetrics = emitMetrics;
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
const DEFAULT_NAMESPACE = 'Unnbound';
|
|
7
|
+
/**
|
|
8
|
+
* Emit a metric via CloudWatch EMF format.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Simple counter
|
|
13
|
+
* emitMetric(
|
|
14
|
+
* { name: 'workflow.created', unit: 'Count', value: 1 },
|
|
15
|
+
* { workflowId: 'wf_123', environment: 'prod' }
|
|
16
|
+
* );
|
|
17
|
+
*
|
|
18
|
+
* // Duration histogram
|
|
19
|
+
* emitMetric(
|
|
20
|
+
* { name: 'deployment.duration', unit: 'Seconds', value: 12.5 },
|
|
21
|
+
* { workflowId: 'wf_123', status: 'success' },
|
|
22
|
+
* { dimensionKeys: ['workflowId', 'status'] }
|
|
23
|
+
* );
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function emitMetric(metric, dimensions, options = {}) {
|
|
27
|
+
const { namespace = DEFAULT_NAMESPACE, dimensionKeys, properties = {} } = options;
|
|
28
|
+
// Use specified dimension keys or all dimension keys
|
|
29
|
+
const dimKeys = dimensionKeys ?? Object.keys(dimensions);
|
|
30
|
+
const emfLog = {
|
|
31
|
+
// EMF metadata
|
|
32
|
+
_aws: {
|
|
33
|
+
Timestamp: Date.now(),
|
|
34
|
+
CloudWatchMetrics: [
|
|
35
|
+
{
|
|
36
|
+
Namespace: namespace,
|
|
37
|
+
Dimensions: [dimKeys],
|
|
38
|
+
Metrics: [
|
|
39
|
+
{
|
|
40
|
+
Name: metric.name,
|
|
41
|
+
Unit: metric.unit ?? 'None',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
// Dimension values (must be at root level)
|
|
48
|
+
...dimensions,
|
|
49
|
+
// Metric value (must be at root level with same name)
|
|
50
|
+
[metric.name]: metric.value,
|
|
51
|
+
// Additional properties
|
|
52
|
+
...properties,
|
|
53
|
+
};
|
|
54
|
+
// Log at info level - CloudWatch will extract the metric
|
|
55
|
+
logger_1.logger.info(emfLog, `metric: ${metric.name}`);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Emit multiple metrics in a single EMF log event.
|
|
59
|
+
* All metrics share the same dimensions.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* emitMetrics(
|
|
64
|
+
* [
|
|
65
|
+
* { name: 'execution.duration', unit: 'Seconds', value: 1.5 },
|
|
66
|
+
* { name: 'execution.payload_size', unit: 'Bytes', value: 2048 },
|
|
67
|
+
* ],
|
|
68
|
+
* { workflowId: 'wf_123', triggerType: 'http' }
|
|
69
|
+
* );
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
function emitMetrics(metrics, dimensions, options = {}) {
|
|
73
|
+
const { namespace = DEFAULT_NAMESPACE, dimensionKeys, properties = {} } = options;
|
|
74
|
+
const dimKeys = dimensionKeys ?? Object.keys(dimensions);
|
|
75
|
+
const metricValues = {};
|
|
76
|
+
const metricDefinitions = metrics.map((m) => {
|
|
77
|
+
metricValues[m.name] = m.value;
|
|
78
|
+
return {
|
|
79
|
+
Name: m.name,
|
|
80
|
+
Unit: m.unit ?? 'None',
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
const emfLog = {
|
|
84
|
+
_aws: {
|
|
85
|
+
Timestamp: Date.now(),
|
|
86
|
+
CloudWatchMetrics: [
|
|
87
|
+
{
|
|
88
|
+
Namespace: namespace,
|
|
89
|
+
Dimensions: [dimKeys],
|
|
90
|
+
Metrics: metricDefinitions,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
...dimensions,
|
|
95
|
+
...metricValues,
|
|
96
|
+
...properties,
|
|
97
|
+
};
|
|
98
|
+
const metricNames = metrics.map((m) => m.name).join(', ');
|
|
99
|
+
logger_1.logger.info(emfLog, `metrics: ${metricNames}`);
|
|
100
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,15 @@
|
|
|
5
5
|
* Provides consistent, well-typed logging across different operational contexts.
|
|
6
6
|
*/
|
|
7
7
|
export type { LogLevel, LogType, HttpMethod, Maybe, EventSource, Log, HttpPayload, SftpPayload, EdiPayload, EdiOperation, EdiFormat, EdiX12Payload, EdiX12Operation, } from './types';
|
|
8
|
+
export { defaultTraceHeaderKey, defaultMessageHeaderKey } from './types';
|
|
8
9
|
export type { ILogger, UnnboundLogger } from './logger';
|
|
9
10
|
export { logger } from './logger';
|
|
10
11
|
export { encode, decode } from './encode';
|
|
11
12
|
export { withTrace, getTraceId } from './trace';
|
|
12
13
|
export { startSpan } from './span';
|
|
13
|
-
export { traceAxios } from './axios';
|
|
14
|
+
export { traceAxios, type OnRequest } from './axios';
|
|
14
15
|
export { traceMiddleware } from './middleware';
|
|
16
|
+
export { storage, withStorage } from './storage';
|
|
17
|
+
export type { UnnboundContext } from './storage';
|
|
18
|
+
export type { MetricUnit, MetricDefinition, EmitMetricOptions } from './emf';
|
|
19
|
+
export { emitMetric, emitMetrics } from './emf';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traceMiddleware = exports.traceAxios = exports.startSpan = exports.getTraceId = exports.withTrace = exports.decode = exports.encode = exports.logger = void 0;
|
|
3
|
+
exports.emitMetrics = exports.emitMetric = exports.withStorage = exports.storage = exports.traceMiddleware = exports.traceAxios = exports.startSpan = exports.getTraceId = exports.withTrace = exports.decode = exports.encode = exports.logger = exports.defaultMessageHeaderKey = exports.defaultTraceHeaderKey = void 0;
|
|
4
|
+
var types_1 = require("./types");
|
|
5
|
+
Object.defineProperty(exports, "defaultTraceHeaderKey", { enumerable: true, get: function () { return types_1.defaultTraceHeaderKey; } });
|
|
6
|
+
Object.defineProperty(exports, "defaultMessageHeaderKey", { enumerable: true, get: function () { return types_1.defaultMessageHeaderKey; } });
|
|
4
7
|
var logger_1 = require("./logger");
|
|
5
8
|
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
6
9
|
var encode_1 = require("./encode");
|
|
@@ -15,3 +18,9 @@ var axios_1 = require("./axios");
|
|
|
15
18
|
Object.defineProperty(exports, "traceAxios", { enumerable: true, get: function () { return axios_1.traceAxios; } });
|
|
16
19
|
var middleware_1 = require("./middleware");
|
|
17
20
|
Object.defineProperty(exports, "traceMiddleware", { enumerable: true, get: function () { return middleware_1.traceMiddleware; } });
|
|
21
|
+
var storage_1 = require("./storage");
|
|
22
|
+
Object.defineProperty(exports, "storage", { enumerable: true, get: function () { return storage_1.storage; } });
|
|
23
|
+
Object.defineProperty(exports, "withStorage", { enumerable: true, get: function () { return storage_1.withStorage; } });
|
|
24
|
+
var emf_1 = require("./emf");
|
|
25
|
+
Object.defineProperty(exports, "emitMetric", { enumerable: true, get: function () { return emf_1.emitMetric; } });
|
|
26
|
+
Object.defineProperty(exports, "emitMetrics", { enumerable: true, get: function () { return emf_1.emitMetrics; } });
|
package/dist/internal.d.ts
CHANGED
package/dist/internal.js
CHANGED
package/dist/logger.js
CHANGED
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.logger = void 0;
|
|
7
7
|
const pino_1 = __importDefault(require("pino"));
|
|
8
8
|
const uuid_1 = require("uuid");
|
|
9
|
-
const storage_1 = require("./storage");
|
|
10
9
|
const encode_1 = require("./encode");
|
|
11
10
|
const internal_1 = require("./internal");
|
|
11
|
+
const storage_1 = require("./storage");
|
|
12
12
|
const levels = new Set(['debug', 'info', 'warn', 'error']);
|
|
13
13
|
const formatLevel = (level) => ({ level });
|
|
14
14
|
// TODO: Check if there is a better way to encode the log object.
|
|
@@ -24,7 +24,7 @@ const formatLog = (log, visited = new WeakSet()) => {
|
|
|
24
24
|
for (const key in log) {
|
|
25
25
|
const value = log[key];
|
|
26
26
|
// We don't want to encode undefined values.
|
|
27
|
-
if (value
|
|
27
|
+
if (value === undefined)
|
|
28
28
|
continue;
|
|
29
29
|
// We can't encode immutable properties.
|
|
30
30
|
if (!Object.getOwnPropertyDescriptor(log, key)?.writable)
|
|
@@ -52,6 +52,7 @@ exports.logger = (0, pino_1.default)({
|
|
|
52
52
|
workflowId: process.env.UNNBOUND_WORKFLOW_ID,
|
|
53
53
|
serviceId: process.env.UNNBOUND_SERVICE_ID,
|
|
54
54
|
deploymentId: process.env.UNNBOUND_DEPLOYMENT_ID,
|
|
55
|
+
source: process.env.UNNBOUND_LOG_SOURCE ?? 'workflow',
|
|
55
56
|
},
|
|
56
57
|
mixin: () => ({ ...storage_1.storage.getStore(), logId: (0, uuid_1.v4)() }),
|
|
57
58
|
serializers: {
|
|
@@ -73,9 +74,7 @@ exports.logger = (0, pino_1.default)({
|
|
|
73
74
|
if ((0, internal_1.hidden)(firstArg))
|
|
74
75
|
return;
|
|
75
76
|
// Dynamic log level by allowing overwriting the log level
|
|
76
|
-
if ('level' in firstArg &&
|
|
77
|
-
typeof firstArg.level === 'string' &&
|
|
78
|
-
levels.has(firstArg.level)) {
|
|
77
|
+
if ('level' in firstArg && typeof firstArg.level === 'string' && levels.has(firstArg.level)) {
|
|
79
78
|
method = this[firstArg.level];
|
|
80
79
|
firstArg.level = undefined;
|
|
81
80
|
}
|
|
@@ -96,7 +95,7 @@ exports.logger = (0, pino_1.default)({
|
|
|
96
95
|
});
|
|
97
96
|
process.on('uncaughtException', (err, origin) => {
|
|
98
97
|
try {
|
|
99
|
-
exports.logger.error({ err, origin },
|
|
98
|
+
exports.logger.error({ err, origin }, 'Uncaught exception.');
|
|
100
99
|
}
|
|
101
100
|
catch {
|
|
102
101
|
// noop
|
|
@@ -104,7 +103,7 @@ process.on('uncaughtException', (err, origin) => {
|
|
|
104
103
|
});
|
|
105
104
|
process.on('unhandledRejection', (err, origin) => {
|
|
106
105
|
try {
|
|
107
|
-
exports.logger.error({ err, origin },
|
|
106
|
+
exports.logger.error({ err, origin }, 'Unhandled rejection.');
|
|
108
107
|
}
|
|
109
108
|
catch {
|
|
110
109
|
// noop
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Request, RequestHandler } from 'express';
|
|
2
|
-
import { HttpOptions } from './types';
|
|
1
|
+
import type { Request, RequestHandler } from 'express';
|
|
2
|
+
import { type HttpOptions } from './types';
|
|
3
3
|
interface Response {
|
|
4
4
|
status: number;
|
|
5
5
|
headers?: Record<string, string | undefined>;
|
package/dist/middleware.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.traceMiddleware = void 0;
|
|
4
4
|
const span_1 = require("./span");
|
|
5
5
|
const types_1 = require("./types");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
6
|
const trace_1 = require("./trace");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
8
|
const extractQueryParams = (url) => {
|
|
9
9
|
const object = new URL(url);
|
|
10
10
|
const query = Object.fromEntries(object.searchParams.entries());
|
|
@@ -18,8 +18,9 @@ const getFullUrl = (req) => {
|
|
|
18
18
|
return url;
|
|
19
19
|
// Check if we have a workflow URL configured (preferred method)
|
|
20
20
|
if (process.env.UNNBOUND_WORKFLOW_URL) {
|
|
21
|
-
// Use workflow URL as the base URL
|
|
22
|
-
|
|
21
|
+
// Use workflow URL as the base URL (strip any existing protocol to avoid duplication)
|
|
22
|
+
const workflowUrl = process.env.UNNBOUND_WORKFLOW_URL.replace(/^https?:\/\//, '').replace(/\/$/, '');
|
|
23
|
+
return `https://${workflowUrl}${url}`;
|
|
23
24
|
}
|
|
24
25
|
// Fallback to constructing from request info for incoming requests
|
|
25
26
|
const protocol = req.protocol || (req.secure ? 'https' : 'http');
|
package/dist/span.d.ts
CHANGED
package/dist/span.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.startSpan = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
|
+
const logger_1 = require("./logger");
|
|
5
6
|
const storage_1 = require("./storage");
|
|
6
7
|
const trace_1 = require("./trace");
|
|
7
|
-
const logger_1 = require("./logger");
|
|
8
8
|
/**
|
|
9
9
|
* Starts a span that tracks the duration of a callback
|
|
10
10
|
* @param spanName - The span name to use for logging
|
package/dist/storage.d.ts
CHANGED
package/dist/storage.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withStorage = exports.storage = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.storage = new
|
|
4
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
|
+
exports.storage = new node_async_hooks_1.AsyncLocalStorage();
|
|
6
6
|
const withStorage = async (data, callback) => {
|
|
7
7
|
const previous = exports.storage.getStore();
|
|
8
8
|
return exports.storage.run({ ...previous, ...data }, callback);
|
package/dist/trace.d.ts
CHANGED
package/dist/trace.js
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unnbound-logger-sdk",
|
|
3
3
|
"description": "A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.35",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "bun x tsc",
|
|
9
|
+
"test": "echo 'No tests'",
|
|
10
|
+
"typecheck": "tsc -noEmit",
|
|
11
|
+
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
|
|
12
|
+
"lint:fix": "bun run lint --fix",
|
|
13
|
+
"format": "biome format --write .",
|
|
14
|
+
"format:check": "biome format .",
|
|
15
|
+
"prepublishOnly": "bun run build",
|
|
16
|
+
"start:example": "bun --watch examples/node-express.ts",
|
|
17
|
+
"version:bump": "npm version patch"
|
|
18
|
+
},
|
|
7
19
|
"keywords": [
|
|
8
20
|
"logging",
|
|
9
21
|
"typescript",
|
|
@@ -33,9 +45,9 @@
|
|
|
33
45
|
},
|
|
34
46
|
"devDependencies": {
|
|
35
47
|
"@types/express": "^4.17.21",
|
|
36
|
-
"@types/jest": "^29.5.12",
|
|
37
48
|
"@types/node": "^22",
|
|
38
|
-
"@types/uuid": "^9.0.8"
|
|
49
|
+
"@types/uuid": "^9.0.8",
|
|
50
|
+
"typescript": "^5.9.3"
|
|
39
51
|
},
|
|
40
52
|
"peerDependencies": {
|
|
41
53
|
"axios": "^1.12.2",
|
|
@@ -57,18 +69,5 @@
|
|
|
57
69
|
"engines": {
|
|
58
70
|
"node": ">=22"
|
|
59
71
|
},
|
|
60
|
-
"sideEffects": false
|
|
61
|
-
|
|
62
|
-
"build": "tsc",
|
|
63
|
-
"test": "jest",
|
|
64
|
-
"test:coverage": "jest --coverage",
|
|
65
|
-
"test:watch": "jest --watch",
|
|
66
|
-
"typecheck": "tsc -noEmit",
|
|
67
|
-
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
|
|
68
|
-
"lint:fix": "pnpm lint --fix",
|
|
69
|
-
"format": "prettier --write .",
|
|
70
|
-
"format:check": "prettier --check .",
|
|
71
|
-
"start:example": "npx --yes tsx --watch examples/node-express.ts",
|
|
72
|
-
"version:bump": "npm version patch"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
72
|
+
"sideEffects": false
|
|
73
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Unnbound Team
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|