@brizz/sdk 0.1.9 → 0.1.11
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/README.md +15 -10
- package/dist/index.cjs +61 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +61 -13
- package/dist/index.js.map +1 -1
- package/dist/preload.cjs +45 -9
- package/dist/preload.cjs.map +1 -1
- package/dist/preload.js +45 -9
- package/dist/preload.js.map +1 -1
- package/package.json +37 -37
package/dist/index.d.cts
CHANGED
|
@@ -122,7 +122,7 @@ declare function callWithProperties<A extends unknown[], F extends (...args: A)
|
|
|
122
122
|
declare function withProperties<F extends (this: any, ...args: any[]) => any>(properties: {
|
|
123
123
|
[name: string]: string;
|
|
124
124
|
}, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
125
|
-
declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
125
|
+
declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, extraProperties?: Record<string, string>): F;
|
|
126
126
|
declare function callWithSessionId<A extends unknown[], F extends (...args: A) => ReturnType<F>>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
|
127
127
|
declare class Session {
|
|
128
128
|
readonly sessionId: string;
|
|
@@ -134,7 +134,7 @@ declare class Session {
|
|
|
134
134
|
setOutput(text: string): void;
|
|
135
135
|
updateProperties(properties: Record<string, AttributeValue>): void;
|
|
136
136
|
}
|
|
137
|
-
declare function startSession<T>(sessionId: string, callback: (session: Session) => T): T;
|
|
137
|
+
declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>): T;
|
|
138
138
|
|
|
139
139
|
declare function getMetricsExporter(): OTLPMetricExporter;
|
|
140
140
|
declare function getMetricsReader(): MetricReader;
|
package/dist/index.d.ts
CHANGED
|
@@ -122,7 +122,7 @@ declare function callWithProperties<A extends unknown[], F extends (...args: A)
|
|
|
122
122
|
declare function withProperties<F extends (this: any, ...args: any[]) => any>(properties: {
|
|
123
123
|
[name: string]: string;
|
|
124
124
|
}, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
125
|
-
declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
125
|
+
declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, extraProperties?: Record<string, string>): F;
|
|
126
126
|
declare function callWithSessionId<A extends unknown[], F extends (...args: A) => ReturnType<F>>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
|
127
127
|
declare class Session {
|
|
128
128
|
readonly sessionId: string;
|
|
@@ -134,7 +134,7 @@ declare class Session {
|
|
|
134
134
|
setOutput(text: string): void;
|
|
135
135
|
updateProperties(properties: Record<string, AttributeValue>): void;
|
|
136
136
|
}
|
|
137
|
-
declare function startSession<T>(sessionId: string, callback: (session: Session) => T): T;
|
|
137
|
+
declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>): T;
|
|
138
138
|
|
|
139
139
|
declare function getMetricsExporter(): OTLPMetricExporter;
|
|
140
140
|
declare function getMetricsReader(): MetricReader;
|
package/dist/index.js
CHANGED
|
@@ -230,7 +230,7 @@ function autoInitializeInstrumentations() {
|
|
|
230
230
|
autoInitializeInstrumentations();
|
|
231
231
|
|
|
232
232
|
// src/internal/sdk.ts
|
|
233
|
-
import { resourceFromAttributes as
|
|
233
|
+
import { resourceFromAttributes as resourceFromAttributes3 } from "@opentelemetry/resources";
|
|
234
234
|
import { NodeSDK } from "@opentelemetry/sdk-node";
|
|
235
235
|
|
|
236
236
|
// src/internal/config.ts
|
|
@@ -296,7 +296,7 @@ function resolveConfig(options) {
|
|
|
296
296
|
});
|
|
297
297
|
} catch (error) {
|
|
298
298
|
logger.error("Failed to parse BRIZZ_HEADERS environment variable", { error });
|
|
299
|
-
throw new Error("Invalid JSON in BRIZZ_HEADERS environment variable");
|
|
299
|
+
throw new Error("Invalid JSON in BRIZZ_HEADERS environment variable", { cause: error });
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
logger.debug("Configuration resolved with environment variables", {
|
|
@@ -434,7 +434,7 @@ import {
|
|
|
434
434
|
|
|
435
435
|
// src/internal/version.ts
|
|
436
436
|
function getSDKVersion() {
|
|
437
|
-
return "0.1.
|
|
437
|
+
return "0.1.11";
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
// src/internal/log/processors/log-processor.ts
|
|
@@ -880,7 +880,9 @@ function getGroupedPattern(patternEntry) {
|
|
|
880
880
|
try {
|
|
881
881
|
new RegExp(patternEntry.pattern);
|
|
882
882
|
} catch (error) {
|
|
883
|
-
throw new Error(`Invalid regex pattern '${patternEntry.pattern}': ${String(error)}
|
|
883
|
+
throw new Error(`Invalid regex pattern '${patternEntry.pattern}': ${String(error)}`, {
|
|
884
|
+
cause: error
|
|
885
|
+
});
|
|
884
886
|
}
|
|
885
887
|
return `(?<${name}>${patternEntry.pattern})`;
|
|
886
888
|
}
|
|
@@ -1430,7 +1432,40 @@ function getMetricsReader() {
|
|
|
1430
1432
|
}
|
|
1431
1433
|
|
|
1432
1434
|
// src/internal/trace/tracing.ts
|
|
1433
|
-
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-
|
|
1435
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
1436
|
+
|
|
1437
|
+
// src/internal/trace/exporters/span-exporter.ts
|
|
1438
|
+
import { resourceFromAttributes as resourceFromAttributes2 } from "@opentelemetry/resources";
|
|
1439
|
+
var BrizzSpanExporter = class {
|
|
1440
|
+
_delegate;
|
|
1441
|
+
_brizzResource;
|
|
1442
|
+
constructor(delegate, config) {
|
|
1443
|
+
this._delegate = delegate;
|
|
1444
|
+
const resourceAttrs = {
|
|
1445
|
+
"service.name": config.appName,
|
|
1446
|
+
[BRIZZ_SDK_VERSION]: getSDKVersion(),
|
|
1447
|
+
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
1448
|
+
};
|
|
1449
|
+
if (config.environment) {
|
|
1450
|
+
resourceAttrs["deployment.environment"] = config.environment;
|
|
1451
|
+
}
|
|
1452
|
+
this._brizzResource = resourceFromAttributes2(resourceAttrs);
|
|
1453
|
+
}
|
|
1454
|
+
export(spans, resultCallback) {
|
|
1455
|
+
const patchedSpans = spans.map((span) => ({
|
|
1456
|
+
...span,
|
|
1457
|
+
resource: span.resource.merge(this._brizzResource),
|
|
1458
|
+
spanContext: span.spanContext.bind(span)
|
|
1459
|
+
}));
|
|
1460
|
+
this._delegate.export(patchedSpans, resultCallback);
|
|
1461
|
+
}
|
|
1462
|
+
async shutdown() {
|
|
1463
|
+
return this._delegate.shutdown();
|
|
1464
|
+
}
|
|
1465
|
+
async forceFlush() {
|
|
1466
|
+
return this._delegate.forceFlush?.();
|
|
1467
|
+
}
|
|
1468
|
+
};
|
|
1434
1469
|
|
|
1435
1470
|
// src/internal/trace/processors/span-processor.ts
|
|
1436
1471
|
import { context as context2 } from "@opentelemetry/api";
|
|
@@ -1560,16 +1595,17 @@ var TracingModule = class _TracingModule {
|
|
|
1560
1595
|
}
|
|
1561
1596
|
if (config.customSpanExporter) {
|
|
1562
1597
|
logger.debug("Using custom span exporter");
|
|
1563
|
-
this.spanExporter = config.customSpanExporter;
|
|
1598
|
+
this.spanExporter = new BrizzSpanExporter(config.customSpanExporter, config);
|
|
1564
1599
|
logger.debug("Custom span exporter initialized successfully");
|
|
1565
1600
|
return;
|
|
1566
1601
|
}
|
|
1567
1602
|
const tracesUrl = config.baseUrl.replace(/\/$/, "") + "/v1/traces";
|
|
1568
1603
|
logger.debug("Initializing default OTLP span exporter", { url: tracesUrl });
|
|
1569
|
-
|
|
1604
|
+
const otlpExporter = new OTLPTraceExporter({
|
|
1570
1605
|
url: tracesUrl,
|
|
1571
1606
|
headers: config.headers
|
|
1572
1607
|
});
|
|
1608
|
+
this.spanExporter = new BrizzSpanExporter(otlpExporter, config);
|
|
1573
1609
|
logger.debug("OTLP span exporter initialized successfully");
|
|
1574
1610
|
}
|
|
1575
1611
|
/**
|
|
@@ -1649,8 +1685,9 @@ function withProperties(properties, fn, thisArg) {
|
|
|
1649
1685
|
);
|
|
1650
1686
|
};
|
|
1651
1687
|
}
|
|
1652
|
-
function withSessionId(sessionId, fn, thisArg) {
|
|
1653
|
-
|
|
1688
|
+
function withSessionId(sessionId, fn, thisArg, extraProperties) {
|
|
1689
|
+
const properties = { [SESSION_ID]: sessionId, ...extraProperties };
|
|
1690
|
+
return withProperties(properties, fn, thisArg);
|
|
1654
1691
|
}
|
|
1655
1692
|
function callWithSessionId(sessionId, fn, thisArg, ...args) {
|
|
1656
1693
|
return callWithProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
|
|
@@ -1698,12 +1735,23 @@ var Session = class {
|
|
|
1698
1735
|
}
|
|
1699
1736
|
}
|
|
1700
1737
|
};
|
|
1701
|
-
function startSession(sessionId, callback) {
|
|
1738
|
+
function startSession(sessionId, callback, extraProperties) {
|
|
1702
1739
|
const tracer = trace.getTracer("@brizz/sdk");
|
|
1703
1740
|
return tracer.startActiveSpan(SESSION_SPAN_NAME, (span) => {
|
|
1704
1741
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
1742
|
+
if (extraProperties) {
|
|
1743
|
+
for (const [key, value] of Object.entries(extraProperties)) {
|
|
1744
|
+
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1705
1747
|
const session = new Session(sessionId, span);
|
|
1706
|
-
|
|
1748
|
+
const contextProperties = { [SESSION_ID]: sessionId };
|
|
1749
|
+
if (extraProperties) {
|
|
1750
|
+
for (const [key, value] of Object.entries(extraProperties)) {
|
|
1751
|
+
contextProperties[key] = String(value);
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
return callWithProperties(contextProperties, () => {
|
|
1707
1755
|
try {
|
|
1708
1756
|
const result = callback(session);
|
|
1709
1757
|
if (result && typeof result.then === "function") {
|
|
@@ -1774,7 +1822,7 @@ var _Brizz = class __Brizz {
|
|
|
1774
1822
|
});
|
|
1775
1823
|
} catch (error) {
|
|
1776
1824
|
logger.error("Failed to initialize Brizz SDK", { error });
|
|
1777
|
-
throw new Error(`Failed to initialize SDK: ${String(error)}
|
|
1825
|
+
throw new Error(`Failed to initialize SDK: ${String(error)}`, { cause: error });
|
|
1778
1826
|
}
|
|
1779
1827
|
}
|
|
1780
1828
|
/**
|
|
@@ -1810,7 +1858,7 @@ var _Brizz = class __Brizz {
|
|
|
1810
1858
|
this._sdk = new NodeSDK({
|
|
1811
1859
|
spanProcessors: [getSpanProcessor()],
|
|
1812
1860
|
metricReader: getMetricsReader(),
|
|
1813
|
-
resource:
|
|
1861
|
+
resource: resourceFromAttributes3(resourceAttributes),
|
|
1814
1862
|
instrumentations: manualInstrumentations
|
|
1815
1863
|
});
|
|
1816
1864
|
this._sdk.start();
|