@brizz/sdk 0.1.27 → 0.1.28

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/index.js CHANGED
@@ -290,7 +290,7 @@ var init_schemas = __esm({
290
290
 
291
291
  // src/internal/semantic-conventions.ts
292
292
  import { createContextKey } from "@opentelemetry/api";
293
- var BRIZZ, PROPERTIES, SESSION_ID, PROPERTIES_CONTEXT_KEY, SESSION_OBJECT_CONTEXT_KEY, SESSION_INPUT, SESSION_OUTPUT, SESSION_INPUT_CONTEXT, SESSION_OUTPUT_CONTEXT, SESSION_SPAN_NAME, SESSION_TITLE_SPAN_NAME, SESSION_TITLE_GENERATION, SESSION_TITLE, INTERRUPT_TOOLS;
293
+ var BRIZZ, PROPERTIES, SESSION_ID, PROPERTIES_CONTEXT_KEY, SESSION_OBJECT_CONTEXT_KEY, SESSION_INPUT, SESSION_OUTPUT, SESSION_INPUT_CONTEXT, SESSION_OUTPUT_CONTEXT, SESSION_SPAN_NAME, MUTE_INPUT, MUTE_OUTPUT, SESSION_TITLE_SPAN_NAME, SESSION_TITLE_GENERATION, SESSION_TITLE, INTERRUPT_TOOLS, INTERNAL_EVENT_PREFIX, EXTERNAL_LINK_EVENT_NAME, EXTERNAL_LINK_URL, EXTERNAL_LINK_TITLE, EXTERNAL_LINK_TYPE;
294
294
  var init_semantic_conventions2 = __esm({
295
295
  "src/internal/semantic-conventions.ts"() {
296
296
  "use strict";
@@ -304,10 +304,17 @@ var init_semantic_conventions2 = __esm({
304
304
  SESSION_INPUT_CONTEXT = "brizz.session.input.context";
305
305
  SESSION_OUTPUT_CONTEXT = "brizz.session.output.context";
306
306
  SESSION_SPAN_NAME = "brizz.start_session";
307
+ MUTE_INPUT = "mute.input";
308
+ MUTE_OUTPUT = "mute.output";
307
309
  SESSION_TITLE_SPAN_NAME = "brizz.session_title";
308
310
  SESSION_TITLE_GENERATION = "session.title_generation";
309
311
  SESSION_TITLE = "brizz.session.title";
310
312
  INTERRUPT_TOOLS = "brizz.internal.interrupt";
313
+ INTERNAL_EVENT_PREFIX = "brizz.internal.";
314
+ EXTERNAL_LINK_EVENT_NAME = "brizz.internal.external_link";
315
+ EXTERNAL_LINK_URL = "brizz.internal.external_link.url";
316
+ EXTERNAL_LINK_TITLE = "brizz.internal.external_link.title";
317
+ EXTERNAL_LINK_TYPE = "brizz.internal.external_link.type";
311
318
  }
312
319
  });
313
320
 
@@ -773,7 +780,7 @@ var init_protocol = __esm({
773
780
 
774
781
  // src/internal/version.ts
775
782
  function getSDKVersion() {
776
- return "0.1.27";
783
+ return "0.1.28";
777
784
  }
778
785
  var init_version = __esm({
779
786
  "src/internal/version.ts"() {
@@ -1483,11 +1490,283 @@ import {
1483
1490
  LoggerProvider
1484
1491
  } from "@opentelemetry/sdk-logs";
1485
1492
  init_logger();
1493
+
1494
+ // src/internal/trace/session.ts
1495
+ import { context as context3, trace as trace4, SpanStatusCode as SpanStatusCode3 } from "@opentelemetry/api";
1496
+ init_logger();
1497
+ init_semantic_conventions2();
1498
+ function setCurrentSpanCustomProperties(properties) {
1499
+ const current = trace4.getActiveSpan();
1500
+ if (!current || !current.isRecording()) {
1501
+ return;
1502
+ }
1503
+ for (const [key, value] of Object.entries(properties)) {
1504
+ try {
1505
+ current.setAttribute(`${BRIZZ}.${key}`, value);
1506
+ } catch {
1507
+ }
1508
+ }
1509
+ }
1510
+ function callWithProperties(properties, fn, thisArg, ...args) {
1511
+ const base = context3.active();
1512
+ const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
1513
+ const merged = prev ? { ...prev, ...properties } : properties;
1514
+ const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
1515
+ return context3.with(next, fn, thisArg, ...args);
1516
+ }
1517
+ function withProperties(properties, fn, thisArg) {
1518
+ return function wrapped(...args) {
1519
+ return callWithProperties(
1520
+ properties,
1521
+ fn,
1522
+ thisArg !== void 0 ? thisArg : this,
1523
+ ...args
1524
+ );
1525
+ };
1526
+ }
1527
+ function muteProperties(options) {
1528
+ const { input = true, output = true } = options;
1529
+ const properties = {};
1530
+ if (input) {
1531
+ properties[MUTE_INPUT] = "true";
1532
+ }
1533
+ if (output) {
1534
+ properties[MUTE_OUTPUT] = "true";
1535
+ }
1536
+ return properties;
1537
+ }
1538
+ function callWithMute(options, fn, thisArg, ...args) {
1539
+ return callWithProperties(muteProperties(options), fn, thisArg, ...args);
1540
+ }
1541
+ function withMute(options, fn, thisArg) {
1542
+ return withProperties(muteProperties(options), fn, thisArg);
1543
+ }
1544
+ function withSessionId(sessionId, fn, thisArg, extraProperties) {
1545
+ const properties = { [SESSION_ID]: sessionId, ...extraProperties };
1546
+ return withProperties(properties, fn, thisArg);
1547
+ }
1548
+ function callWithSessionId(sessionId, fn, thisArg, ...args) {
1549
+ return callWithProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
1550
+ }
1551
+ var Session = class {
1552
+ sessionId;
1553
+ span;
1554
+ inputs = [];
1555
+ outputs = [];
1556
+ inputContexts = [];
1557
+ outputContexts = [];
1558
+ constructor(sessionId, span) {
1559
+ this.sessionId = sessionId;
1560
+ this.span = span;
1561
+ }
1562
+ /**
1563
+ * Append a user turn to session input tracking.
1564
+ *
1565
+ * Each call appends one element to `brizz.session.input` (the text) AND one
1566
+ * element to `brizz.session.input.context` (the per-turn context bag). The
1567
+ * two arrays stay index-aligned — the ingestion pipeline zips them together
1568
+ * so the i-th context bag lands on the i-th user_display conversation item's
1569
+ * `span_attributes` map.
1570
+ *
1571
+ * @param text - Text to append (null becomes a null/"hide marker")
1572
+ * @param context - Optional per-turn context bag to attach to this turn
1573
+ */
1574
+ setInput(text, context6) {
1575
+ this.inputs.push(text);
1576
+ this.inputContexts.push(context6 ?? {});
1577
+ this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
1578
+ this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
1579
+ }
1580
+ /**
1581
+ * Append an assistant turn to session output tracking.
1582
+ *
1583
+ * Symmetric to {@link setInput} — appends one text element and one
1584
+ * context-bag element to the index-aligned `brizz.session.output` /
1585
+ * `brizz.session.output.context` arrays.
1586
+ *
1587
+ * @param text - Text to append (null becomes a null/"hide marker")
1588
+ * @param context - Optional per-turn context bag to attach to this turn
1589
+ */
1590
+ setOutput(text, context6) {
1591
+ this.outputs.push(text);
1592
+ this.outputContexts.push(context6 ?? {});
1593
+ this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
1594
+ this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
1595
+ }
1596
+ /**
1597
+ * Set the session title on the span.
1598
+ *
1599
+ * @param title - The generated title string
1600
+ */
1601
+ setTitle(title) {
1602
+ this.span.setAttribute(SESSION_TITLE, title);
1603
+ }
1604
+ /**
1605
+ * Update custom properties on the session span.
1606
+ * Properties are prefixed with 'brizz.'.
1607
+ *
1608
+ * @param properties - Key-value properties to set on the session
1609
+ */
1610
+ updateProperties(properties) {
1611
+ for (const [key, value] of Object.entries(properties)) {
1612
+ this.span.setAttribute(`${BRIZZ}.${key}`, value);
1613
+ }
1614
+ }
1615
+ /**
1616
+ * Attach an external link (URL) to this session.
1617
+ *
1618
+ * The link surfaces on the session's detail panel in Brizz — use it to
1619
+ * correlate a session with an external record such as a Datadog trace,
1620
+ * Sentry issue, or internal dashboard. Re-sending the same URL is idempotent;
1621
+ * distinct URLs add separate links.
1622
+ *
1623
+ * @param url - The link target
1624
+ * @param options - Optional `title` (defaults to the URL host) and `linkType`
1625
+ * (free-form category, defaults to `'generic'`)
1626
+ */
1627
+ addExternalLink(url, options) {
1628
+ emitExternalLink(this.sessionId, url, options?.title, options?.linkType);
1629
+ }
1630
+ };
1631
+ var SessionTitle = class {
1632
+ span;
1633
+ constructor(span) {
1634
+ this.span = span;
1635
+ }
1636
+ /**
1637
+ * Set the generated title on the wrapper span.
1638
+ *
1639
+ * @param title - The generated title string
1640
+ */
1641
+ setTitle(title) {
1642
+ this.span.setAttribute(SESSION_TITLE, title);
1643
+ }
1644
+ };
1645
+ function getActiveSession() {
1646
+ return context3.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
1647
+ }
1648
+ function resolveSessionIdFromContext() {
1649
+ const active = getActiveSession();
1650
+ if (active) {
1651
+ return active.sessionId;
1652
+ }
1653
+ const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
1654
+ return props?.[SESSION_ID];
1655
+ }
1656
+ function emitExternalLink(sessionId, url, title, linkType) {
1657
+ try {
1658
+ emitEventWithSessionId(sessionId, EXTERNAL_LINK_EVENT_NAME, {
1659
+ [EXTERNAL_LINK_URL]: url,
1660
+ [EXTERNAL_LINK_TITLE]: title ?? "",
1661
+ [EXTERNAL_LINK_TYPE]: linkType ?? "generic"
1662
+ });
1663
+ } catch (error) {
1664
+ logger.warn("addExternalLink: failed to emit external link", error);
1665
+ }
1666
+ }
1667
+ function addExternalLink(url, options) {
1668
+ const sessionId = options?.sessionId ?? resolveSessionIdFromContext();
1669
+ if (!sessionId) {
1670
+ logger.warn(
1671
+ "addExternalLink called without a resolvable session id; link dropped. Pass options.sessionId or call inside a startSession/callWithSessionId scope."
1672
+ );
1673
+ return;
1674
+ }
1675
+ emitExternalLink(sessionId, url, options?.title, options?.linkType);
1676
+ }
1677
+ function startSession(sessionId, callback, extraProperties, options) {
1678
+ const isTitle = options?.mode === "title";
1679
+ const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
1680
+ const tracer = trace4.getTracer("@brizz/sdk");
1681
+ return tracer.startActiveSpan(spanName, (span) => {
1682
+ span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
1683
+ if (extraProperties) {
1684
+ for (const [key, value] of Object.entries(extraProperties)) {
1685
+ span.setAttribute(`${BRIZZ}.${key}`, value);
1686
+ }
1687
+ }
1688
+ const session = new Session(sessionId, span);
1689
+ const contextProperties = { [SESSION_ID]: sessionId };
1690
+ if (isTitle) {
1691
+ contextProperties[SESSION_TITLE_GENERATION] = "true";
1692
+ }
1693
+ if (extraProperties) {
1694
+ for (const [key, value] of Object.entries(extraProperties)) {
1695
+ contextProperties[key] = String(value);
1696
+ }
1697
+ }
1698
+ return callWithProperties(contextProperties, () => {
1699
+ const sessionCtx = context3.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
1700
+ return context3.with(sessionCtx, () => {
1701
+ try {
1702
+ const result = callback(session);
1703
+ if (result && typeof result.then === "function") {
1704
+ return result.then((value) => {
1705
+ span.end();
1706
+ return value;
1707
+ }).catch((error) => {
1708
+ span.recordException(error);
1709
+ span.setStatus({ code: SpanStatusCode3.ERROR });
1710
+ span.end();
1711
+ throw error;
1712
+ });
1713
+ }
1714
+ span.end();
1715
+ return result;
1716
+ } catch (error) {
1717
+ span.recordException(error);
1718
+ span.setStatus({ code: SpanStatusCode3.ERROR });
1719
+ span.end();
1720
+ throw error;
1721
+ }
1722
+ });
1723
+ });
1724
+ });
1725
+ }
1726
+ function startSessionTitle(callback, options) {
1727
+ const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
1728
+ const tracer = trace4.getTracer("@brizz/sdk");
1729
+ return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
1730
+ if (resolvedSessionId) {
1731
+ span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
1732
+ }
1733
+ const sessionTitle = new SessionTitle(span);
1734
+ const properties = { [SESSION_TITLE_GENERATION]: "true" };
1735
+ if (resolvedSessionId) {
1736
+ properties[SESSION_ID] = resolvedSessionId;
1737
+ }
1738
+ return callWithProperties(properties, () => {
1739
+ try {
1740
+ const result = callback(sessionTitle);
1741
+ if (result && typeof result.then === "function") {
1742
+ return result.then((value) => {
1743
+ span.end();
1744
+ return value;
1745
+ }).catch((error) => {
1746
+ span.recordException(error);
1747
+ span.setStatus({ code: SpanStatusCode3.ERROR });
1748
+ span.end();
1749
+ throw error;
1750
+ });
1751
+ }
1752
+ span.end();
1753
+ return result;
1754
+ } catch (error) {
1755
+ span.recordException(error);
1756
+ span.setStatus({ code: SpanStatusCode3.ERROR });
1757
+ span.end();
1758
+ throw error;
1759
+ }
1760
+ });
1761
+ });
1762
+ }
1763
+
1764
+ // src/internal/log/logging.ts
1486
1765
  init_version();
1487
1766
 
1488
1767
  // src/internal/log/processors/log-processor.ts
1489
1768
  init_logger();
1490
- import { context as context3 } from "@opentelemetry/api";
1769
+ import { context as context4 } from "@opentelemetry/api";
1491
1770
  import { BatchLogRecordProcessor, SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
1492
1771
 
1493
1772
  // src/internal/masking/patterns.ts
@@ -1918,7 +2197,7 @@ var BrizzSimpleLogRecordProcessor = class extends SimpleLogRecordProcessor {
1918
2197
  if (maskingConfig) {
1919
2198
  maskLog(logRecord, maskingConfig);
1920
2199
  }
1921
- const associationProperties = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
2200
+ const associationProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
1922
2201
  if (associationProperties) {
1923
2202
  for (const [key, value] of Object.entries(associationProperties)) {
1924
2203
  logRecord.setAttribute(`${BRIZZ}.${key}`, value);
@@ -1938,7 +2217,7 @@ var BrizzBatchLogRecordProcessor = class extends BatchLogRecordProcessor {
1938
2217
  if (maskingConfig) {
1939
2218
  maskLog(logRecord, maskingConfig);
1940
2219
  }
1941
- const associationProperties = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
2220
+ const associationProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
1942
2221
  if (associationProperties) {
1943
2222
  for (const [key, value] of Object.entries(associationProperties)) {
1944
2223
  logRecord.setAttribute(`${BRIZZ}.${key}`, value);
@@ -1967,6 +2246,11 @@ function maskLog(logRecord, config) {
1967
2246
  for (const [key, value] of Object.entries(maskedAttributes)) {
1968
2247
  newAttributes[key] = value;
1969
2248
  }
2249
+ for (const [key, value] of Object.entries(logRecord.attributes)) {
2250
+ if (key.startsWith(INTERNAL_EVENT_PREFIX)) {
2251
+ newAttributes[key] = value;
2252
+ }
2253
+ }
1970
2254
  logRecord.setAttributes(newAttributes);
1971
2255
  }
1972
2256
  }
@@ -2156,6 +2440,11 @@ var LoggingModule = class _LoggingModule {
2156
2440
  function emitEvent(name, attributes, body, severityNumber = SeverityNumber.INFO) {
2157
2441
  return LoggingModule.getInstance().emitEvent(name, attributes, body, severityNumber);
2158
2442
  }
2443
+ function emitEventWithSessionId(sessionId, name, attributes, body, severityNumber = SeverityNumber.INFO) {
2444
+ return callWithSessionId(sessionId, () => {
2445
+ LoggingModule.getInstance().emitEvent(name, attributes, body, severityNumber);
2446
+ });
2447
+ }
2159
2448
 
2160
2449
  // src/internal/sdk.ts
2161
2450
  init_logger();
@@ -2339,14 +2628,14 @@ var BrizzSpanExporter = class {
2339
2628
 
2340
2629
  // src/internal/trace/processors/span-processor.ts
2341
2630
  init_logger();
2342
- import { context as context4 } from "@opentelemetry/api";
2631
+ import { context as context5 } from "@opentelemetry/api";
2343
2632
  import {
2344
2633
  BatchSpanProcessor,
2345
2634
  SimpleSpanProcessor
2346
2635
  } from "@opentelemetry/sdk-trace-base";
2347
2636
  init_semantic_conventions2();
2348
2637
  function applyContextAttributes(span) {
2349
- const sessionProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
2638
+ const sessionProperties = context5.active().getValue(PROPERTIES_CONTEXT_KEY);
2350
2639
  if (sessionProperties) {
2351
2640
  for (const [key, value] of Object.entries(sessionProperties)) {
2352
2641
  span.setAttribute(`${BRIZZ}.${key}`, value);
@@ -2531,214 +2820,6 @@ function getSpanProcessor() {
2531
2820
  return TracingModule.getInstance().getSpanProcessor();
2532
2821
  }
2533
2822
 
2534
- // src/internal/trace/session.ts
2535
- init_semantic_conventions2();
2536
- import { context as context5, trace as trace4, SpanStatusCode as SpanStatusCode3 } from "@opentelemetry/api";
2537
- function setCurrentSpanCustomProperties(properties) {
2538
- const current = trace4.getActiveSpan();
2539
- if (!current || !current.isRecording()) {
2540
- return;
2541
- }
2542
- for (const [key, value] of Object.entries(properties)) {
2543
- try {
2544
- current.setAttribute(`${BRIZZ}.${key}`, value);
2545
- } catch {
2546
- }
2547
- }
2548
- }
2549
- function callWithProperties(properties, fn, thisArg, ...args) {
2550
- const base = context5.active();
2551
- const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
2552
- const merged = prev ? { ...prev, ...properties } : properties;
2553
- const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
2554
- return context5.with(next, fn, thisArg, ...args);
2555
- }
2556
- function withProperties(properties, fn, thisArg) {
2557
- return function wrapped(...args) {
2558
- return callWithProperties(
2559
- properties,
2560
- fn,
2561
- thisArg !== void 0 ? thisArg : this,
2562
- ...args
2563
- );
2564
- };
2565
- }
2566
- function withSessionId(sessionId, fn, thisArg, extraProperties) {
2567
- const properties = { [SESSION_ID]: sessionId, ...extraProperties };
2568
- return withProperties(properties, fn, thisArg);
2569
- }
2570
- function callWithSessionId(sessionId, fn, thisArg, ...args) {
2571
- return callWithProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
2572
- }
2573
- var Session = class {
2574
- sessionId;
2575
- span;
2576
- inputs = [];
2577
- outputs = [];
2578
- inputContexts = [];
2579
- outputContexts = [];
2580
- constructor(sessionId, span) {
2581
- this.sessionId = sessionId;
2582
- this.span = span;
2583
- }
2584
- /**
2585
- * Append a user turn to session input tracking.
2586
- *
2587
- * Each call appends one element to `brizz.session.input` (the text) AND one
2588
- * element to `brizz.session.input.context` (the per-turn context bag). The
2589
- * two arrays stay index-aligned — the ingestion pipeline zips them together
2590
- * so the i-th context bag lands on the i-th user_display conversation item's
2591
- * `span_attributes` map.
2592
- *
2593
- * @param text - Text to append (null becomes a null/"hide marker")
2594
- * @param context - Optional per-turn context bag to attach to this turn
2595
- */
2596
- setInput(text, context6) {
2597
- this.inputs.push(text);
2598
- this.inputContexts.push(context6 ?? {});
2599
- this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
2600
- this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
2601
- }
2602
- /**
2603
- * Append an assistant turn to session output tracking.
2604
- *
2605
- * Symmetric to {@link setInput} — appends one text element and one
2606
- * context-bag element to the index-aligned `brizz.session.output` /
2607
- * `brizz.session.output.context` arrays.
2608
- *
2609
- * @param text - Text to append (null becomes a null/"hide marker")
2610
- * @param context - Optional per-turn context bag to attach to this turn
2611
- */
2612
- setOutput(text, context6) {
2613
- this.outputs.push(text);
2614
- this.outputContexts.push(context6 ?? {});
2615
- this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
2616
- this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
2617
- }
2618
- /**
2619
- * Set the session title on the span.
2620
- *
2621
- * @param title - The generated title string
2622
- */
2623
- setTitle(title) {
2624
- this.span.setAttribute(SESSION_TITLE, title);
2625
- }
2626
- /**
2627
- * Update custom properties on the session span.
2628
- * Properties are prefixed with 'brizz.'.
2629
- *
2630
- * @param properties - Key-value properties to set on the session
2631
- */
2632
- updateProperties(properties) {
2633
- for (const [key, value] of Object.entries(properties)) {
2634
- this.span.setAttribute(`${BRIZZ}.${key}`, value);
2635
- }
2636
- }
2637
- };
2638
- var SessionTitle = class {
2639
- span;
2640
- constructor(span) {
2641
- this.span = span;
2642
- }
2643
- /**
2644
- * Set the generated title on the wrapper span.
2645
- *
2646
- * @param title - The generated title string
2647
- */
2648
- setTitle(title) {
2649
- this.span.setAttribute(SESSION_TITLE, title);
2650
- }
2651
- };
2652
- function getActiveSession() {
2653
- return context5.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
2654
- }
2655
- function startSession(sessionId, callback, extraProperties, options) {
2656
- const isTitle = options?.mode === "title";
2657
- const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
2658
- const tracer = trace4.getTracer("@brizz/sdk");
2659
- return tracer.startActiveSpan(spanName, (span) => {
2660
- span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
2661
- if (extraProperties) {
2662
- for (const [key, value] of Object.entries(extraProperties)) {
2663
- span.setAttribute(`${BRIZZ}.${key}`, value);
2664
- }
2665
- }
2666
- const session = new Session(sessionId, span);
2667
- const contextProperties = { [SESSION_ID]: sessionId };
2668
- if (isTitle) {
2669
- contextProperties[SESSION_TITLE_GENERATION] = "true";
2670
- }
2671
- if (extraProperties) {
2672
- for (const [key, value] of Object.entries(extraProperties)) {
2673
- contextProperties[key] = String(value);
2674
- }
2675
- }
2676
- return callWithProperties(contextProperties, () => {
2677
- const sessionCtx = context5.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
2678
- return context5.with(sessionCtx, () => {
2679
- try {
2680
- const result = callback(session);
2681
- if (result && typeof result.then === "function") {
2682
- return result.then((value) => {
2683
- span.end();
2684
- return value;
2685
- }).catch((error) => {
2686
- span.recordException(error);
2687
- span.setStatus({ code: SpanStatusCode3.ERROR });
2688
- span.end();
2689
- throw error;
2690
- });
2691
- }
2692
- span.end();
2693
- return result;
2694
- } catch (error) {
2695
- span.recordException(error);
2696
- span.setStatus({ code: SpanStatusCode3.ERROR });
2697
- span.end();
2698
- throw error;
2699
- }
2700
- });
2701
- });
2702
- });
2703
- }
2704
- function startSessionTitle(callback, options) {
2705
- const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
2706
- const tracer = trace4.getTracer("@brizz/sdk");
2707
- return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
2708
- if (resolvedSessionId) {
2709
- span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
2710
- }
2711
- const sessionTitle = new SessionTitle(span);
2712
- const properties = { [SESSION_TITLE_GENERATION]: "true" };
2713
- if (resolvedSessionId) {
2714
- properties[SESSION_ID] = resolvedSessionId;
2715
- }
2716
- return callWithProperties(properties, () => {
2717
- try {
2718
- const result = callback(sessionTitle);
2719
- if (result && typeof result.then === "function") {
2720
- return result.then((value) => {
2721
- span.end();
2722
- return value;
2723
- }).catch((error) => {
2724
- span.recordException(error);
2725
- span.setStatus({ code: SpanStatusCode3.ERROR });
2726
- span.end();
2727
- throw error;
2728
- });
2729
- }
2730
- span.end();
2731
- return result;
2732
- } catch (error) {
2733
- span.recordException(error);
2734
- span.setStatus({ code: SpanStatusCode3.ERROR });
2735
- span.end();
2736
- throw error;
2737
- }
2738
- });
2739
- });
2740
- }
2741
-
2742
2823
  // src/internal/sdk.ts
2743
2824
  init_version();
2744
2825
  var _Brizz = class __Brizz {
@@ -2997,10 +3078,13 @@ export {
2997
3078
  Session,
2998
3079
  SessionTitle,
2999
3080
  SeverityNumber2 as SeverityNumber,
3081
+ addExternalLink,
3082
+ callWithMute,
3000
3083
  callWithProperties,
3001
3084
  callWithSessionId,
3002
3085
  detectRuntime,
3003
3086
  emitEvent,
3087
+ emitEventWithSessionId,
3004
3088
  getActiveSession,
3005
3089
  getLogLevel,
3006
3090
  getMetricsExporter,
@@ -3015,6 +3099,7 @@ export {
3015
3099
  setLogLevel,
3016
3100
  startSession,
3017
3101
  startSessionTitle,
3102
+ withMute,
3018
3103
  withProperties,
3019
3104
  withSessionId
3020
3105
  };
package/dist/preload.cjs CHANGED
@@ -472,6 +472,7 @@ var SESSION_ID = "session.id";
472
472
  var PROPERTIES_CONTEXT_KEY = (0, import_api3.createContextKey)(PROPERTIES);
473
473
  var SESSION_OBJECT_CONTEXT_KEY = (0, import_api3.createContextKey)("brizz.session.object");
474
474
  var INTERRUPT_TOOLS = "brizz.internal.interrupt";
475
+ var INTERNAL_EVENT_PREFIX = "brizz.internal.";
475
476
 
476
477
  // src/internal/instrumentation/mcp/session.ts
477
478
  function stampAndPropagateSession(span, sessionId, baseContext = import_api4.context.active()) {
@@ -909,7 +910,7 @@ function safeEnd(span) {
909
910
 
910
911
  // src/internal/version.ts
911
912
  function getSDKVersion() {
912
- return "0.1.27";
913
+ return "0.1.28";
913
914
  }
914
915
 
915
916
  // src/internal/instrumentation/mcp/version.ts
@@ -1211,8 +1212,11 @@ var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-
1211
1212
  var import_resources = require("@opentelemetry/resources");
1212
1213
  var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
1213
1214
 
1214
- // src/internal/log/processors/log-processor.ts
1215
+ // src/internal/trace/session.ts
1215
1216
  var import_api9 = require("@opentelemetry/api");
1217
+
1218
+ // src/internal/log/processors/log-processor.ts
1219
+ var import_api10 = require("@opentelemetry/api");
1216
1220
  var import_sdk_logs = require("@opentelemetry/sdk-logs");
1217
1221
 
1218
1222
  // src/internal/masking/patterns.ts
@@ -1641,7 +1645,7 @@ var BrizzSimpleLogRecordProcessor = class extends import_sdk_logs.SimpleLogRecor
1641
1645
  if (maskingConfig) {
1642
1646
  maskLog(logRecord, maskingConfig);
1643
1647
  }
1644
- const associationProperties = import_api9.context.active().getValue(PROPERTIES_CONTEXT_KEY);
1648
+ const associationProperties = import_api10.context.active().getValue(PROPERTIES_CONTEXT_KEY);
1645
1649
  if (associationProperties) {
1646
1650
  for (const [key, value] of Object.entries(associationProperties)) {
1647
1651
  logRecord.setAttribute(`${BRIZZ}.${key}`, value);
@@ -1661,7 +1665,7 @@ var BrizzBatchLogRecordProcessor = class extends import_sdk_logs.BatchLogRecordP
1661
1665
  if (maskingConfig) {
1662
1666
  maskLog(logRecord, maskingConfig);
1663
1667
  }
1664
- const associationProperties = import_api9.context.active().getValue(PROPERTIES_CONTEXT_KEY);
1668
+ const associationProperties = import_api10.context.active().getValue(PROPERTIES_CONTEXT_KEY);
1665
1669
  if (associationProperties) {
1666
1670
  for (const [key, value] of Object.entries(associationProperties)) {
1667
1671
  logRecord.setAttribute(`${BRIZZ}.${key}`, value);
@@ -1690,6 +1694,11 @@ function maskLog(logRecord, config) {
1690
1694
  for (const [key, value] of Object.entries(maskedAttributes)) {
1691
1695
  newAttributes[key] = value;
1692
1696
  }
1697
+ for (const [key, value] of Object.entries(logRecord.attributes)) {
1698
+ if (key.startsWith(INTERNAL_EVENT_PREFIX)) {
1699
+ newAttributes[key] = value;
1700
+ }
1701
+ }
1693
1702
  logRecord.setAttributes(newAttributes);
1694
1703
  }
1695
1704
  }
@@ -2048,10 +2057,10 @@ var BrizzSpanExporter = class {
2048
2057
  };
2049
2058
 
2050
2059
  // src/internal/trace/processors/span-processor.ts
2051
- var import_api10 = require("@opentelemetry/api");
2060
+ var import_api11 = require("@opentelemetry/api");
2052
2061
  var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
2053
2062
  function applyContextAttributes(span) {
2054
- const sessionProperties = import_api10.context.active().getValue(PROPERTIES_CONTEXT_KEY);
2063
+ const sessionProperties = import_api11.context.active().getValue(PROPERTIES_CONTEXT_KEY);
2055
2064
  if (sessionProperties) {
2056
2065
  for (const [key, value] of Object.entries(sessionProperties)) {
2057
2066
  span.setAttribute(`${BRIZZ}.${key}`, value);
@@ -2233,9 +2242,6 @@ function getSpanProcessor() {
2233
2242
  return TracingModule.getInstance().getSpanProcessor();
2234
2243
  }
2235
2244
 
2236
- // src/internal/trace/session.ts
2237
- var import_api11 = require("@opentelemetry/api");
2238
-
2239
2245
  // src/internal/sdk.ts
2240
2246
  var _Brizz = class __Brizz {
2241
2247
  static instance = null;