@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 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 withProperties(properties, fn, thisArg, ...args) {
1662
- if (Object.keys(properties).length === 0) {
1663
- return fn.apply(thisArg, args);
1664
- }
1665
- const newContext = import_api5.context.active().setValue(PROPERTIES_CONTEXT_KEY, properties);
1666
- return import_api5.context.with(newContext, fn, thisArg, ...args);
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 withSessionId(sessionId, fn, thisArg) {
1670
+ function withProperties(properties, fn, thisArg) {
1669
1671
  return function wrapped(...args) {
1670
- const base = import_api5.context.active();
1671
- const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
1672
- const next = base.setValue(
1673
- PROPERTIES_CONTEXT_KEY,
1674
- prev ? { ...prev, [SESSION_ID]: sessionId } : { [SESSION_ID]: sessionId }
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 withProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
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