@brizz/sdk 0.1.5 → 0.1.7

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);
@@ -360,6 +362,11 @@ function resolveConfig(options) {
360
362
  return resolvedConfig;
361
363
  }
362
364
 
365
+ // src/internal/constants.ts
366
+ var BRIZZ_SDK_VERSION = "brizz.sdk.version";
367
+ var BRIZZ_SDK_LANGUAGE = "brizz.sdk.language";
368
+ var SDK_LANGUAGE = "typescript";
369
+
363
370
  // src/internal/instrumentation/registry.ts
364
371
  var import_instrumentation_anthropic2 = require("@traceloop/instrumentation-anthropic");
365
372
  var import_instrumentation_bedrock2 = require("@traceloop/instrumentation-bedrock");
@@ -471,6 +478,11 @@ var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-
471
478
  var import_resources = require("@opentelemetry/resources");
472
479
  var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
473
480
 
481
+ // src/internal/version.ts
482
+ function getSDKVersion() {
483
+ return "0.1.7";
484
+ }
485
+
474
486
  // src/internal/log/processors/log-processor.ts
475
487
  var import_api3 = require("@opentelemetry/api");
476
488
  var import_sdk_logs = require("@opentelemetry/sdk-logs");
@@ -1268,7 +1280,9 @@ var LoggingModule = class _LoggingModule {
1268
1280
  serviceName: config.appName
1269
1281
  });
1270
1282
  const resourceAttributes = {
1271
- "service.name": config.appName
1283
+ "service.name": config.appName,
1284
+ [BRIZZ_SDK_VERSION]: getSDKVersion(),
1285
+ [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
1272
1286
  };
1273
1287
  if (config.environment) {
1274
1288
  resourceAttributes["deployment.environment"] = config.environment;
@@ -1658,26 +1672,28 @@ function getSpanProcessor() {
1658
1672
 
1659
1673
  // src/internal/trace/session.ts
1660
1674
  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);
1675
+ function callWithProperties(properties, fn, thisArg, ...args) {
1676
+ const base = import_api5.context.active();
1677
+ const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
1678
+ const merged = prev ? { ...prev, ...properties } : properties;
1679
+ const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
1680
+ return import_api5.context.with(next, fn, thisArg, ...args);
1667
1681
  }
1668
- function withSessionId(sessionId, fn, thisArg) {
1682
+ function withProperties(properties, fn, thisArg) {
1669
1683
  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 }
1684
+ return callWithProperties(
1685
+ properties,
1686
+ fn,
1687
+ thisArg !== void 0 ? thisArg : this,
1688
+ ...args
1675
1689
  );
1676
- return import_api5.context.with(next, fn, thisArg ?? this, ...args);
1677
1690
  };
1678
1691
  }
1692
+ function withSessionId(sessionId, fn, thisArg) {
1693
+ return withProperties({ [SESSION_ID]: sessionId }, fn, thisArg);
1694
+ }
1679
1695
  function callWithSessionId(sessionId, fn, thisArg, ...args) {
1680
- return withProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
1696
+ return callWithProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
1681
1697
  }
1682
1698
 
1683
1699
  // src/internal/sdk.ts
@@ -1751,7 +1767,9 @@ var _Brizz = class __Brizz {
1751
1767
  const registry = InstrumentationRegistry.getInstance();
1752
1768
  const manualInstrumentations = registry.getManualInstrumentations();
1753
1769
  const resourceAttributes = {
1754
- "service.name": resolvedConfig.appName
1770
+ "service.name": resolvedConfig.appName,
1771
+ [BRIZZ_SDK_VERSION]: getSDKVersion(),
1772
+ [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
1755
1773
  };
1756
1774
  if (resolvedConfig.environment) {
1757
1775
  resourceAttributes["deployment.environment"] = resolvedConfig.environment;
@@ -1928,6 +1946,7 @@ var init_exports = {};
1928
1946
  DEFAULT_PII_PATTERNS,
1929
1947
  LogLevel,
1930
1948
  SeverityNumber,
1949
+ callWithProperties,
1931
1950
  callWithSessionId,
1932
1951
  detectRuntime,
1933
1952
  emitEvent,
@@ -1941,6 +1960,7 @@ var init_exports = {};
1941
1960
  maskAttributes,
1942
1961
  maskValue,
1943
1962
  setLogLevel,
1963
+ withProperties,
1944
1964
  withSessionId
1945
1965
  });
1946
1966
  //# sourceMappingURL=index.cjs.map