@brizz/sdk 0.1.5 → 0.1.6
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 -0
- package/dist/index.cjs +20 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +18 -14
- package/dist/index.js.map +1 -1
- package/dist/preload.cjs.map +1 -1
- package/dist/preload.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -292,6 +292,21 @@ import { callWithSessionId } from '@brizz/sdk';
|
|
|
292
292
|
await callWithSessionId('session-123', processUserWorkflow, null, 'user-456');
|
|
293
293
|
```
|
|
294
294
|
|
|
295
|
+
### Custom Properties
|
|
296
|
+
|
|
297
|
+
Add custom properties to telemetry context:
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
import { withProperties, callWithProperties } from '@brizz/sdk';
|
|
301
|
+
|
|
302
|
+
// Wrapper pattern - properties applied to all calls
|
|
303
|
+
const taggedFn = withProperties({ env: 'prod', feature: 'chat' }, myFunction);
|
|
304
|
+
await taggedFn(args);
|
|
305
|
+
|
|
306
|
+
// Immediate execution - properties applied once
|
|
307
|
+
await callWithProperties({ userId: 'user-123' }, myFunction, null, args);
|
|
308
|
+
```
|
|
309
|
+
|
|
295
310
|
### Handling Method Context
|
|
296
311
|
|
|
297
312
|
When wrapping methods that use `this`, you have several options:
|
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
DEFAULT_PII_PATTERNS: () => DEFAULT_PII_PATTERNS,
|
|
35
35
|
LogLevel: () => LogLevel,
|
|
36
36
|
SeverityNumber: () => import_api_logs2.SeverityNumber,
|
|
37
|
+
callWithProperties: () => callWithProperties,
|
|
37
38
|
callWithSessionId: () => callWithSessionId,
|
|
38
39
|
detectRuntime: () => detectRuntime,
|
|
39
40
|
emitEvent: () => emitEvent,
|
|
@@ -47,6 +48,7 @@ __export(src_exports, {
|
|
|
47
48
|
maskAttributes: () => maskAttributes,
|
|
48
49
|
maskValue: () => maskValue,
|
|
49
50
|
setLogLevel: () => setLogLevel,
|
|
51
|
+
withProperties: () => withProperties,
|
|
50
52
|
withSessionId: () => withSessionId
|
|
51
53
|
});
|
|
52
54
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -1658,26 +1660,28 @@ function getSpanProcessor() {
|
|
|
1658
1660
|
|
|
1659
1661
|
// src/internal/trace/session.ts
|
|
1660
1662
|
var import_api5 = require("@opentelemetry/api");
|
|
1661
|
-
function
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
}
|
|
1665
|
-
const
|
|
1666
|
-
return import_api5.context.with(
|
|
1663
|
+
function callWithProperties(properties, fn, thisArg, ...args) {
|
|
1664
|
+
const base = import_api5.context.active();
|
|
1665
|
+
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
1666
|
+
const merged = prev ? { ...prev, ...properties } : properties;
|
|
1667
|
+
const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
|
|
1668
|
+
return import_api5.context.with(next, fn, thisArg, ...args);
|
|
1667
1669
|
}
|
|
1668
|
-
function
|
|
1670
|
+
function withProperties(properties, fn, thisArg) {
|
|
1669
1671
|
return function wrapped(...args) {
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1672
|
+
return callWithProperties(
|
|
1673
|
+
properties,
|
|
1674
|
+
fn,
|
|
1675
|
+
thisArg !== void 0 ? thisArg : this,
|
|
1676
|
+
...args
|
|
1675
1677
|
);
|
|
1676
|
-
return import_api5.context.with(next, fn, thisArg ?? this, ...args);
|
|
1677
1678
|
};
|
|
1678
1679
|
}
|
|
1680
|
+
function withSessionId(sessionId, fn, thisArg) {
|
|
1681
|
+
return withProperties({ [SESSION_ID]: sessionId }, fn, thisArg);
|
|
1682
|
+
}
|
|
1679
1683
|
function callWithSessionId(sessionId, fn, thisArg, ...args) {
|
|
1680
|
-
return
|
|
1684
|
+
return callWithProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
|
|
1681
1685
|
}
|
|
1682
1686
|
|
|
1683
1687
|
// src/internal/sdk.ts
|
|
@@ -1928,6 +1932,7 @@ var init_exports = {};
|
|
|
1928
1932
|
DEFAULT_PII_PATTERNS,
|
|
1929
1933
|
LogLevel,
|
|
1930
1934
|
SeverityNumber,
|
|
1935
|
+
callWithProperties,
|
|
1931
1936
|
callWithSessionId,
|
|
1932
1937
|
detectRuntime,
|
|
1933
1938
|
emitEvent,
|
|
@@ -1941,6 +1946,7 @@ var init_exports = {};
|
|
|
1941
1946
|
maskAttributes,
|
|
1942
1947
|
maskValue,
|
|
1943
1948
|
setLogLevel,
|
|
1949
|
+
withProperties,
|
|
1944
1950
|
withSessionId
|
|
1945
1951
|
});
|
|
1946
1952
|
//# sourceMappingURL=index.cjs.map
|