@brizz/sdk 0.1.37 → 0.1.39

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.
Files changed (102) hide show
  1. package/README.md +28 -125
  2. package/dist/{chunk-OR3YPY4I.js → chunk-JBNWC4YN.js} +1 -1
  3. package/dist/{chunk-2DSTZTDA.cjs → chunk-NMDPWJMU.cjs} +1 -1
  4. package/dist/index.cjs +2257 -13
  5. package/dist/index.js +2292 -48
  6. package/dist/{mcp-NC5OXRT4.cjs → mcp-3N3DAQGD.cjs} +2 -2
  7. package/dist/{mcp-7Y3O5QSS.js → mcp-EWOGAW4J.js} +1 -1
  8. package/dist/types/cjs/eve.d.ts +2 -0
  9. package/dist/types/cjs/google-genai.d.ts +1 -0
  10. package/dist/types/cjs/index.d.ts +15 -0
  11. package/dist/types/cjs/internal/config.d.ts +19 -0
  12. package/dist/types/cjs/internal/constants.d.ts +3 -0
  13. package/dist/types/cjs/internal/dsn.d.ts +13 -0
  14. package/dist/types/cjs/internal/instrumentation/auto-init.d.ts +8 -0
  15. package/dist/types/cjs/internal/instrumentation/google-genai.d.ts +13 -0
  16. package/dist/types/cjs/internal/instrumentation/index.d.ts +2 -0
  17. package/dist/types/cjs/internal/instrumentation/mcp/index.d.ts +2 -0
  18. package/dist/types/cjs/internal/instrumentation/mcp/instrumentation.d.ts +15 -0
  19. package/dist/types/cjs/internal/instrumentation/mcp/patches/attributes.d.ts +9 -0
  20. package/dist/types/cjs/internal/instrumentation/mcp/patches/protocol.d.ts +2 -0
  21. package/dist/types/cjs/internal/instrumentation/mcp/schemas.d.ts +2 -0
  22. package/dist/types/cjs/internal/instrumentation/mcp/semantic-conventions.d.ts +37 -0
  23. package/dist/types/cjs/internal/instrumentation/mcp/session.d.ts +6 -0
  24. package/dist/types/cjs/internal/instrumentation/mcp/types.d.ts +47 -0
  25. package/dist/types/cjs/internal/instrumentation/mcp/version.d.ts +2 -0
  26. package/dist/types/cjs/internal/instrumentation/registry.d.ts +29 -0
  27. package/dist/types/cjs/internal/instrumentation/vercel-ai/interrupt.d.ts +11 -0
  28. package/dist/types/cjs/internal/log/index.d.ts +1 -0
  29. package/dist/types/cjs/internal/log/logging.d.ts +21 -0
  30. package/dist/types/cjs/internal/log/processors/log-processor.d.ts +16 -0
  31. package/dist/types/cjs/internal/logger.d.ts +23 -0
  32. package/dist/types/cjs/internal/masking/index.d.ts +3 -0
  33. package/dist/types/cjs/internal/masking/patterns.d.ts +2 -0
  34. package/dist/types/cjs/internal/masking/types.d.ts +32 -0
  35. package/dist/types/cjs/internal/masking/utils.d.ts +5 -0
  36. package/dist/types/cjs/internal/metric/index.d.ts +1 -0
  37. package/dist/types/cjs/internal/metric/metrics.d.ts +17 -0
  38. package/dist/types/cjs/internal/sdk.d.ts +42 -0
  39. package/dist/types/cjs/internal/semantic-conventions.d.ts +54 -0
  40. package/dist/types/cjs/internal/trace/exporters/eve-trace-exporter.d.ts +18 -0
  41. package/dist/types/cjs/internal/trace/exporters/span-exporter.d.ts +12 -0
  42. package/dist/types/cjs/internal/trace/index.d.ts +4 -0
  43. package/dist/types/cjs/internal/trace/processors/eve-session-processor.d.ts +2 -0
  44. package/dist/types/cjs/internal/trace/processors/span-processor.d.ts +18 -0
  45. package/dist/types/cjs/internal/trace/session.d.ts +135 -0
  46. package/dist/types/cjs/internal/trace/tracing.d.ts +17 -0
  47. package/dist/types/cjs/internal/version.d.ts +1 -0
  48. package/dist/types/cjs/package.json +3 -0
  49. package/dist/types/esm/eve.d.ts +2 -0
  50. package/dist/types/esm/google-genai.d.ts +1 -0
  51. package/dist/types/esm/index.d.ts +15 -0
  52. package/dist/types/esm/internal/config.d.ts +19 -0
  53. package/dist/types/esm/internal/constants.d.ts +3 -0
  54. package/dist/types/esm/internal/dsn.d.ts +13 -0
  55. package/dist/types/esm/internal/instrumentation/auto-init.d.ts +8 -0
  56. package/dist/types/esm/internal/instrumentation/google-genai.d.ts +13 -0
  57. package/dist/types/esm/internal/instrumentation/index.d.ts +2 -0
  58. package/dist/types/esm/internal/instrumentation/mcp/index.d.ts +2 -0
  59. package/dist/types/esm/internal/instrumentation/mcp/instrumentation.d.ts +15 -0
  60. package/dist/types/esm/internal/instrumentation/mcp/patches/attributes.d.ts +9 -0
  61. package/dist/types/esm/internal/instrumentation/mcp/patches/protocol.d.ts +2 -0
  62. package/dist/types/esm/internal/instrumentation/mcp/schemas.d.ts +2 -0
  63. package/dist/types/esm/internal/instrumentation/mcp/semantic-conventions.d.ts +37 -0
  64. package/dist/types/esm/internal/instrumentation/mcp/session.d.ts +6 -0
  65. package/dist/types/esm/internal/instrumentation/mcp/types.d.ts +47 -0
  66. package/dist/types/esm/internal/instrumentation/mcp/version.d.ts +2 -0
  67. package/dist/types/esm/internal/instrumentation/registry.d.ts +29 -0
  68. package/dist/types/esm/internal/instrumentation/vercel-ai/interrupt.d.ts +11 -0
  69. package/dist/types/esm/internal/log/index.d.ts +1 -0
  70. package/dist/types/esm/internal/log/logging.d.ts +21 -0
  71. package/dist/types/esm/internal/log/processors/log-processor.d.ts +16 -0
  72. package/dist/types/esm/internal/logger.d.ts +23 -0
  73. package/dist/types/esm/internal/masking/index.d.ts +3 -0
  74. package/dist/types/esm/internal/masking/patterns.d.ts +2 -0
  75. package/dist/types/esm/internal/masking/types.d.ts +32 -0
  76. package/dist/types/esm/internal/masking/utils.d.ts +5 -0
  77. package/dist/types/esm/internal/metric/index.d.ts +1 -0
  78. package/dist/types/esm/internal/metric/metrics.d.ts +17 -0
  79. package/dist/types/esm/internal/sdk.d.ts +42 -0
  80. package/dist/types/esm/internal/semantic-conventions.d.ts +54 -0
  81. package/dist/types/esm/internal/trace/exporters/eve-trace-exporter.d.ts +18 -0
  82. package/dist/types/esm/internal/trace/exporters/span-exporter.d.ts +12 -0
  83. package/dist/types/esm/internal/trace/index.d.ts +4 -0
  84. package/dist/types/esm/internal/trace/processors/eve-session-processor.d.ts +2 -0
  85. package/dist/types/esm/internal/trace/processors/span-processor.d.ts +18 -0
  86. package/dist/types/esm/internal/trace/session.d.ts +135 -0
  87. package/dist/types/esm/internal/trace/tracing.d.ts +17 -0
  88. package/dist/types/esm/internal/version.d.ts +1 -0
  89. package/package.json +57 -57
  90. package/dist/chunk-4Q2CRWI6.js +0 -2377
  91. package/dist/chunk-O5DVPC42.cjs +0 -2377
  92. package/dist/eve.d.cts +0 -19
  93. package/dist/eve.d.ts +0 -19
  94. package/dist/google-genai.d.cts +0 -7
  95. package/dist/google-genai.d.ts +0 -7
  96. package/dist/index.d.cts +0 -291
  97. package/dist/index.d.ts +0 -291
  98. package/dist/loader.mjs +0 -85
  99. package/dist/preload.cjs +0 -119
  100. package/dist/preload.d.cts +0 -2
  101. package/dist/preload.d.ts +0 -2
  102. package/dist/preload.js +0 -119
@@ -1,2377 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6;
2
-
3
-
4
- var _chunkUNLNNKZ7cjs = require('./chunk-UNLNNKZ7.cjs');
5
-
6
-
7
- var _chunk2DSTZTDAcjs = require('./chunk-2DSTZTDA.cjs');
8
-
9
-
10
-
11
-
12
-
13
- var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
14
-
15
-
16
- var _chunkEVRCHF74cjs = require('./chunk-EVRCHF74.cjs');
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
- var _chunk77UGZGMPcjs = require('./chunk-77UGZGMP.cjs');
69
-
70
-
71
- var _chunkOBGZSXTJcjs = require('./chunk-OBGZSXTJ.cjs');
72
-
73
- // src/internal/instrumentation/registry.ts
74
- var _openinferenceinstrumentationopenai = require('@arizeai/openinference-instrumentation-openai');
75
- var _instrumentationanthropic = require('@traceloop/instrumentation-anthropic');
76
- var _instrumentationbedrock = require('@traceloop/instrumentation-bedrock');
77
- var _instrumentationchromadb = require('@traceloop/instrumentation-chromadb');
78
- var _instrumentationcohere = require('@traceloop/instrumentation-cohere');
79
- var _instrumentationllamaindex = require('@traceloop/instrumentation-llamaindex');
80
- var _instrumentationpinecone = require('@traceloop/instrumentation-pinecone');
81
- var _instrumentationqdrant = require('@traceloop/instrumentation-qdrant');
82
- var _instrumentationtogether = require('@traceloop/instrumentation-together');
83
- var InstrumentationRegistry = (_class = class _InstrumentationRegistry {constructor() { _class.prototype.__init.call(this); }
84
-
85
- static getInstance() {
86
- if (!this.instance) {
87
- this.instance = new _InstrumentationRegistry();
88
- }
89
- return this.instance;
90
- }
91
- __init() {this.manualModules = null}
92
- /**
93
- * Helper to load instrumentation with optional manual module
94
- */
95
- loadInstrumentation(InstrumentationClass, name, manualModule, exceptionLogger) {
96
- try {
97
- const inst = new InstrumentationClass({
98
- exceptionLogger: exceptionLogger || ((error) => _chunkWC573FCIcjs.logger.error(`Exception in instrumentation: ${String(error)}`))
99
- });
100
- if (manualModule) {
101
- inst.manuallyInstrument(manualModule);
102
- _chunkWC573FCIcjs.logger.debug(`Manual instrumentation enabled for ${name}`);
103
- }
104
- return inst;
105
- } catch (error) {
106
- _chunkWC573FCIcjs.logger.error(`Failed to load ${name} instrumentation: ${String(error)}`);
107
- return null;
108
- }
109
- }
110
- /**
111
- * Load manual instrumentations only (with modules provided by user).
112
- * @private
113
- */
114
- loadManualInstrumentations(instrumentations, exceptionLogger) {
115
- if (_optionalChain([this, 'access', _2 => _2.manualModules, 'optionalAccess', _3 => _3.openAI])) {
116
- try {
117
- const openAIInst = new (0, _openinferenceinstrumentationopenai.OpenAIInstrumentation)();
118
- openAIInst.manuallyInstrument(this.manualModules.openAI);
119
- instrumentations.push(openAIInst);
120
- _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for OpenAI");
121
- } catch (error) {
122
- _chunkWC573FCIcjs.logger.error(`Failed to load OpenAI instrumentation: ${String(error)}`);
123
- }
124
- }
125
- const instrumentationConfigs = [
126
- { class: _instrumentationanthropic.AnthropicInstrumentation, name: "Anthropic", module: _optionalChain([this, 'access', _4 => _4.manualModules, 'optionalAccess', _5 => _5.anthropic]) },
127
- { class: _instrumentationcohere.CohereInstrumentation, name: "Cohere", module: _optionalChain([this, 'access', _6 => _6.manualModules, 'optionalAccess', _7 => _7.cohere]) },
128
- { class: _instrumentationbedrock.BedrockInstrumentation, name: "Bedrock", module: _optionalChain([this, 'access', _8 => _8.manualModules, 'optionalAccess', _9 => _9.bedrock]) },
129
- { class: _instrumentationpinecone.PineconeInstrumentation, name: "Pinecone", module: _optionalChain([this, 'access', _10 => _10.manualModules, 'optionalAccess', _11 => _11.pinecone]) },
130
- {
131
- class: _instrumentationllamaindex.LlamaIndexInstrumentation,
132
- name: "LlamaIndex",
133
- module: _optionalChain([this, 'access', _12 => _12.manualModules, 'optionalAccess', _13 => _13.llamaindex])
134
- },
135
- { class: _instrumentationchromadb.ChromaDBInstrumentation, name: "ChromaDB", module: _optionalChain([this, 'access', _14 => _14.manualModules, 'optionalAccess', _15 => _15.chromadb]) },
136
- { class: _instrumentationqdrant.QdrantInstrumentation, name: "Qdrant", module: _optionalChain([this, 'access', _16 => _16.manualModules, 'optionalAccess', _17 => _17.qdrant]) },
137
- { class: _instrumentationtogether.TogetherInstrumentation, name: "Together", module: _optionalChain([this, 'access', _18 => _18.manualModules, 'optionalAccess', _19 => _19.together]) }
138
- ];
139
- for (const config of instrumentationConfigs) {
140
- if (!config.module) {
141
- continue;
142
- }
143
- const instrumentation = this.loadInstrumentation(
144
- config.class,
145
- config.name,
146
- config.module,
147
- exceptionLogger
148
- );
149
- if (instrumentation) {
150
- instrumentations.push(instrumentation);
151
- }
152
- }
153
- if (_optionalChain([this, 'access', _20 => _20.manualModules, 'optionalAccess', _21 => _21.langchain, 'optionalAccess', _22 => _22.callbackManagerModule])) {
154
- const callbackManagerModule = this.manualModules.langchain.callbackManagerModule;
155
- void (async () => {
156
- try {
157
- const { LangChainInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("@arizeai/openinference-instrumentation-langchain")));
158
- const lcInst = new LangChainInstrumentation();
159
- lcInst.manuallyInstrument(callbackManagerModule);
160
- _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for LangChain");
161
- } catch (error) {
162
- _chunkWC573FCIcjs.logger.error(
163
- `Failed to load LangChain instrumentation. Ensure @langchain/core is installed: ${String(error)}`
164
- );
165
- }
166
- })();
167
- }
168
- if (_optionalChain([this, 'access', _23 => _23.manualModules, 'optionalAccess', _24 => _24.google_vertexai])) {
169
- const vertexModule = this.manualModules.google_vertexai;
170
- void (async () => {
171
- try {
172
- const { VertexAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("@traceloop/instrumentation-vertexai")));
173
- const vertexInst = new VertexAIInstrumentation({ exceptionLogger });
174
- vertexInst.manuallyInstrument(vertexModule);
175
- _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for Vertex AI");
176
- } catch (error) {
177
- _chunkWC573FCIcjs.logger.error(
178
- `Failed to load Vertex AI instrumentation. Ensure @traceloop/instrumentation-vertexai is installed: ${String(error)}`
179
- );
180
- }
181
- })();
182
- }
183
- if (_optionalChain([this, 'access', _25 => _25.manualModules, 'optionalAccess', _26 => _26.google_genai])) {
184
- const genaiModule = this.manualModules.google_genai;
185
- void (async () => {
186
- try {
187
- const { GoogleGenAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./google-genai-LMEZ62FB.cjs")));
188
- const genaiInst = new GoogleGenAIInstrumentation({ exceptionLogger });
189
- genaiInst.manuallyInstrument(genaiModule);
190
- _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for Google GenAI");
191
- } catch (error) {
192
- _chunkWC573FCIcjs.logger.error(
193
- `Failed to apply Google GenAI instrumentation. Ensure @traceloop/instrumentation-google-generativeai is installed; on a read-only ESM module namespace use instrumentGoogleGenAI from @brizz/sdk/google-genai instead: ${String(error)}`
194
- );
195
- }
196
- })();
197
- }
198
- if (_optionalChain([this, 'access', _27 => _27.manualModules, 'optionalAccess', _28 => _28.mcp])) {
199
- const mcpModules = this.manualModules.mcp;
200
- void (async () => {
201
- try {
202
- const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-NC5OXRT4.cjs")));
203
- const instrumentation = new MCPInstrumentation({ exceptionLogger });
204
- instrumentation.manuallyInstrument(mcpModules);
205
- _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for MCP");
206
- } catch (error) {
207
- _chunkWC573FCIcjs.logger.error(`Failed to apply MCP instrumentation: ${String(error)}`);
208
- }
209
- })();
210
- }
211
- }
212
- /**
213
- * Set manual instrumentation modules for Next.js/Webpack environments
214
- */
215
- setManualModules(modules) {
216
- this.manualModules = modules;
217
- _chunkWC573FCIcjs.logger.info("Manual instrumentation modules configured for Next.js/Webpack compatibility");
218
- }
219
- /**
220
- * Get manual instrumentations only.
221
- * Auto-instrumentations are handled at import time.
222
- */
223
- getManualInstrumentations() {
224
- if (!this.manualModules || Object.keys(this.manualModules).length === 0) {
225
- _chunkWC573FCIcjs.logger.debug("No manual instrumentation modules configured");
226
- return [];
227
- }
228
- const instrumentations = [];
229
- const exceptionLogger = (error) => {
230
- _chunkWC573FCIcjs.logger.error(`Exception in manual instrumentation: ${String(error)}`);
231
- };
232
- this.loadManualInstrumentations(instrumentations, exceptionLogger);
233
- _chunkWC573FCIcjs.logger.info(`Loaded ${instrumentations.length} manual instrumentations`);
234
- return instrumentations;
235
- }
236
- }, _class);
237
-
238
- // src/internal/trace/session.ts
239
- var _api = require('@opentelemetry/api');
240
-
241
- // src/internal/log/logging.ts
242
- var _apilogs = require('@opentelemetry/api-logs');
243
- var _exporterlogsotlphttp = require('@opentelemetry/exporter-logs-otlp-http');
244
- var _resources = require('@opentelemetry/resources');
245
-
246
-
247
- var _sdklogs = require('@opentelemetry/sdk-logs');
248
-
249
- // src/internal/constants.ts
250
- var BRIZZ_SDK_VERSION = "brizz.sdk.version";
251
- var BRIZZ_SDK_LANGUAGE = "brizz.sdk.language";
252
- var SDK_LANGUAGE = "typescript";
253
-
254
- // src/internal/log/processors/log-processor.ts
255
-
256
-
257
-
258
- // src/internal/masking/patterns.ts
259
- var DEFAULT_PII_PATTERNS = [
260
- // Phone numbers (US format)
261
- {
262
- name: "us_phone_numbers",
263
- pattern: String.raw`(?:^|[\s])(?:\+?1[-.\s]*)?(?:\([0-9]{3}\)\s?[0-9]{3}[-.\s]?[0-9]{4}|[0-9]{3}[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}|[0-9]{10})(?=[\s]|$)`
264
- },
265
- // Credit card numbers
266
- {
267
- name: "credit_cards",
268
- pattern: String.raw`\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\\d{3})\\d{11})\b`
269
- },
270
- {
271
- name: "credit_cards_with_separators",
272
- pattern: String.raw`\b(?:4\\d{3}|5[1-5]\\d{2}|3[47]\\d{2})[-\s]?\\d{4}[-\s]?\\d{4}[-\s]?\\d{4}\b`
273
- },
274
- // IP addresses (IPv4)
275
- {
276
- name: "ipv4_addresses",
277
- pattern: String.raw`\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?!\.[0-9])\b`
278
- },
279
- // API keys/tokens
280
- {
281
- name: "generic_api_keys",
282
- pattern: String.raw`\b(?:[Aa][Pp][Ii][_-]?[Kk][Ee][Yy]|[Tt][Oo][Kk][Ee][Nn]|[Ss][Ee][Cc][Rr][Ee][Tt])[_-]?[=:]?\s*["']?(?:[a-zA-Z0-9\-_.]{20,})["']?\b`
283
- },
284
- {
285
- name: "openai_keys",
286
- pattern: String.raw`\bsk[-_][a-zA-Z0-9]{20,}\b`
287
- },
288
- // AWS Keys
289
- {
290
- name: "aws_access_keys",
291
- pattern: String.raw`\b(?:AKIA|ABIA|ACCA|ASIA)[0-9A-Z]{16}\b`
292
- },
293
- // GitHub tokens
294
- {
295
- name: "github_tokens",
296
- pattern: String.raw`\bghp_[a-zA-Z0-9]{36}\b`
297
- },
298
- // Slack tokens
299
- {
300
- name: "slack_tokens",
301
- pattern: String.raw`\bxox[baprs]-[0-9]{10,13}-[0-9]{10,13}-[a-zA-Z0-9]{24,34}\b`
302
- },
303
- // Stripe keys
304
- {
305
- name: "stripe_keys",
306
- pattern: String.raw`\b(?:sk|pk)_(?:test|live)_[a-zA-Z0-9]{24,}\b`
307
- },
308
- // JWT tokens
309
- {
310
- name: "jwt_tokens",
311
- pattern: String.raw`\beyJ[A-Za-z0-9_-]{2,}\\.[A-Za-z0-9_-]{2,}\\.[A-Za-z0-9_-]{2,}\b`
312
- },
313
- // MAC addresses
314
- {
315
- name: "mac_addresses",
316
- pattern: String.raw`\b(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}\b`
317
- },
318
- // IPv6 addresses
319
- {
320
- name: "ipv6_addresses",
321
- pattern: String.raw`\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b`
322
- },
323
- // Bitcoin addresses
324
- {
325
- name: "bitcoin_addresses",
326
- pattern: String.raw`\b[13][a-km-zA-HJ-NP-Z1-9]{25,34}\b`
327
- },
328
- // Ethereum addresses
329
- {
330
- name: "ethereum_addresses",
331
- pattern: String.raw`\b0x[a-fA-F0-9]{40}(?![a-fA-F0-9])\b`
332
- },
333
- // Database connection strings
334
- {
335
- name: "database_connections",
336
- pattern: String.raw`\b(?:[Mm][Oo][Nn][Gg][Oo][Dd][Bb]|[Pp][Oo][Ss][Tt][Gg][Rr][Ee][Ss]|[Mm][Yy][Ss][Qq][Ll]|[Rr][Ee][Dd][Ii][Ss]|[Mm][Ss][Ss][Qq][Ll]|[Oo][Rr][Aa][Cc][Ll][Ee]):\\/\\/[^\\s]+\b`
337
- },
338
- // Private keys
339
- {
340
- name: "rsa_private_keys",
341
- pattern: "-----BEGIN (?:RSA )?PRIVATE KEY-----"
342
- },
343
- {
344
- name: "pgp_private_keys",
345
- pattern: "-----BEGIN PGP PRIVATE KEY BLOCK-----"
346
- },
347
- // Additional API Keys and Tokens
348
- {
349
- name: "google_oauth",
350
- pattern: String.raw`\bya29\\.[a-zA-Z0-9_-]{60,}\b`
351
- },
352
- {
353
- name: "firebase_tokens",
354
- pattern: String.raw`\bAAAA[A-Za-z0-9_-]{100,}\b`
355
- },
356
- {
357
- name: "google_app_ids",
358
- pattern: String.raw`\b[0-9]+-\w+\.apps\.googleusercontent\.com\b`
359
- },
360
- {
361
- name: "facebook_secrets",
362
- pattern: String.raw`\b(facebook_secret|FACEBOOK_SECRET|facebook_app_secret|FACEBOOK_APP_SECRET)[a-z_ =\\s"'\\:]{0,5}[^a-zA-Z0-9][a-f0-9]{32}[^a-zA-Z0-9]`
363
- },
364
- {
365
- name: "github_keys",
366
- pattern: String.raw`\b(GITHUB_SECRET|GITHUB_KEY|github_secret|github_key|github_token|GITHUB_TOKEN|github_api_key|GITHUB_API_KEY)[a-z_ =\\s\"'\\:]{0,10}[^a-zA-Z0-9][a-zA-Z0-9]{40}[^a-zA-Z0-9]`
367
- },
368
- {
369
- name: "heroku_keys",
370
- pattern: String.raw`\b(heroku_api_key|HEROKU_API_KEY|heroku_secret|HEROKU_SECRET)[a-z_ =\\s\"'\\:]{0,10}[^a-zA-Z0-9-]\\w{8}(?:-\\w{4}){3}-\\w{12}[^a-zA-Z0-9\\-]`
371
- },
372
- {
373
- name: "slack_api_keys",
374
- pattern: String.raw`\b(slack_api_key|SLACK_API_KEY|slack_key|SLACK_KEY)[a-z_ =\\s\"'\\:]{0,10}[^a-f0-9][a-f0-9]{32}[^a-f0-9]`
375
- },
376
- {
377
- name: "slack_api_tokens",
378
- pattern: String.raw`\b(xox[pb](?:-[a-zA-Z0-9]+){4,})\b`
379
- },
380
- // Extended Private Keys and Certificates
381
- {
382
- name: "dsa_private_keys",
383
- pattern: String.raw`-----BEGIN DSA PRIVATE KEY-----(?:[a-zA-Z0-9\+\=\/"']|\s)+?-----END DSA PRIVATE KEY-----`
384
- },
385
- {
386
- name: "ec_private_keys",
387
- pattern: String.raw`-----BEGIN (?:EC|ECDSA) PRIVATE KEY-----(?:[a-zA-Z0-9\+\=\/"']|\s)+?-----END (?:EC|ECDSA) PRIVATE KEY-----`
388
- },
389
- {
390
- name: "encrypted_private_keys",
391
- pattern: String.raw`-----BEGIN ENCRYPTED PRIVATE KEY-----(?:.|\s)+?-----END ENCRYPTED PRIVATE KEY-----`
392
- },
393
- {
394
- name: "ssl_certificates",
395
- pattern: String.raw`-----BEGIN CERTIFICATE-----(?:.|\n)+?\s*-----END CERTIFICATE-----`
396
- },
397
- {
398
- name: "ssh_dss_public",
399
- pattern: String.raw`\bssh-dss [0-9A-Za-z+/]+[=]{2}\b`
400
- },
401
- {
402
- name: "ssh_rsa_public",
403
- pattern: String.raw`\bssh-rsa AAAA[0-9A-Za-z+/]+[=]{0,3} [^@]+@[^@]+\b`
404
- },
405
- {
406
- name: "putty_ssh_keys",
407
- pattern: String.raw`PuTTY-User-Key-File-2: ssh-(?:rsa|dss)\s*Encryption: none(?:.|\s?)*?Private-MAC:`
408
- },
409
- // Security and Network
410
- {
411
- name: "cve_numbers",
412
- pattern: String.raw`\b[Cc][Vv][Ee]-\\d{4}-\\d{4,7}\b`
413
- },
414
- {
415
- name: "microsoft_oauth",
416
- pattern: String.raw`https://login\.microsoftonline\.com/common/oauth2/v2\.0/token|https://login\.windows\.net/common/oauth2/token`
417
- },
418
- {
419
- name: "postgres_connections",
420
- pattern: String.raw`\b(?:[Pp][Oo][Ss][Tt][Gg][Rr][Ee][Ss]|[Pp][Gg][Ss][Qq][Ll])\\:\\/\\/`
421
- },
422
- {
423
- name: "box_links",
424
- pattern: String.raw`https://app\.box\.com/[s|l]/\S+`
425
- },
426
- {
427
- name: "dropbox_links",
428
- pattern: String.raw`https://www\.dropbox\.com/(?:s|l)/\S+`
429
- },
430
- // Credit Card Variants
431
- {
432
- name: "amex_cards",
433
- pattern: String.raw`\b3[47][0-9]{13}\b`
434
- },
435
- {
436
- name: "visa_cards",
437
- pattern: String.raw`\b4[0-9]{12}(?:[0-9]{3})?\b`
438
- },
439
- {
440
- name: "discover_cards",
441
- pattern: String.raw`\b65[4-9][0-9]{13}|64[4-9][0-9]{13}|6011[0-9]{12}\b`
442
- }
443
- ];
444
-
445
- // src/internal/masking/utils.ts
446
- function isValidPatternName(name) {
447
- return /^[a-zA-Z0-9_]+$/.test(name);
448
- }
449
- function isLikelyReDoSPattern(pattern) {
450
- const dangerousPatterns = [
451
- // Nested quantifiers like (a+)+, (a*)+, (a+)*
452
- /\([^)]*[+*]\)[+*]/,
453
- // Overlapping alternation under an outer quantifier like (a|a)+, (\w|\d)+. Scoped to
454
- // capturing groups so the lazy (?:…)+? built-ins aren't false-flagged.
455
- /\((?!\?)[^)]*\|[^)]*\)[+*]/,
456
- // Complex backtracking patterns - but more specific
457
- /\([^)]*[+*][^)]*[+*][^)]*\)[+*]/
458
- ];
459
- return dangerousPatterns.some((dangerous) => dangerous.test(pattern));
460
- }
461
- function getGroupedPattern(patternEntry) {
462
- let name = patternEntry.name;
463
- if (!name || name === "") {
464
- name = `pattern_${Math.random().toString(16).slice(2)}`;
465
- }
466
- if (!isValidPatternName(name)) {
467
- throw new Error(
468
- `Pattern name '${name}' must only contain alphanumeric characters and underscores`
469
- );
470
- }
471
- if (isLikelyReDoSPattern(patternEntry.pattern)) {
472
- throw new Error(`Potentially dangerous ReDoS pattern detected: '${patternEntry.pattern}'`);
473
- }
474
- try {
475
- new RegExp(patternEntry.pattern);
476
- } catch (error) {
477
- throw new Error(`Invalid regex pattern '${patternEntry.pattern}': ${String(error)}`, {
478
- cause: error
479
- });
480
- }
481
- return `(?<${name}>${patternEntry.pattern})`;
482
- }
483
- function isIPatternEntry(obj) {
484
- return typeof obj === "object" && obj !== null && typeof obj.pattern === "string" && (obj.name === void 0 || typeof obj.name === "string");
485
- }
486
- function isIEventMaskingRule(obj) {
487
- return typeof obj === "object" && obj !== null && typeof obj.mode === "string" && Array.isArray(obj.patterns) && obj.patterns.every(
488
- (p) => isIPatternEntry(p) || typeof p === "string"
489
- ) && (obj.attributePattern === void 0 || typeof obj.attributePattern === "string");
490
- }
491
- function convertPatternsToPatternEntries(patterns) {
492
- const patternEntries = [];
493
- for (const pattern of patterns) {
494
- if (typeof pattern === "string") {
495
- patternEntries.push({ pattern, name: "" });
496
- } else if (isIPatternEntry(pattern)) {
497
- patternEntries.push(pattern);
498
- } else {
499
- throw new Error("Patterns must be either strings or PatternEntry instances");
500
- }
501
- }
502
- return patternEntries;
503
- }
504
- function compilePatternEntries(patternEntries) {
505
- const patternGroups = [];
506
- for (const patternEntry of patternEntries) {
507
- try {
508
- patternGroups.push(getGroupedPattern(patternEntry));
509
- } catch (error) {
510
- _chunkWC573FCIcjs.logger.warn(`Invalid pattern '${patternEntry.name}': ${patternEntry.pattern}`, error);
511
- continue;
512
- }
513
- }
514
- if (patternGroups.length === 0) {
515
- return null;
516
- }
517
- try {
518
- return new RegExp(patternGroups.join("|"));
519
- } catch (error) {
520
- _chunkWC573FCIcjs.logger.warn("Failed to compile pattern entries into regex", error);
521
- return null;
522
- }
523
- }
524
- var compiledPatternCache = /* @__PURE__ */ new WeakMap();
525
- function getCompiledPatternsForRule(rule) {
526
- const key = rule.patterns;
527
- if (compiledPatternCache.has(key)) {
528
- return _nullishCoalesce(compiledPatternCache.get(key), () => ( null));
529
- }
530
- const compiled = compilePatternEntries(convertPatternsToPatternEntries(rule.patterns));
531
- compiledPatternCache.set(key, compiled);
532
- return compiled;
533
- }
534
- function getCompiledAttributeNamePattern(rule) {
535
- if (!rule.attributePattern) {
536
- _chunkWC573FCIcjs.logger.debug("No attribute pattern provided, using default .*");
537
- return /.*/;
538
- }
539
- let compiledPatternString = rule.attributePattern;
540
- if (isIEventMaskingRule(rule) && rule.eventNamePattern) {
541
- compiledPatternString = `(${compiledPatternString})|(${rule.eventNamePattern})`;
542
- }
543
- return new RegExp(compiledPatternString);
544
- }
545
- function shouldContinueExecution(startTime, iterations, timeoutMs) {
546
- if (Date.now() - startTime > timeoutMs) {
547
- _chunkWC573FCIcjs.logger.warn("Regex execution timed out - potential ReDoS pattern detected");
548
- return false;
549
- }
550
- const maxIterations = 1e3;
551
- if (iterations > maxIterations) {
552
- _chunkWC573FCIcjs.logger.warn("Regex execution exceeded maximum iterations - potential ReDoS pattern detected");
553
- return false;
554
- }
555
- return true;
556
- }
557
- function createGlobalPattern(pattern) {
558
- return new RegExp(
559
- pattern.source,
560
- pattern.flags.includes("g") ? pattern.flags : pattern.flags + "g"
561
- );
562
- }
563
- function executeRegexWithTimeout(pattern, value, timeoutMs = 100) {
564
- const matches = [];
565
- const globalPattern = createGlobalPattern(pattern);
566
- const startTime = Date.now();
567
- let match;
568
- let iterations = 0;
569
- while ((match = globalPattern.exec(value)) !== null) {
570
- if (!shouldContinueExecution(startTime, ++iterations, timeoutMs)) {
571
- break;
572
- }
573
- matches.push(match);
574
- if (match[0].length === 0) {
575
- globalPattern.lastIndex = match.index + 1;
576
- }
577
- }
578
- return matches;
579
- }
580
- function maskStringByPattern(value, pattern, mode = "full") {
581
- const matches = [];
582
- try {
583
- const regexMatches = executeRegexWithTimeout(pattern, value);
584
- for (const match of regexMatches) {
585
- matches.push({
586
- start: match.index,
587
- end: match.index + match[0].length,
588
- text: match[0],
589
- groups: match.groups
590
- });
591
- }
592
- } catch (error) {
593
- _chunkWC573FCIcjs.logger.warn("Regex execution failed, skipping masking", error);
594
- return value;
595
- }
596
- for (const matchInfo of matches.toReversed()) {
597
- let patternName = "unknown";
598
- if (matchInfo.groups) {
599
- const firstDefined = Object.entries(matchInfo.groups).find(
600
- ([, groupValue]) => groupValue !== void 0
601
- );
602
- if (firstDefined) {
603
- const [groupName] = firstDefined;
604
- if (groupName.includes("_") && /\d$/.test(groupName)) {
605
- const parts = groupName.split("_");
606
- patternName = parts[0] || groupName;
607
- } else {
608
- patternName = groupName;
609
- }
610
- }
611
- }
612
- _chunkWC573FCIcjs.logger.info(`Masking detected: pattern '${patternName}' found match in value`);
613
- const masked = mode === "partial" ? matchInfo.text.at(0) + "*****" : "*****";
614
- value = value.slice(0, matchInfo.start) + masked + value.slice(matchInfo.end);
615
- }
616
- return value;
617
- }
618
- function maskStringByPatternBasedRule(value, rule) {
619
- const patternEntries = convertPatternsToPatternEntries(rule.patterns);
620
- if (patternEntries.length === 0) {
621
- _chunkWC573FCIcjs.logger.warn("No patterns provided for masking rule, returning original value");
622
- return value;
623
- }
624
- const mode = rule.mode;
625
- if (!patternEntries || patternEntries.length === 0) {
626
- return mode === "partial" && value ? value.at(0) + "*****" : "*****";
627
- }
628
- const compiledPatterns = getCompiledPatternsForRule(rule);
629
- if (!compiledPatterns) {
630
- return value;
631
- }
632
- return maskStringByPattern(value, compiledPatterns, mode);
633
- }
634
- function maskValue(value, rule) {
635
- if (typeof value === "string") {
636
- return maskStringByPatternBasedRule(value, rule);
637
- }
638
- if (typeof value === "boolean" || typeof value === "number") {
639
- return maskStringByPatternBasedRule(String(value), rule);
640
- }
641
- if (Array.isArray(value)) {
642
- return value.map((v) => maskStringByPatternBasedRule(String(v), rule));
643
- }
644
- if (value !== null && typeof value === "object") {
645
- const result = {};
646
- for (const [k, v] of Object.entries(value)) {
647
- result[k] = maskValue(v, rule);
648
- }
649
- return result;
650
- }
651
- throw new Error(`Unsupported value type for masking: ${typeof value}`);
652
- }
653
- function maskAttributes(attributes, rules, outputOriginalValue = false) {
654
- if (!attributes || Object.keys(attributes).length === 0) {
655
- return {};
656
- }
657
- const maskedAttributes = { ...attributes };
658
- for (const rule of rules) {
659
- const compiledAttributeNamePattern = getCompiledAttributeNamePattern(rule);
660
- const attributesToMask = compiledAttributeNamePattern ? Object.keys(maskedAttributes).filter((attr) => compiledAttributeNamePattern.test(attr)) : Object.keys(maskedAttributes);
661
- for (const attribute of attributesToMask) {
662
- const value = maskedAttributes[attribute];
663
- if (value !== null && value !== void 0) {
664
- if (outputOriginalValue) {
665
- _chunkWC573FCIcjs.logger.debug(`Masking attribute '${attribute}' with original value`, { value });
666
- }
667
- maskedAttributes[attribute] = maskValue(value, rule);
668
- }
669
- }
670
- }
671
- return maskedAttributes;
672
- }
673
-
674
- // src/internal/log/processors/log-processor.ts
675
- var DEFAULT_LOG_MASKING_RULES = [
676
- {
677
- mode: "partial",
678
- attributePattern: "event.name",
679
- patterns: DEFAULT_PII_PATTERNS
680
- }
681
- ];
682
- var BrizzSimpleLogRecordProcessor = class extends _sdklogs.SimpleLogRecordProcessor {
683
-
684
- constructor(exporter, config) {
685
- super({ exporter });
686
- this.config = config;
687
- }
688
- onEmit(logRecord) {
689
- const maskingConfig = _optionalChain([this, 'access', _29 => _29.config, 'access', _30 => _30.masking, 'optionalAccess', _31 => _31.eventMasking]);
690
- if (maskingConfig) {
691
- maskLog(logRecord, maskingConfig);
692
- }
693
- const associationProperties = _api.context.active().getValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY);
694
- if (associationProperties) {
695
- for (const [key, value] of Object.entries(associationProperties)) {
696
- logRecord.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${key}`, value);
697
- }
698
- }
699
- super.onEmit(logRecord);
700
- }
701
- };
702
- var BrizzBatchLogRecordProcessor = class extends _sdklogs.BatchLogRecordProcessor {
703
-
704
- constructor(exporter, config) {
705
- super({ exporter });
706
- this.config = config;
707
- }
708
- onEmit(logRecord) {
709
- const maskingConfig = _optionalChain([this, 'access', _32 => _32.config, 'access', _33 => _33.masking, 'optionalAccess', _34 => _34.eventMasking]);
710
- if (maskingConfig) {
711
- maskLog(logRecord, maskingConfig);
712
- }
713
- const associationProperties = _api.context.active().getValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY);
714
- if (associationProperties) {
715
- for (const [key, value] of Object.entries(associationProperties)) {
716
- logRecord.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${key}`, value);
717
- }
718
- }
719
- super.onEmit(logRecord);
720
- }
721
- };
722
- function maskLog(logRecord, config) {
723
- if (!logRecord.attributes) {
724
- return logRecord;
725
- }
726
- let rules = config.rules || [];
727
- if (!config.disableDefaultRules) {
728
- rules = [...DEFAULT_LOG_MASKING_RULES, ...rules];
729
- }
730
- try {
731
- if (logRecord.attributes && Object.keys(logRecord.attributes).length > 0) {
732
- const attributesRecord = {};
733
- for (const [key, value] of Object.entries(logRecord.attributes)) {
734
- attributesRecord[key] = value;
735
- }
736
- const maskedAttributes = maskAttributes(attributesRecord, rules);
737
- if (maskedAttributes) {
738
- const newAttributes = {};
739
- for (const [key, value] of Object.entries(maskedAttributes)) {
740
- newAttributes[key] = value;
741
- }
742
- for (const [key, value] of Object.entries(logRecord.attributes)) {
743
- if (key.startsWith(_chunk77UGZGMPcjs.INTERNAL_EVENT_PREFIX)) {
744
- newAttributes[key] = value;
745
- }
746
- }
747
- logRecord.setAttributes(newAttributes);
748
- }
749
- }
750
- if (config.maskBody && logRecord.body !== void 0 && logRecord.body !== null) {
751
- let maskedBody = logRecord.body;
752
- for (const rule of rules) {
753
- maskedBody = maskValue(maskedBody, rule);
754
- }
755
- logRecord.setBody(maskedBody);
756
- }
757
- return logRecord;
758
- } catch (error) {
759
- _chunkWC573FCIcjs.logger.error("Error masking log record:", error);
760
- return logRecord;
761
- }
762
- }
763
-
764
- // src/internal/log/logging.ts
765
- var LoggingModule = (_class2 = class _LoggingModule {constructor() { _class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this); }
766
- static __initStatic() {this.instance = null}
767
- static getInstance() {
768
- if (!this.instance) {
769
- throw new Error("Brizz must be initialized before accessing LoggingModule");
770
- }
771
- return this.instance;
772
- }
773
- __init2() {this.logExporter = null}
774
- __init3() {this.logProcessor = null}
775
- __init4() {this.loggerProvider = null}
776
- /**
777
- * Initialize the log exporter
778
- */
779
- initLogExporter(config) {
780
- if (this.logExporter) {
781
- _chunkWC573FCIcjs.logger.debug("Log exporter already initialized, skipping re-initialization");
782
- return;
783
- }
784
- if (config.customLogExporter) {
785
- _chunkWC573FCIcjs.logger.debug("Using custom log exporter");
786
- this.logExporter = config.customLogExporter;
787
- _chunkWC573FCIcjs.logger.debug("Custom log exporter initialized successfully");
788
- return;
789
- }
790
- const logsUrl = config.baseUrl.replace(/\/$/, "") + "/v1/logs";
791
- _chunkWC573FCIcjs.logger.debug("Initializing default OTLP log exporter", { url: logsUrl });
792
- const headers = { ...config.headers };
793
- this.logExporter = new (0, _exporterlogsotlphttp.OTLPLogExporter)({
794
- url: logsUrl,
795
- headers
796
- });
797
- _chunkWC573FCIcjs.logger.debug("OTLP log exporter initialized successfully");
798
- }
799
- /**
800
- * Initialize the log processor with masking support
801
- */
802
- initLogProcessor(config) {
803
- if (this.logProcessor) {
804
- _chunkWC573FCIcjs.logger.debug("Log processor already initialized, skipping re-initialization");
805
- return;
806
- }
807
- if (!this.logExporter) {
808
- throw new Error("Log exporter must be initialized before processor");
809
- }
810
- _chunkWC573FCIcjs.logger.debug("Initializing log processor", {
811
- disableBatch: config.disableBatch,
812
- hasMasking: !!_optionalChain([config, 'access', _35 => _35.masking, 'optionalAccess', _36 => _36.eventMasking])
813
- });
814
- this.logProcessor = config.disableBatch ? new BrizzSimpleLogRecordProcessor(this.logExporter, config) : new BrizzBatchLogRecordProcessor(this.logExporter, config);
815
- _chunkWC573FCIcjs.logger.debug("Log processor initialized successfully");
816
- }
817
- /**
818
- * Initialize the logger provider
819
- */
820
- initLoggerProvider(config) {
821
- if (this.loggerProvider) {
822
- _chunkWC573FCIcjs.logger.debug("Logger provider already initialized, skipping re-initialization");
823
- return;
824
- }
825
- if (!this.logProcessor) {
826
- throw new Error("Log processor must be initialized before logger provider");
827
- }
828
- _chunkWC573FCIcjs.logger.debug("Creating resource with service name", {
829
- serviceName: config.appName
830
- });
831
- const resourceAttributes = {
832
- ...config.resourceAttributes,
833
- "service.name": config.appName,
834
- [BRIZZ_SDK_VERSION]: _chunk2DSTZTDAcjs.getSDKVersion.call(void 0, ),
835
- [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
836
- };
837
- if (config.environment) {
838
- resourceAttributes["deployment.environment"] = config.environment;
839
- }
840
- if (config.appVersion) {
841
- resourceAttributes["service.version"] = config.appVersion;
842
- }
843
- const resource = _resources.resourceFromAttributes.call(void 0, resourceAttributes);
844
- _chunkWC573FCIcjs.logger.debug("Creating logger provider with resource");
845
- this.loggerProvider = new (0, _sdklogs.LoggerProvider)({
846
- resource,
847
- processors: [this.logProcessor]
848
- });
849
- _chunkWC573FCIcjs.logger.debug("Logger provider initialization completed");
850
- }
851
- /**
852
- * Initialize the logging module with the provided configuration
853
- */
854
- setup(config) {
855
- _chunkWC573FCIcjs.logger.info("Setting up logging module");
856
- this.initLogExporter(config);
857
- this.initLogProcessor(config);
858
- this.initLoggerProvider(config);
859
- _LoggingModule.instance = this;
860
- _chunkWC573FCIcjs.logger.info("Logging module setup completed");
861
- }
862
- /**
863
- * Emit a custom event to the telemetry pipeline
864
- */
865
- emitEvent(name, attributes, body, severityNumber = _apilogs.SeverityNumber.INFO) {
866
- _chunkWC573FCIcjs.logger.debug("Attempting to emit event", {
867
- name,
868
- hasAttributes: !!attributes,
869
- attributesCount: attributes ? Object.keys(attributes).length : 0,
870
- hasBody: !!body,
871
- severityNumber
872
- });
873
- if (!this.loggerProvider) {
874
- _chunkWC573FCIcjs.logger.error("Cannot emit event: Logger provider not initialized");
875
- throw new Error("Logging module not initialized");
876
- }
877
- const logAttributes = { "event.name": name };
878
- if (attributes) {
879
- Object.assign(logAttributes, attributes);
880
- _chunkWC573FCIcjs.logger.debug("Combined log attributes", { attributes: Object.keys(logAttributes) });
881
- }
882
- _chunkWC573FCIcjs.logger.debug("Getting logger instance for brizz_events");
883
- const eventLogger = this.loggerProvider.getLogger("brizz.events");
884
- _chunkWC573FCIcjs.logger.debug("Emitting log record with eventName", { eventName: name });
885
- try {
886
- eventLogger.emit({
887
- eventName: name,
888
- attributes: logAttributes,
889
- severityNumber,
890
- body
891
- });
892
- _chunkWC573FCIcjs.logger.debug("Event successfully emitted", { eventName: name });
893
- } catch (error) {
894
- _chunkWC573FCIcjs.logger.error(`Failed to emit event '${name}'`, { error, eventName: name });
895
- _chunkWC573FCIcjs.logger.error("Log record that failed", {
896
- eventName: name,
897
- hasAttributes: logAttributes,
898
- severityNumber,
899
- hasBody: body
900
- });
901
- throw error instanceof Error ? error : new Error(String(error));
902
- }
903
- }
904
- /**
905
- * Check if the module is initialized
906
- */
907
- isInitialized() {
908
- return this.loggerProvider !== null;
909
- }
910
- /**
911
- * Get the logger provider
912
- */
913
- getLoggerProvider() {
914
- return this.loggerProvider;
915
- }
916
- /**
917
- * Shutdown the logging module
918
- */
919
- async shutdown() {
920
- _chunkWC573FCIcjs.logger.debug("Shutting down logging module");
921
- if (this.loggerProvider) {
922
- await this.loggerProvider.shutdown();
923
- this.loggerProvider = null;
924
- }
925
- this.logProcessor = null;
926
- this.logExporter = null;
927
- if (_LoggingModule.instance === this) {
928
- _LoggingModule.instance = null;
929
- }
930
- _chunkWC573FCIcjs.logger.debug("Logging module shutdown completed");
931
- }
932
- }, _class2.__initStatic(), _class2);
933
- function emitEvent(name, attributes, body, severityNumber = _apilogs.SeverityNumber.INFO) {
934
- return LoggingModule.getInstance().emitEvent(name, attributes, body, severityNumber);
935
- }
936
- function emitEventWithSessionId(sessionId, name, attributes, body, severityNumber = _apilogs.SeverityNumber.INFO) {
937
- return callWithSessionId(sessionId, () => {
938
- LoggingModule.getInstance().emitEvent(name, attributes, body, severityNumber);
939
- });
940
- }
941
-
942
- // src/internal/trace/session.ts
943
- function setCurrentSpanCustomProperties(properties) {
944
- const current = _api.trace.getActiveSpan();
945
- if (!current || !current.isRecording()) {
946
- return;
947
- }
948
- for (const [key, value] of Object.entries(properties)) {
949
- try {
950
- current.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${key}`, value);
951
- } catch (e) {
952
- }
953
- }
954
- }
955
- function callWithProperties(properties, fn, thisArg, ...args) {
956
- const base = _api.context.active();
957
- const prev = base.getValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY);
958
- const merged = prev ? { ...prev, ...properties } : properties;
959
- const next = base.setValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY, merged);
960
- return _api.context.with(next, fn, thisArg, ...args);
961
- }
962
- function withProperties(properties, fn, thisArg) {
963
- return function wrapped(...args) {
964
- return callWithProperties(
965
- properties,
966
- fn,
967
- thisArg !== void 0 ? thisArg : this,
968
- ...args
969
- );
970
- };
971
- }
972
- function propagatePropertiesImperatively(properties) {
973
- try {
974
- const manager = _api.context;
975
- const mgr = _optionalChain([manager, 'access', _37 => _37._getContextManager, 'optionalCall', _38 => _38()]);
976
- const store = _optionalChain([mgr, 'optionalAccess', _39 => _39._asyncLocalStorage]);
977
- if (!store || typeof store.enterWith !== "function") {
978
- return;
979
- }
980
- const base = _api.context.active();
981
- const prev = base.getValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY);
982
- const merged = prev ? { ...prev, ...properties } : properties;
983
- store.enterWith(base.setValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY, merged));
984
- } catch (e2) {
985
- }
986
- }
987
- function setUser(user) {
988
- const properties = { [_chunk77UGZGMPcjs.USER_ID]: user.id };
989
- if (user.email !== void 0) {
990
- properties[_chunk77UGZGMPcjs.USER_EMAIL] = user.email;
991
- }
992
- if (user.name !== void 0) {
993
- properties[_chunk77UGZGMPcjs.USER_NAME] = user.name;
994
- }
995
- if (user.role !== void 0) {
996
- properties[_chunk77UGZGMPcjs.USER_ROLE] = user.role;
997
- }
998
- if (user.plan !== void 0) {
999
- properties[_chunk77UGZGMPcjs.USER_PLAN] = user.plan;
1000
- }
1001
- if (user.traits) {
1002
- for (const [key, value] of Object.entries(user.traits)) {
1003
- const k = `user.${key}`;
1004
- if (properties[k] === void 0) {
1005
- properties[k] = value;
1006
- }
1007
- }
1008
- }
1009
- setCurrentSpanCustomProperties(properties);
1010
- propagatePropertiesImperatively(properties);
1011
- }
1012
- function setOrganization(org) {
1013
- const properties = { [_chunk77UGZGMPcjs.ORGANIZATION_ID]: org.id };
1014
- if (org.name !== void 0) {
1015
- properties[_chunk77UGZGMPcjs.ORGANIZATION_NAME] = org.name;
1016
- }
1017
- if (org.plan !== void 0) {
1018
- properties[_chunk77UGZGMPcjs.ORGANIZATION_PLAN] = org.plan;
1019
- }
1020
- if (org.domain !== void 0) {
1021
- properties[_chunk77UGZGMPcjs.ORGANIZATION_DOMAIN] = org.domain;
1022
- }
1023
- if (org.traits) {
1024
- for (const [key, value] of Object.entries(org.traits)) {
1025
- const k = `organization.${key}`;
1026
- if (properties[k] === void 0) {
1027
- properties[k] = value;
1028
- }
1029
- }
1030
- }
1031
- setCurrentSpanCustomProperties(properties);
1032
- propagatePropertiesImperatively(properties);
1033
- }
1034
- function setMessageId(id) {
1035
- const properties = { [_chunk77UGZGMPcjs.MESSAGE_ID]: id };
1036
- setCurrentSpanCustomProperties(properties);
1037
- propagatePropertiesImperatively(properties);
1038
- }
1039
- function userProperties(user) {
1040
- const properties = { [_chunk77UGZGMPcjs.USER_ID]: user.id };
1041
- if (user.email !== void 0) {
1042
- properties[_chunk77UGZGMPcjs.USER_EMAIL] = user.email;
1043
- }
1044
- if (user.name !== void 0) {
1045
- properties[_chunk77UGZGMPcjs.USER_NAME] = user.name;
1046
- }
1047
- if (user.role !== void 0) {
1048
- properties[_chunk77UGZGMPcjs.USER_ROLE] = user.role;
1049
- }
1050
- if (user.plan !== void 0) {
1051
- properties[_chunk77UGZGMPcjs.USER_PLAN] = user.plan;
1052
- }
1053
- if (user.traits) {
1054
- for (const [key, value] of Object.entries(user.traits)) {
1055
- const k = `user.${key}`;
1056
- if (properties[k] === void 0) {
1057
- properties[k] = value;
1058
- }
1059
- }
1060
- }
1061
- return properties;
1062
- }
1063
- function organizationProperties(org) {
1064
- const properties = { [_chunk77UGZGMPcjs.ORGANIZATION_ID]: org.id };
1065
- if (org.name !== void 0) {
1066
- properties[_chunk77UGZGMPcjs.ORGANIZATION_NAME] = org.name;
1067
- }
1068
- if (org.plan !== void 0) {
1069
- properties[_chunk77UGZGMPcjs.ORGANIZATION_PLAN] = org.plan;
1070
- }
1071
- if (org.domain !== void 0) {
1072
- properties[_chunk77UGZGMPcjs.ORGANIZATION_DOMAIN] = org.domain;
1073
- }
1074
- if (org.traits) {
1075
- for (const [key, value] of Object.entries(org.traits)) {
1076
- const k = `organization.${key}`;
1077
- if (properties[k] === void 0) {
1078
- properties[k] = value;
1079
- }
1080
- }
1081
- }
1082
- return properties;
1083
- }
1084
- function callWithUser(user, fn, thisArg, ...args) {
1085
- return callWithProperties(userProperties(user), fn, thisArg, ...args);
1086
- }
1087
- function withUser(user, fn, thisArg) {
1088
- return withProperties(userProperties(user), fn, thisArg);
1089
- }
1090
- function callWithOrganization(org, fn, thisArg, ...args) {
1091
- return callWithProperties(organizationProperties(org), fn, thisArg, ...args);
1092
- }
1093
- function withOrganization(org, fn, thisArg) {
1094
- return withProperties(organizationProperties(org), fn, thisArg);
1095
- }
1096
- function callWithMessageId(id, fn, thisArg, ...args) {
1097
- return callWithProperties({ [_chunk77UGZGMPcjs.MESSAGE_ID]: id }, fn, thisArg, ...args);
1098
- }
1099
- function withMessageId(id, fn, thisArg) {
1100
- return withProperties({ [_chunk77UGZGMPcjs.MESSAGE_ID]: id }, fn, thisArg);
1101
- }
1102
- function inheritedMuteTools() {
1103
- const properties = _api.context.active().getValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY);
1104
- return _optionalChain([properties, 'optionalAccess', _40 => _40[_chunk77UGZGMPcjs.MUTE_TOOLS]]);
1105
- }
1106
- function muteProperties(options) {
1107
- const { input = true, output = true, tools = output } = options;
1108
- const properties = {};
1109
- if (input) {
1110
- properties[_chunk77UGZGMPcjs.MUTE_INPUT] = "true";
1111
- }
1112
- if (output) {
1113
- properties[_chunk77UGZGMPcjs.MUTE_OUTPUT] = "true";
1114
- }
1115
- if (tools !== output) {
1116
- properties[_chunk77UGZGMPcjs.MUTE_TOOLS] = String(tools);
1117
- } else {
1118
- const inherited = inheritedMuteTools();
1119
- if (tools && inherited === "false") {
1120
- properties[_chunk77UGZGMPcjs.MUTE_TOOLS] = "true";
1121
- } else if (options.tools === false && inherited === "true") {
1122
- properties[_chunk77UGZGMPcjs.MUTE_TOOLS] = "false";
1123
- }
1124
- }
1125
- return properties;
1126
- }
1127
- function callWithMute(options, fn, thisArg, ...args) {
1128
- return callWithProperties(muteProperties(options), fn, thisArg, ...args);
1129
- }
1130
- function withMute(options, fn, thisArg) {
1131
- return withProperties(muteProperties(options), fn, thisArg);
1132
- }
1133
- function withSessionId(sessionId, fn, thisArg, extraProperties) {
1134
- const properties = { [_chunk77UGZGMPcjs.SESSION_ID]: sessionId, ...extraProperties };
1135
- return withProperties(properties, fn, thisArg);
1136
- }
1137
- function callWithSessionId(sessionId, fn, thisArg, ...args) {
1138
- return callWithProperties({ [_chunk77UGZGMPcjs.SESSION_ID]: sessionId }, fn, thisArg, ...args);
1139
- }
1140
- var Session = (_class3 = class {
1141
-
1142
- __init5() {this.inputs = []}
1143
- __init6() {this.outputs = []}
1144
- __init7() {this.inputContexts = []}
1145
- __init8() {this.outputContexts = []}
1146
-
1147
- constructor(sessionId, span) {;_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);
1148
- this.sessionId = sessionId;
1149
- this.span = span;
1150
- }
1151
- /**
1152
- * Append a user turn to session input tracking.
1153
- *
1154
- * Each call appends one element to `brizz.session.input` (the text) AND one
1155
- * element to `brizz.session.input.context` (the per-turn context bag). The
1156
- * two arrays stay index-aligned — the ingestion pipeline zips them together
1157
- * so the i-th context bag lands on the i-th user_display conversation item's
1158
- * `span_attributes` map.
1159
- *
1160
- * @param text - Text to append (null becomes a null/"hide marker")
1161
- * @param context - Optional per-turn context bag to attach to this turn
1162
- */
1163
- setInput(text, context4) {
1164
- this.inputs.push(text);
1165
- this.inputContexts.push(_nullishCoalesce(context4, () => ( {})));
1166
- this.span.setAttribute(_chunk77UGZGMPcjs.SESSION_INPUT, JSON.stringify(this.inputs));
1167
- this.span.setAttribute(_chunk77UGZGMPcjs.SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
1168
- }
1169
- /**
1170
- * Append an assistant turn to session output tracking.
1171
- *
1172
- * Symmetric to {@link setInput} — appends one text element and one
1173
- * context-bag element to the index-aligned `brizz.session.output` /
1174
- * `brizz.session.output.context` arrays.
1175
- *
1176
- * @param text - Text to append (null becomes a null/"hide marker")
1177
- * @param context - Optional per-turn context bag to attach to this turn
1178
- */
1179
- setOutput(text, context4) {
1180
- this.outputs.push(text);
1181
- this.outputContexts.push(_nullishCoalesce(context4, () => ( {})));
1182
- this.span.setAttribute(_chunk77UGZGMPcjs.SESSION_OUTPUT, JSON.stringify(this.outputs));
1183
- this.span.setAttribute(_chunk77UGZGMPcjs.SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
1184
- }
1185
- /**
1186
- * Set the session title on the span.
1187
- *
1188
- * @param title - The generated title string
1189
- */
1190
- setTitle(title) {
1191
- this.span.setAttribute(_chunk77UGZGMPcjs.SESSION_TITLE, title);
1192
- }
1193
- /**
1194
- * Update custom properties on the session span.
1195
- * Properties are prefixed with 'brizz.'.
1196
- *
1197
- * @param properties - Key-value properties to set on the session
1198
- */
1199
- updateProperties(properties) {
1200
- for (const [key, value] of Object.entries(properties)) {
1201
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${key}`, value);
1202
- }
1203
- }
1204
- /**
1205
- * Set end-user identity on the session span: `brizz.user.id` and, when
1206
- * provided, `brizz.user.email` / `brizz.user.name`. Undefined fields are omitted.
1207
- *
1208
- * @param user - User identity (`id` required; `email` / `name` optional)
1209
- */
1210
- setUser(user) {
1211
- if (user.traits) {
1212
- for (const [key, value] of Object.entries(user.traits)) {
1213
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.user.${key}`, value);
1214
- }
1215
- }
1216
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.USER_ID}`, user.id);
1217
- if (user.email !== void 0) {
1218
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.USER_EMAIL}`, user.email);
1219
- }
1220
- if (user.name !== void 0) {
1221
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.USER_NAME}`, user.name);
1222
- }
1223
- if (user.role !== void 0) {
1224
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.USER_ROLE}`, user.role);
1225
- }
1226
- if (user.plan !== void 0) {
1227
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.USER_PLAN}`, user.plan);
1228
- }
1229
- }
1230
- /**
1231
- * Set organization identity on the session span: `brizz.organization.id` and,
1232
- * when provided, `brizz.organization.name`. Undefined fields are omitted.
1233
- *
1234
- * @param org - Organization identity (`id` required; `name` optional)
1235
- */
1236
- setOrganization(org) {
1237
- if (org.traits) {
1238
- for (const [key, value] of Object.entries(org.traits)) {
1239
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.organization.${key}`, value);
1240
- }
1241
- }
1242
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.ORGANIZATION_ID}`, org.id);
1243
- if (org.name !== void 0) {
1244
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.ORGANIZATION_NAME}`, org.name);
1245
- }
1246
- if (org.plan !== void 0) {
1247
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.ORGANIZATION_PLAN}`, org.plan);
1248
- }
1249
- if (org.domain !== void 0) {
1250
- this.span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.ORGANIZATION_DOMAIN}`, org.domain);
1251
- }
1252
- }
1253
- /**
1254
- * Attach an external link (URL) to this session.
1255
- *
1256
- * The link surfaces on the session's detail panel in Brizz — use it to
1257
- * correlate a session with an external record such as a Datadog trace,
1258
- * Sentry issue, or internal dashboard. Re-sending the same URL is idempotent;
1259
- * distinct URLs add separate links.
1260
- *
1261
- * @param url - The link target
1262
- * @param options - Optional `title` (defaults to the URL host) and `linkType`
1263
- * (free-form category, defaults to `'generic'`)
1264
- */
1265
- addExternalLink(url, options) {
1266
- emitExternalLink(this.sessionId, url, _optionalChain([options, 'optionalAccess', _41 => _41.title]), _optionalChain([options, 'optionalAccess', _42 => _42.linkType]));
1267
- }
1268
- }, _class3);
1269
- var SessionTitle = class {
1270
-
1271
- constructor(span) {
1272
- this.span = span;
1273
- }
1274
- /**
1275
- * Set the generated title on the wrapper span.
1276
- *
1277
- * @param title - The generated title string
1278
- */
1279
- setTitle(title) {
1280
- this.span.setAttribute(_chunk77UGZGMPcjs.SESSION_TITLE, title);
1281
- }
1282
- };
1283
- function getActiveSession() {
1284
- return _api.context.active().getValue(_chunk77UGZGMPcjs.SESSION_OBJECT_CONTEXT_KEY);
1285
- }
1286
- function resolveSessionIdFromContext() {
1287
- const active = getActiveSession();
1288
- if (active) {
1289
- return active.sessionId;
1290
- }
1291
- const props = _api.context.active().getValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY);
1292
- return _optionalChain([props, 'optionalAccess', _43 => _43[_chunk77UGZGMPcjs.SESSION_ID]]);
1293
- }
1294
- function resolveMessageIdFromContext() {
1295
- const props = _api.context.active().getValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY);
1296
- return _optionalChain([props, 'optionalAccess', _44 => _44[_chunk77UGZGMPcjs.MESSAGE_ID]]);
1297
- }
1298
- function emitExternalLink(sessionId, url, title, linkType) {
1299
- try {
1300
- emitEventWithSessionId(sessionId, _chunk77UGZGMPcjs.EXTERNAL_LINK_EVENT_NAME, {
1301
- [_chunk77UGZGMPcjs.EXTERNAL_LINK_URL]: url,
1302
- [_chunk77UGZGMPcjs.EXTERNAL_LINK_TITLE]: _nullishCoalesce(title, () => ( "")),
1303
- [_chunk77UGZGMPcjs.EXTERNAL_LINK_TYPE]: _nullishCoalesce(linkType, () => ( "generic"))
1304
- });
1305
- } catch (error) {
1306
- _chunkWC573FCIcjs.logger.warn("addExternalLink: failed to emit external link", error);
1307
- }
1308
- }
1309
- function addExternalLink(url, options) {
1310
- const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _45 => _45.sessionId]), () => ( resolveSessionIdFromContext()));
1311
- if (!sessionId) {
1312
- _chunkWC573FCIcjs.logger.warn(
1313
- "addExternalLink called without a resolvable session id; link dropped. Pass options.sessionId or call inside a startSession/callWithSessionId scope."
1314
- );
1315
- return;
1316
- }
1317
- emitExternalLink(sessionId, url, _optionalChain([options, 'optionalAccess', _46 => _46.title]), _optionalChain([options, 'optionalAccess', _47 => _47.linkType]));
1318
- }
1319
- function recordFeedback(type, options) {
1320
- const eventAttributes = { [_chunk77UGZGMPcjs.FEEDBACK_TYPE]: type };
1321
- if (_optionalChain([options, 'optionalAccess', _48 => _48.score]) !== void 0) {
1322
- eventAttributes[_chunk77UGZGMPcjs.FEEDBACK_SCORE] = options.score;
1323
- }
1324
- if (_optionalChain([options, 'optionalAccess', _49 => _49.reason]) !== void 0) {
1325
- eventAttributes[_chunk77UGZGMPcjs.FEEDBACK_REASON] = options.reason;
1326
- }
1327
- if (_optionalChain([options, 'optionalAccess', _50 => _50.comment]) !== void 0) {
1328
- eventAttributes[_chunk77UGZGMPcjs.FEEDBACK_COMMENT] = options.comment;
1329
- }
1330
- if (_optionalChain([options, 'optionalAccess', _51 => _51.source]) !== void 0) {
1331
- eventAttributes[_chunk77UGZGMPcjs.FEEDBACK_SOURCE] = options.source;
1332
- }
1333
- if (_optionalChain([options, 'optionalAccess', _52 => _52.attributes])) {
1334
- for (const [key, value] of Object.entries(options.attributes)) {
1335
- const k = `${_chunk77UGZGMPcjs.FEEDBACK_ATTR_PREFIX}${key}`;
1336
- if (eventAttributes[k] === void 0) {
1337
- eventAttributes[k] = value;
1338
- }
1339
- }
1340
- }
1341
- const messageId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _53 => _53.messageId]), () => ( resolveMessageIdFromContext()));
1342
- const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _54 => _54.sessionId]), () => ( resolveSessionIdFromContext()));
1343
- if (messageId === void 0 && sessionId === void 0) {
1344
- _chunkWC573FCIcjs.logger.warn(
1345
- "recordFeedback called with no resolvable message id or session id; the feedback cannot be attributed to a message or conversation. Pass options.messageId / options.sessionId or call inside a startSession/callWithMessageId scope."
1346
- );
1347
- }
1348
- const anchor = {};
1349
- if (messageId !== void 0) {
1350
- anchor[_chunk77UGZGMPcjs.MESSAGE_ID] = messageId;
1351
- }
1352
- if (sessionId !== void 0) {
1353
- anchor[_chunk77UGZGMPcjs.SESSION_ID] = sessionId;
1354
- }
1355
- try {
1356
- if (Object.keys(anchor).length === 0) {
1357
- emitEvent(_chunk77UGZGMPcjs.FEEDBACK_EVENT_NAME, eventAttributes);
1358
- } else {
1359
- callWithProperties(anchor, () => emitEvent(_chunk77UGZGMPcjs.FEEDBACK_EVENT_NAME, eventAttributes));
1360
- }
1361
- } catch (error) {
1362
- _chunkWC573FCIcjs.logger.warn("recordFeedback: failed to emit feedback event", error);
1363
- }
1364
- }
1365
- var METRIC_NAME_PATTERN = /^[a-z][a-z0-9_.-]{0,63}$/;
1366
- var METRIC_COMMENT_MAX_LEN = 4096;
1367
- var METRIC_ATTRIBUTES_MAX = 20;
1368
- var METRIC_ATTRIBUTE_VALUE_MAX_LEN = 256;
1369
- function recordMetric(options) {
1370
- try {
1371
- recordMetricImpl(options);
1372
- } catch (error) {
1373
- _chunkWC573FCIcjs.logger.warn(`recordMetric(${JSON.stringify(_optionalChain([options, 'optionalAccess', _55 => _55.name]))}) failed; metric dropped.`, error);
1374
- }
1375
- }
1376
- function recordMetricImpl(options) {
1377
- const name = typeof options.name === "string" ? options.name.toLowerCase() : "";
1378
- if (!METRIC_NAME_PATTERN.test(name)) {
1379
- _chunkWC573FCIcjs.logger.warn(
1380
- `recordMetric called with an invalid name ${JSON.stringify(options.name)}; metric dropped. Names must match ${METRIC_NAME_PATTERN.source} after lowercasing.`
1381
- );
1382
- return;
1383
- }
1384
- if (_chunk77UGZGMPcjs.RESERVED_METRIC_NAMES.has(name)) {
1385
- _chunkWC573FCIcjs.logger.warn(
1386
- `recordMetric called with the reserved name ${JSON.stringify(name)}; metric dropped. Brizz computes this metric itself \u2014 pick a different name.`
1387
- );
1388
- return;
1389
- }
1390
- const { value } = options;
1391
- let numericValue;
1392
- if (typeof value === "boolean") {
1393
- numericValue = value ? 1 : 0;
1394
- } else if (typeof value === "number" && Number.isFinite(value)) {
1395
- numericValue = value;
1396
- } else {
1397
- _chunkWC573FCIcjs.logger.warn(
1398
- `recordMetric(${name}) called with a non-finite or non-numeric value ${JSON.stringify(value)}; metric dropped.`
1399
- );
1400
- return;
1401
- }
1402
- const eventAttributes = {
1403
- [_chunk77UGZGMPcjs.METRIC_NAME]: name,
1404
- [_chunk77UGZGMPcjs.METRIC_VALUE]: numericValue
1405
- };
1406
- if (options.unit !== void 0) {
1407
- eventAttributes[_chunk77UGZGMPcjs.METRIC_UNIT] = options.unit;
1408
- }
1409
- if (options.minValue !== void 0) {
1410
- eventAttributes[_chunk77UGZGMPcjs.METRIC_MIN] = options.minValue;
1411
- }
1412
- if (options.maxValue !== void 0) {
1413
- eventAttributes[_chunk77UGZGMPcjs.METRIC_MAX] = options.maxValue;
1414
- }
1415
- if (options.comment !== void 0) {
1416
- let comment = options.comment;
1417
- if (comment.length > METRIC_COMMENT_MAX_LEN) {
1418
- _chunkWC573FCIcjs.logger.warn(
1419
- `recordMetric(${name}) comment exceeds ${METRIC_COMMENT_MAX_LEN} characters; truncated.`
1420
- );
1421
- comment = comment.slice(0, METRIC_COMMENT_MAX_LEN);
1422
- }
1423
- eventAttributes[_chunk77UGZGMPcjs.METRIC_COMMENT] = comment;
1424
- }
1425
- if (options.polarity !== void 0) {
1426
- const polarity = options.polarity;
1427
- if (polarity === _chunk77UGZGMPcjs.METRIC_POLARITY_POSITIVE || polarity === _chunk77UGZGMPcjs.METRIC_POLARITY_NEGATIVE) {
1428
- eventAttributes[_chunk77UGZGMPcjs.METRIC_POLARITY] = polarity;
1429
- } else {
1430
- _chunkWC573FCIcjs.logger.warn(
1431
- `recordMetric(${name}) called with an invalid polarity ${JSON.stringify(polarity)}; expected '${_chunk77UGZGMPcjs.METRIC_POLARITY_POSITIVE}' or '${_chunk77UGZGMPcjs.METRIC_POLARITY_NEGATIVE}'. Emitting the metric without it.`
1432
- );
1433
- }
1434
- }
1435
- if (options.timestamp !== void 0) {
1436
- if (Number.isFinite(options.timestamp.getTime())) {
1437
- eventAttributes[_chunk77UGZGMPcjs.METRIC_TIMESTAMP] = options.timestamp.toISOString();
1438
- } else {
1439
- _chunkWC573FCIcjs.logger.warn(
1440
- `recordMetric(${name}) called with an invalid timestamp; emitting the metric without it.`
1441
- );
1442
- }
1443
- }
1444
- if (options.attributes) {
1445
- let accepted = 0;
1446
- for (const [key, attrValue] of Object.entries(options.attributes)) {
1447
- if (accepted >= METRIC_ATTRIBUTES_MAX) {
1448
- _chunkWC573FCIcjs.logger.warn(
1449
- `recordMetric(${name}) called with more than ${METRIC_ATTRIBUTES_MAX} attributes; the excess was dropped.`
1450
- );
1451
- break;
1452
- }
1453
- const normalizedKey = key.toLowerCase();
1454
- if (!METRIC_NAME_PATTERN.test(normalizedKey)) {
1455
- _chunkWC573FCIcjs.logger.warn(
1456
- `recordMetric(${name}) called with an invalid attribute key ${JSON.stringify(key)}; that attribute was dropped. Keys must match ${METRIC_NAME_PATTERN.source} after lowercasing.`
1457
- );
1458
- continue;
1459
- }
1460
- let text = typeof attrValue === "string" ? attrValue : String(attrValue);
1461
- if (text.length > METRIC_ATTRIBUTE_VALUE_MAX_LEN) {
1462
- _chunkWC573FCIcjs.logger.warn(
1463
- `recordMetric(${name}) attribute ${JSON.stringify(normalizedKey)} exceeds ${METRIC_ATTRIBUTE_VALUE_MAX_LEN} characters; truncated.`
1464
- );
1465
- text = text.slice(0, METRIC_ATTRIBUTE_VALUE_MAX_LEN);
1466
- }
1467
- eventAttributes[`${_chunk77UGZGMPcjs.METRIC_ATTRIBUTE_PREFIX}${normalizedKey}`] = text;
1468
- accepted += 1;
1469
- }
1470
- }
1471
- const sessionId = _nullishCoalesce(options.sessionId, () => ( resolveSessionIdFromContext()));
1472
- if (sessionId === void 0) {
1473
- _chunkWC573FCIcjs.logger.warn(
1474
- `recordMetric(${name}) called with no resolvable session id; the metric cannot be attributed to a conversation and is dropped. Pass options.sessionId or call inside a startSession/callWithSessionId scope.`
1475
- );
1476
- return;
1477
- }
1478
- try {
1479
- callWithProperties(
1480
- { [_chunk77UGZGMPcjs.SESSION_ID]: sessionId },
1481
- () => emitEvent(_chunk77UGZGMPcjs.METRIC_EVENT_NAME, eventAttributes)
1482
- );
1483
- } catch (error) {
1484
- _chunkWC573FCIcjs.logger.warn("recordMetric: failed to emit metric event", error);
1485
- }
1486
- }
1487
- function startSession(sessionId, callback, extraProperties, options) {
1488
- const isTitle = _optionalChain([options, 'optionalAccess', _56 => _56.mode]) === "title";
1489
- const spanName = isTitle ? _chunk77UGZGMPcjs.SESSION_TITLE_SPAN_NAME : _chunk77UGZGMPcjs.SESSION_SPAN_NAME;
1490
- const tracer = _api.trace.getTracer("@brizz/sdk");
1491
- return tracer.startActiveSpan(spanName, (span) => {
1492
- span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.SESSION_ID}`, sessionId);
1493
- if (extraProperties) {
1494
- for (const [key, value] of Object.entries(extraProperties)) {
1495
- span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${key}`, value);
1496
- }
1497
- }
1498
- const session = new Session(sessionId, span);
1499
- const contextProperties = { [_chunk77UGZGMPcjs.SESSION_ID]: sessionId };
1500
- if (isTitle) {
1501
- contextProperties[_chunk77UGZGMPcjs.SESSION_TITLE_GENERATION] = "true";
1502
- }
1503
- if (extraProperties) {
1504
- for (const [key, value] of Object.entries(extraProperties)) {
1505
- contextProperties[key] = String(value);
1506
- }
1507
- }
1508
- return callWithProperties(contextProperties, () => {
1509
- const sessionCtx = _api.context.active().setValue(_chunk77UGZGMPcjs.SESSION_OBJECT_CONTEXT_KEY, session);
1510
- return _api.context.with(sessionCtx, () => {
1511
- try {
1512
- const result = callback(session);
1513
- if (result && typeof result.then === "function") {
1514
- return result.then((value) => {
1515
- span.end();
1516
- return value;
1517
- }).catch((error) => {
1518
- span.recordException(error);
1519
- span.setStatus({ code: _api.SpanStatusCode.ERROR });
1520
- span.end();
1521
- throw error;
1522
- });
1523
- }
1524
- span.end();
1525
- return result;
1526
- } catch (error) {
1527
- span.recordException(error);
1528
- span.setStatus({ code: _api.SpanStatusCode.ERROR });
1529
- span.end();
1530
- throw error;
1531
- }
1532
- });
1533
- });
1534
- });
1535
- }
1536
- function startSessionTitle(callback, options) {
1537
- const resolvedSessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _57 => _57.sessionId]), () => ( _optionalChain([getActiveSession, 'call', _58 => _58(), 'optionalAccess', _59 => _59.sessionId])));
1538
- const tracer = _api.trace.getTracer("@brizz/sdk");
1539
- return tracer.startActiveSpan(_chunk77UGZGMPcjs.SESSION_TITLE_SPAN_NAME, (span) => {
1540
- if (resolvedSessionId) {
1541
- span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${_chunk77UGZGMPcjs.SESSION_ID}`, resolvedSessionId);
1542
- }
1543
- const sessionTitle = new SessionTitle(span);
1544
- const properties = { [_chunk77UGZGMPcjs.SESSION_TITLE_GENERATION]: "true" };
1545
- if (resolvedSessionId) {
1546
- properties[_chunk77UGZGMPcjs.SESSION_ID] = resolvedSessionId;
1547
- }
1548
- return callWithProperties(properties, () => {
1549
- try {
1550
- const result = callback(sessionTitle);
1551
- if (result && typeof result.then === "function") {
1552
- return result.then((value) => {
1553
- span.end();
1554
- return value;
1555
- }).catch((error) => {
1556
- span.recordException(error);
1557
- span.setStatus({ code: _api.SpanStatusCode.ERROR });
1558
- span.end();
1559
- throw error;
1560
- });
1561
- }
1562
- span.end();
1563
- return result;
1564
- } catch (error) {
1565
- span.recordException(error);
1566
- span.setStatus({ code: _api.SpanStatusCode.ERROR });
1567
- span.end();
1568
- throw error;
1569
- }
1570
- });
1571
- });
1572
- }
1573
-
1574
- // src/internal/metric/metrics.ts
1575
- var _exportermetricsotlphttp = require('@opentelemetry/exporter-metrics-otlp-http');
1576
- var _sdkmetrics = require('@opentelemetry/sdk-metrics');
1577
- var MetricsModule = (_class4 = class _MetricsModule {constructor() { _class4.prototype.__init9.call(this);_class4.prototype.__init10.call(this); }
1578
- static __initStatic2() {this.instance = null}
1579
- static getInstance() {
1580
- if (!this.instance) {
1581
- throw new Error("Brizz must be initialized before accessing MetricsModule");
1582
- }
1583
- return this.instance;
1584
- }
1585
- __init9() {this.metricsExporter = null}
1586
- __init10() {this.metricsReader = null}
1587
- /**
1588
- * Initialize the metrics exporter
1589
- */
1590
- initMetricsExporter(config) {
1591
- if (this.metricsExporter) {
1592
- _chunkWC573FCIcjs.logger.debug("Metrics exporter already initialized, skipping re-initialization");
1593
- return;
1594
- }
1595
- const metricsUrl = config.baseUrl.replace(/\/$/, "") + "/v1/metrics";
1596
- _chunkWC573FCIcjs.logger.debug("Initializing metrics exporter", { url: metricsUrl });
1597
- this.metricsExporter = new (0, _exportermetricsotlphttp.OTLPMetricExporter)({
1598
- url: metricsUrl,
1599
- headers: config.headers
1600
- });
1601
- _chunkWC573FCIcjs.logger.debug("Metrics exporter initialized successfully");
1602
- }
1603
- /**
1604
- * Initialize the metrics reader
1605
- */
1606
- initMetricsReader(config) {
1607
- if (this.metricsReader) {
1608
- _chunkWC573FCIcjs.logger.debug("Metrics reader already initialized, skipping re-initialization");
1609
- return;
1610
- }
1611
- if (config.customMetricReader) {
1612
- _chunkWC573FCIcjs.logger.debug("Using custom metric reader");
1613
- this.metricsReader = config.customMetricReader;
1614
- _chunkWC573FCIcjs.logger.debug("Custom metric reader initialized successfully");
1615
- return;
1616
- }
1617
- _chunkWC573FCIcjs.logger.debug(
1618
- "Using default metrics flow - creating OTLP exporter and PeriodicExportingMetricReader"
1619
- );
1620
- this.initMetricsExporter(config);
1621
- if (!this.metricsExporter) {
1622
- throw new Error("Failed to initialize metrics exporter");
1623
- }
1624
- this.metricsReader = new (0, _sdkmetrics.PeriodicExportingMetricReader)({
1625
- exporter: this.metricsExporter
1626
- });
1627
- _chunkWC573FCIcjs.logger.debug("Default metrics reader initialized successfully");
1628
- }
1629
- /**
1630
- * Initialize the metrics module with the provided configuration
1631
- */
1632
- setup(config) {
1633
- _chunkWC573FCIcjs.logger.info("Setting up metrics module");
1634
- this.initMetricsReader(config);
1635
- _MetricsModule.instance = this;
1636
- _chunkWC573FCIcjs.logger.info("Metrics module setup completed");
1637
- }
1638
- /**
1639
- * Get the metrics exporter
1640
- */
1641
- getMetricsExporter() {
1642
- if (!this.metricsExporter) {
1643
- throw new Error("Metrics module not initialized");
1644
- }
1645
- return this.metricsExporter;
1646
- }
1647
- /**
1648
- * Get the metrics reader
1649
- */
1650
- getMetricsReader() {
1651
- if (!this.metricsReader) {
1652
- throw new Error("Metrics module not initialized");
1653
- }
1654
- return this.metricsReader;
1655
- }
1656
- /**
1657
- * Shutdown the metrics module
1658
- */
1659
- shutdown() {
1660
- _chunkWC573FCIcjs.logger.debug("Shutting down metrics module");
1661
- this.metricsReader = null;
1662
- this.metricsExporter = null;
1663
- if (_MetricsModule.instance === this) {
1664
- _MetricsModule.instance = null;
1665
- }
1666
- _chunkWC573FCIcjs.logger.debug("Metrics module shutdown completed");
1667
- }
1668
- }, _class4.__initStatic2(), _class4);
1669
- function getMetricsExporter() {
1670
- return MetricsModule.getInstance().getMetricsExporter();
1671
- }
1672
- function getMetricsReader() {
1673
- return MetricsModule.getInstance().getMetricsReader();
1674
- }
1675
-
1676
- // src/internal/trace/tracing.ts
1677
- var _exportertraceotlpproto = require('@opentelemetry/exporter-trace-otlp-proto');
1678
-
1679
- // src/internal/trace/exporters/span-exporter.ts
1680
- var _core = require('@opentelemetry/core');
1681
-
1682
- var BrizzSpanExporter = class {
1683
-
1684
-
1685
-
1686
- constructor(delegate, config) {
1687
- this._delegate = delegate;
1688
- const resourceAttrs = {
1689
- ...config.resourceAttributes,
1690
- "service.name": config.appName,
1691
- [BRIZZ_SDK_VERSION]: _chunk2DSTZTDAcjs.getSDKVersion.call(void 0, ),
1692
- [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
1693
- };
1694
- if (config.environment) {
1695
- resourceAttrs["deployment.environment"] = config.environment;
1696
- }
1697
- if (config.appVersion) {
1698
- resourceAttrs["service.version"] = config.appVersion;
1699
- }
1700
- this._brizzResource = _resources.resourceFromAttributes.call(void 0, resourceAttrs);
1701
- this._beforeSendSpan = config.beforeSendSpan;
1702
- }
1703
- export(spans, resultCallback) {
1704
- if (spans.length === 0) {
1705
- resultCallback({ code: _core.ExportResultCode.SUCCESS });
1706
- return;
1707
- }
1708
- const patchedSpans = spans.map((span) => ({
1709
- ...span,
1710
- resource: span.resource.merge(this._brizzResource),
1711
- spanContext: span.spanContext.bind(span)
1712
- }));
1713
- const filter = this._beforeSendSpan;
1714
- if (!filter) {
1715
- this._delegate.export(patchedSpans, resultCallback);
1716
- return;
1717
- }
1718
- const verdicts = patchedSpans.map((span) => {
1719
- try {
1720
- return Promise.resolve(filter(span));
1721
- } catch (error) {
1722
- _chunkWC573FCIcjs.logger.warn("beforeSendSpan threw; span will be kept", { error });
1723
- return Promise.resolve(true);
1724
- }
1725
- });
1726
- Promise.all(verdicts).then((keep) => {
1727
- const filtered = patchedSpans.filter((_, i) => keep[i] !== false);
1728
- if (filtered.length === 0) {
1729
- resultCallback({ code: _core.ExportResultCode.SUCCESS });
1730
- return;
1731
- }
1732
- this._delegate.export(filtered, resultCallback);
1733
- return;
1734
- }).catch((error) => {
1735
- _chunkWC573FCIcjs.logger.warn("beforeSendSpan rejected; all spans will be kept", { error });
1736
- this._delegate.export(patchedSpans, resultCallback);
1737
- });
1738
- }
1739
- async shutdown() {
1740
- return this._delegate.shutdown();
1741
- }
1742
- async forceFlush() {
1743
- return _optionalChain([this, 'access', _60 => _60._delegate, 'access', _61 => _61.forceFlush, 'optionalCall', _62 => _62()]);
1744
- }
1745
- };
1746
-
1747
- // src/internal/trace/processors/span-processor.ts
1748
-
1749
-
1750
-
1751
-
1752
- var _sdktracebase = require('@opentelemetry/sdk-trace-base');
1753
- function applyContextAttributes(span) {
1754
- const sessionProperties = _api.context.active().getValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY);
1755
- if (sessionProperties) {
1756
- for (const [key, value] of Object.entries(sessionProperties)) {
1757
- span.setAttribute(`${_chunk77UGZGMPcjs.BRIZZ}.${key}`, value);
1758
- }
1759
- }
1760
- }
1761
- var DEFAULT_MASKING_RULES = [
1762
- {
1763
- mode: "partial",
1764
- patterns: DEFAULT_PII_PATTERNS
1765
- }
1766
- ];
1767
- var BrizzSimpleSpanProcessor = class extends _sdktracebase.SimpleSpanProcessor {
1768
-
1769
- constructor(spanExporter, config) {
1770
- super(spanExporter);
1771
- this.config = config;
1772
- }
1773
- onStart(span, parentContext) {
1774
- applyContextAttributes(span);
1775
- super.onStart(span, parentContext);
1776
- }
1777
- onEnd(span) {
1778
- const maskingConfig = _optionalChain([this, 'access', _63 => _63.config, 'access', _64 => _64.masking, 'optionalAccess', _65 => _65.spanMasking]);
1779
- if (maskingConfig) {
1780
- maskReadableSpan(span, maskingConfig);
1781
- }
1782
- super.onEnd(span);
1783
- }
1784
- };
1785
- var BrizzBatchSpanProcessor = class extends _sdktracebase.BatchSpanProcessor {
1786
-
1787
- constructor(spanExporter, config) {
1788
- super(spanExporter);
1789
- this.config = config;
1790
- }
1791
- onStart(span, parentContext) {
1792
- applyContextAttributes(span);
1793
- super.onStart(span, parentContext);
1794
- }
1795
- onEnd(span) {
1796
- const maskingConfig = _optionalChain([this, 'access', _66 => _66.config, 'access', _67 => _67.masking, 'optionalAccess', _68 => _68.spanMasking]);
1797
- if (maskingConfig) {
1798
- maskReadableSpan(span, maskingConfig);
1799
- }
1800
- super.onEnd(span);
1801
- }
1802
- };
1803
- function maskReadableSpan(span, config) {
1804
- const attrs = span.attributes;
1805
- if (!attrs || Object.keys(attrs).length === 0) {
1806
- return;
1807
- }
1808
- let rules = config.rules ? [...config.rules] : [];
1809
- if (!config.disableDefaultRules) {
1810
- rules = [...rules, ...DEFAULT_MASKING_RULES];
1811
- }
1812
- try {
1813
- const input = {};
1814
- for (const [k, v] of Object.entries(attrs)) {
1815
- input[k] = v;
1816
- }
1817
- const masked = maskAttributes(input, rules);
1818
- const maskedEntries = Object.entries(_nullishCoalesce(masked, () => ( {})));
1819
- for (const [k, v] of maskedEntries) {
1820
- if (attrs[k] !== v) {
1821
- attrs[k] = v;
1822
- }
1823
- }
1824
- } catch (error) {
1825
- _chunkWC573FCIcjs.logger.error("Error masking span", { err: error });
1826
- }
1827
- }
1828
-
1829
- // src/internal/trace/tracing.ts
1830
- var TracingModule = (_class5 = class _TracingModule {constructor() { _class5.prototype.__init11.call(this);_class5.prototype.__init12.call(this); }
1831
- static __initStatic3() {this.instance = null}
1832
- static getInstance() {
1833
- if (!this.instance) {
1834
- throw new Error("Brizz must be initialized before accessing TracingModule");
1835
- }
1836
- return this.instance;
1837
- }
1838
- __init11() {this.spanExporter = null}
1839
- __init12() {this.spanProcessor = null}
1840
- /**
1841
- * Initialize the span exporter
1842
- */
1843
- initSpanExporter(config) {
1844
- if (this.spanExporter) {
1845
- _chunkWC573FCIcjs.logger.debug("Span exporter already initialized, skipping re-initialization");
1846
- return;
1847
- }
1848
- if (config.customSpanExporter) {
1849
- _chunkWC573FCIcjs.logger.debug("Using custom span exporter");
1850
- this.spanExporter = new BrizzSpanExporter(config.customSpanExporter, config);
1851
- _chunkWC573FCIcjs.logger.debug("Custom span exporter initialized successfully");
1852
- return;
1853
- }
1854
- const tracesUrl = config.baseUrl.replace(/\/$/, "") + "/v1/traces";
1855
- _chunkWC573FCIcjs.logger.debug("Initializing default OTLP span exporter", { url: tracesUrl });
1856
- const otlpExporter = new (0, _exportertraceotlpproto.OTLPTraceExporter)({
1857
- url: tracesUrl,
1858
- headers: config.headers
1859
- });
1860
- this.spanExporter = new BrizzSpanExporter(otlpExporter, config);
1861
- _chunkWC573FCIcjs.logger.debug("OTLP span exporter initialized successfully");
1862
- }
1863
- /**
1864
- * Initialize the span processor with masking support
1865
- */
1866
- initSpanProcessor(config) {
1867
- if (this.spanProcessor) {
1868
- _chunkWC573FCIcjs.logger.debug("Span processor already initialized, skipping re-initialization");
1869
- return;
1870
- }
1871
- if (!this.spanExporter) {
1872
- throw new Error("Span exporter must be initialized before processor");
1873
- }
1874
- _chunkWC573FCIcjs.logger.debug("Initializing span processor", {
1875
- disableBatch: config.disableBatch,
1876
- hasMasking: !!_optionalChain([config, 'access', _69 => _69.masking, 'optionalAccess', _70 => _70.spanMasking])
1877
- });
1878
- const spanProcessor = config.disableBatch ? new BrizzSimpleSpanProcessor(this.spanExporter, config) : new BrizzBatchSpanProcessor(this.spanExporter, config);
1879
- _chunkWC573FCIcjs.logger.debug("Span processor initialized successfully");
1880
- this.spanProcessor = spanProcessor;
1881
- }
1882
- /**
1883
- * Initialize the tracing module with the provided configuration
1884
- */
1885
- setup(config) {
1886
- _chunkWC573FCIcjs.logger.info("Setting up tracing module");
1887
- if (config.disableSpanExporter) {
1888
- _chunkWC573FCIcjs.logger.info(
1889
- "Span exporter disabled via disableSpanExporter; skipping exporter and processor setup"
1890
- );
1891
- this.spanExporter = null;
1892
- this.spanProcessor = null;
1893
- _TracingModule.instance = this;
1894
- return;
1895
- }
1896
- this.initSpanExporter(config);
1897
- this.initSpanProcessor(config);
1898
- _TracingModule.instance = this;
1899
- _chunkWC573FCIcjs.logger.info("Tracing module setup completed");
1900
- }
1901
- /**
1902
- * Get the span exporter
1903
- */
1904
- getSpanExporter() {
1905
- if (!this.spanExporter) {
1906
- throw new Error("Tracing module not initialized");
1907
- }
1908
- return this.spanExporter;
1909
- }
1910
- /**
1911
- * Get the span processor
1912
- */
1913
- getSpanProcessor() {
1914
- if (!this.spanProcessor) {
1915
- throw new Error("Tracing module not initialized");
1916
- }
1917
- return this.spanProcessor;
1918
- }
1919
- async shutdown() {
1920
- _chunkWC573FCIcjs.logger.debug("Shutting down tracing module");
1921
- if (this.spanProcessor) {
1922
- await this.spanProcessor.shutdown();
1923
- this.spanProcessor = null;
1924
- }
1925
- if (this.spanExporter) {
1926
- await this.spanExporter.shutdown();
1927
- this.spanExporter = null;
1928
- }
1929
- _TracingModule.instance = null;
1930
- _chunkWC573FCIcjs.logger.debug("Tracing module shutdown completed");
1931
- }
1932
- }, _class5.__initStatic3(), _class5);
1933
- function getSpanExporter() {
1934
- return TracingModule.getInstance().getSpanExporter();
1935
- }
1936
- function getSpanProcessor() {
1937
- return TracingModule.getInstance().getSpanProcessor();
1938
- }
1939
-
1940
- // src/internal/sdk.ts
1941
-
1942
- var _instrumentation = require('@opentelemetry/instrumentation');
1943
-
1944
-
1945
-
1946
-
1947
-
1948
-
1949
-
1950
-
1951
-
1952
- var _sdktracenode = require('@opentelemetry/sdk-trace-node');
1953
-
1954
- // src/internal/config.ts
1955
- function resolveConfig(options) {
1956
- const envLogLevel = process.env["BRIZZ_LOG_LEVEL"] || _optionalChain([options, 'access', _71 => _71.logLevel, 'optionalAccess', _72 => _72.toString, 'call', _73 => _73()]) || _chunkWC573FCIcjs.DEFAULT_LOG_LEVEL.toString();
1957
- let resolvedLogLevel;
1958
- if (envLogLevel) {
1959
- resolvedLogLevel = _chunkWC573FCIcjs.parseLogLevel.call(void 0, envLogLevel);
1960
- } else if (typeof options.logLevel === "string") {
1961
- resolvedLogLevel = _chunkWC573FCIcjs.parseLogLevel.call(void 0, options.logLevel);
1962
- } else {
1963
- resolvedLogLevel = options.logLevel || _chunkWC573FCIcjs.DEFAULT_LOG_LEVEL;
1964
- }
1965
- _chunkWC573FCIcjs.setLogLevel.call(void 0, resolvedLogLevel);
1966
- let maskingStatus;
1967
- if (options.masking === true) {
1968
- maskingStatus = "enabled";
1969
- } else if (options.masking === false) {
1970
- maskingStatus = "disabled";
1971
- } else if (typeof options.masking === "object") {
1972
- maskingStatus = "custom";
1973
- } else {
1974
- maskingStatus = "default-disabled";
1975
- }
1976
- _chunkWC573FCIcjs.logger.debug("Starting configuration resolution", {
1977
- appName: options.appName,
1978
- baseUrl: options.baseUrl,
1979
- hasApiKey: !!options.apiKey,
1980
- dsnProvided: !!(process.env["BRIZZ_DSN"] || options.dsn),
1981
- disableBatch: options.disableBatch,
1982
- logLevel: resolvedLogLevel,
1983
- headersCount: Object.keys(options.headers || {}).length,
1984
- masking: maskingStatus
1985
- });
1986
- let resolvedMasking;
1987
- if (options.masking === true) {
1988
- resolvedMasking = {
1989
- spanMasking: {},
1990
- eventMasking: {}
1991
- };
1992
- } else if (options.masking && typeof options.masking === "object") {
1993
- resolvedMasking = options.masking;
1994
- }
1995
- const resolvedConfig = {
1996
- ...options,
1997
- appName: process.env["BRIZZ_APP_NAME"] || options.appName || "unknown-app",
1998
- appVersion: process.env["BRIZZ_APP_VERSION"] || options.appVersion,
1999
- baseUrl: process.env["BRIZZ_BASE_URL"] || options.baseUrl || "https://telemetry.brizz.dev",
2000
- headers: { ...options.headers },
2001
- apiKey: process.env["BRIZZ_API_KEY"] || options.apiKey,
2002
- disableBatch: process.env["BRIZZ_DISABLE_BATCH"] === "true" || !!options.disableBatch,
2003
- disableSpanExporter: process.env["BRIZZ_DISABLE_SPAN_EXPORTER"] === "true" || !!options.disableSpanExporter,
2004
- environment: process.env["BRIZZ_ENVIRONMENT"] || options.environment,
2005
- logLevel: resolvedLogLevel,
2006
- masking: resolvedMasking
2007
- };
2008
- const dsnInput = process.env["BRIZZ_DSN"] || options.dsn;
2009
- let parsedDSN = null;
2010
- if (dsnInput) {
2011
- const kwargConflicts = [];
2012
- if (options.apiKey !== void 0) {
2013
- kwargConflicts.push("apiKey");
2014
- }
2015
- if (options.baseUrl !== void 0) {
2016
- kwargConflicts.push("baseUrl");
2017
- }
2018
- if (options.appName !== void 0) {
2019
- kwargConflicts.push("appName");
2020
- }
2021
- if (kwargConflicts.length > 0) {
2022
- throw new Error(
2023
- `dsn cannot be combined with kwargs ${kwargConflicts.join(", ")}. The DSN bundles bearer, gateway URL, and service name \u2014 choose one configuration style.`
2024
- );
2025
- }
2026
- const envConflicts = ["BRIZZ_API_KEY", "BRIZZ_BASE_URL", "BRIZZ_APP_NAME"].filter(
2027
- (name) => process.env[name] !== void 0
2028
- );
2029
- if (envConflicts.length > 0) {
2030
- _chunkWC573FCIcjs.logger.warn(
2031
- `Ignoring ${envConflicts.join(", ")} \u2014 dsn / BRIZZ_DSN takes precedence.`
2032
- );
2033
- }
2034
- resolvedConfig.apiKey = void 0;
2035
- resolvedConfig.baseUrl = "https://telemetry.brizz.dev";
2036
- resolvedConfig.appName = "unknown-app";
2037
- parsedDSN = _chunkUNLNNKZ7cjs.parseDSN.call(void 0, dsnInput);
2038
- if (parsedDSN) {
2039
- resolvedConfig.appName = parsedDSN.service;
2040
- resolvedConfig.baseUrl = parsedDSN.baseUrl;
2041
- resolvedConfig.apiKey = parsedDSN.bearer;
2042
- }
2043
- } else if (resolvedConfig.apiKey) {
2044
- resolvedConfig.headers["Authorization"] = `Bearer ${resolvedConfig.apiKey}`;
2045
- }
2046
- if (process.env["BRIZZ_HEADERS"]) {
2047
- try {
2048
- const envHeaders = JSON.parse(process.env["BRIZZ_HEADERS"]);
2049
- Object.assign(resolvedConfig.headers, envHeaders);
2050
- _chunkWC573FCIcjs.logger.debug("Added headers from environment variable", {
2051
- headers: Object.keys(envHeaders)
2052
- });
2053
- } catch (error) {
2054
- _chunkWC573FCIcjs.logger.error("Failed to parse BRIZZ_HEADERS environment variable", { error });
2055
- throw new Error("Invalid JSON in BRIZZ_HEADERS environment variable", { cause: error });
2056
- }
2057
- }
2058
- if (dsnInput) {
2059
- const authHeaderKeys = /* @__PURE__ */ new Set(["authorization", _chunkUNLNNKZ7cjs.SERVICE_NAME_HEADER.toLowerCase()]);
2060
- resolvedConfig.headers = Object.fromEntries(
2061
- Object.entries(resolvedConfig.headers).filter(
2062
- ([key]) => !authHeaderKeys.has(key.toLowerCase())
2063
- )
2064
- );
2065
- if (parsedDSN) {
2066
- resolvedConfig.headers["Authorization"] = `Bearer ${parsedDSN.bearer}`;
2067
- resolvedConfig.headers[_chunkUNLNNKZ7cjs.SERVICE_NAME_HEADER] = parsedDSN.service;
2068
- }
2069
- }
2070
- _chunkWC573FCIcjs.logger.debug("Configuration resolved with environment variables", {
2071
- appName: resolvedConfig.appName,
2072
- baseUrl: resolvedConfig.baseUrl,
2073
- hasApiKey: !!resolvedConfig.apiKey,
2074
- dsnProvided: !!dsnInput,
2075
- disableBatch: resolvedConfig.disableBatch,
2076
- envOverrides: {
2077
- hasEnvApiKey: !!process.env["BRIZZ_API_KEY"],
2078
- hasEnvBaseUrl: !!process.env["BRIZZ_BASE_URL"],
2079
- hasEnvDsn: !!process.env["BRIZZ_DSN"],
2080
- hasEnvBatch: !!process.env["BRIZZ_DISABLE_BATCH"],
2081
- hasEnvHeaders: !!process.env["BRIZZ_HEADERS"]
2082
- }
2083
- });
2084
- return resolvedConfig;
2085
- }
2086
-
2087
- // src/internal/sdk.ts
2088
- var _Brizz = (_class6 = class __Brizz {constructor() { _class6.prototype.__init13.call(this);_class6.prototype.__init14.call(this);_class6.prototype.__init15.call(this); }
2089
- static __initStatic4() {this.instance = null}
2090
- static getInstance() {
2091
- if (!this.instance) {
2092
- throw new Error("Brizz must be initialized before accessing TracingModule");
2093
- }
2094
- return this.instance;
2095
- }
2096
- /** Flag indicating if SDK initialization has completed successfully */
2097
- __init13() {this._initialized = false}
2098
- /** OpenTelemetry tracer provider */
2099
- __init14() {this._tracerProvider = null}
2100
- /** OpenTelemetry meter provider */
2101
- __init15() {this._meterProvider = null}
2102
- /**
2103
- * Set up instrumentation registry and configure manual modules.
2104
- * @private
2105
- */
2106
- setupInstrumentation(options) {
2107
- const registry = InstrumentationRegistry.getInstance();
2108
- if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
2109
- registry.setManualModules(options.instrumentModules);
2110
- }
2111
- }
2112
- /**
2113
- * Create and register the tracer + meter providers if not disabled.
2114
- * Only handles manual instrumentations now - auto instrumentations are loaded at import time.
2115
- * @private
2116
- */
2117
- createAndStartProviders(options, resolvedConfig) {
2118
- if (options.disableNodeSdk) {
2119
- _chunkWC573FCIcjs.logger.info("NodeSDK disabled - only telemetry modules initialized");
2120
- return;
2121
- }
2122
- const registry = InstrumentationRegistry.getInstance();
2123
- const manualInstrumentations = registry.getManualInstrumentations();
2124
- const resourceAttributes = {
2125
- ...resolvedConfig.resourceAttributes,
2126
- "service.name": resolvedConfig.appName,
2127
- [BRIZZ_SDK_VERSION]: _chunk2DSTZTDAcjs.getSDKVersion.call(void 0, ),
2128
- [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
2129
- };
2130
- if (resolvedConfig.environment) {
2131
- resourceAttributes["deployment.environment"] = resolvedConfig.environment;
2132
- }
2133
- if (resolvedConfig.appVersion) {
2134
- resourceAttributes["service.version"] = resolvedConfig.appVersion;
2135
- }
2136
- const resource = _resources.defaultResource.call(void 0, ).merge(_resources.detectResources.call(void 0, { detectors: [_resources.envDetector, _resources.hostDetector, _resources.processDetector] })).merge(_resources.resourceFromAttributes.call(void 0, resourceAttributes));
2137
- this._tracerProvider = new (0, _sdktracenode.NodeTracerProvider)({
2138
- resource,
2139
- spanProcessors: resolvedConfig.disableSpanExporter ? [] : [new (0, _chunkEVRCHF74cjs.InterruptPropagator)(), getSpanProcessor()]
2140
- });
2141
- this._tracerProvider.register();
2142
- this._meterProvider = new (0, _sdkmetrics.MeterProvider)({ resource, readers: [getMetricsReader()] });
2143
- _api.metrics.setGlobalMeterProvider(this._meterProvider);
2144
- if (manualInstrumentations.length > 0) {
2145
- _instrumentation.registerInstrumentations.call(void 0, { instrumentations: manualInstrumentations });
2146
- _chunkWC573FCIcjs.logger.info(
2147
- `Telemetry providers started with ${manualInstrumentations.length} manual instrumentations`
2148
- );
2149
- } else {
2150
- _chunkWC573FCIcjs.logger.info(
2151
- "Telemetry providers started - using auto-instrumentations loaded at import time"
2152
- );
2153
- }
2154
- }
2155
- /**
2156
- * Initialize telemetry modules.
2157
- *
2158
- * Sets up the tracing, metrics, and logging modules with their
2159
- * respective exporters and processors.
2160
- *
2161
- * @param {IResolvedBrizzConfig} config - Resolved configuration
2162
- * @private
2163
- */
2164
- initializeModules(config) {
2165
- _chunkWC573FCIcjs.logger.info("Initializing telemetry modules");
2166
- _chunkWC573FCIcjs.logger.debug("Initializing tracing module");
2167
- const tracingModule = new TracingModule();
2168
- tracingModule.setup(config);
2169
- _chunkWC573FCIcjs.logger.debug("Initializing metrics module");
2170
- const metricsModule = new MetricsModule();
2171
- metricsModule.setup(config);
2172
- _chunkWC573FCIcjs.logger.debug("Initializing logging module");
2173
- const loggingModule = new LoggingModule();
2174
- loggingModule.setup(config);
2175
- _chunkWC573FCIcjs.logger.info("All telemetry modules initialized successfully");
2176
- }
2177
- /**
2178
- * Detect the current module system (ESM or CJS) using reliable indicators
2179
- *
2180
- * @returns {string} - 'ESM' or 'CJS'
2181
- * @private
2182
- */
2183
- detectModuleSystem() {
2184
- const inCJS = typeof module !== "undefined" && typeof exports !== "undefined" && typeof _chunkOBGZSXTJcjs.__require === "function" && typeof __filename === "string" && typeof __dirname === "string" && this === (typeof exports !== "undefined" ? exports : void 0);
2185
- return inCJS ? "CJS" : "ESM";
2186
- }
2187
- /**
2188
- * Shutdown all telemetry modules.
2189
- * @private
2190
- */
2191
- async shutdownModules() {
2192
- _chunkWC573FCIcjs.logger.info("Shutting down telemetry modules");
2193
- try {
2194
- try {
2195
- const tracingModule = TracingModule.getInstance();
2196
- await tracingModule.shutdown();
2197
- } catch (e3) {
2198
- _chunkWC573FCIcjs.logger.debug("Tracing module already shut down or not initialized");
2199
- }
2200
- try {
2201
- const metricsModule = MetricsModule.getInstance();
2202
- metricsModule.shutdown();
2203
- } catch (e4) {
2204
- _chunkWC573FCIcjs.logger.debug("Metrics module already shut down or not initialized");
2205
- }
2206
- try {
2207
- const loggingModule = LoggingModule.getInstance();
2208
- await loggingModule.shutdown();
2209
- } catch (e5) {
2210
- _chunkWC573FCIcjs.logger.debug("Logging module already shut down or not initialized");
2211
- }
2212
- _chunkWC573FCIcjs.logger.info("All telemetry modules shut down successfully");
2213
- } catch (error) {
2214
- _chunkWC573FCIcjs.logger.error("Error shutting down modules", { error });
2215
- throw error;
2216
- }
2217
- }
2218
- /**
2219
- * Initialize the Brizz SDK with the provided configuration.
2220
- *
2221
- * @param {IBrizzInitializeOptions} options - Configuration options for the SDK
2222
- * @throws {Error} - If initialization fails
2223
- *
2224
- * @example
2225
- * ```typescript
2226
- * Brizz.initialize({
2227
- * appName: 'my-app',
2228
- * baseUrl: 'http://localhost:4318',
2229
- * apiKey: 'your-api-key'
2230
- * });
2231
- * ```
2232
- */
2233
- initialize(options) {
2234
- if (this._initialized) {
2235
- _chunkWC573FCIcjs.logger.warn("Brizz SDK already initialized");
2236
- return;
2237
- }
2238
- _chunkWC573FCIcjs.logger.info("Starting Brizz SDK initialization");
2239
- try {
2240
- const resolvedConfig = resolveConfig(options);
2241
- this.initializeModules(resolvedConfig);
2242
- this.setupInstrumentation(options);
2243
- this.createAndStartProviders(options, resolvedConfig);
2244
- this._initialized = true;
2245
- _chunkWC573FCIcjs.logger.info("Brizz SDK initialization completed successfully", {
2246
- moduleSystem: this.detectModuleSystem()
2247
- });
2248
- } catch (error) {
2249
- _chunkWC573FCIcjs.logger.error("Failed to initialize Brizz SDK", { error });
2250
- throw new Error(`Failed to initialize SDK: ${String(error)}`, { cause: error });
2251
- }
2252
- }
2253
- /**
2254
- * Gracefully shutdown the Brizz SDK.
2255
- *
2256
- * This method stops all telemetry collection, flushes any pending data,
2257
- * and releases resources. Should be called before app termination.
2258
- *
2259
- * @returns {Promise<void>} - Resolves when shutdown is complete
2260
- * @throws {Error} - If shutdown fails
2261
- *
2262
- * @example
2263
- * ```typescript
2264
- * // Shutdown before app exit
2265
- * await Brizz.shutdown();
2266
- * ```
2267
- */
2268
- async shutdown() {
2269
- if (!this._initialized) {
2270
- _chunkWC573FCIcjs.logger.warn("Brizz SDK not initialized");
2271
- return;
2272
- }
2273
- try {
2274
- await this.shutdownModules();
2275
- await _optionalChain([this, 'access', _74 => _74._tracerProvider, 'optionalAccess', _75 => _75.forceFlush, 'call', _76 => _76()]);
2276
- await _optionalChain([this, 'access', _77 => _77._tracerProvider, 'optionalAccess', _78 => _78.shutdown, 'call', _79 => _79()]);
2277
- await _optionalChain([this, 'access', _80 => _80._meterProvider, 'optionalAccess', _81 => _81.forceFlush, 'call', _82 => _82()]);
2278
- await _optionalChain([this, 'access', _83 => _83._meterProvider, 'optionalAccess', _84 => _84.shutdown, 'call', _85 => _85()]);
2279
- this._initialized = false;
2280
- this._tracerProvider = null;
2281
- this._meterProvider = null;
2282
- __Brizz.instance = null;
2283
- _chunkWC573FCIcjs.logger.info("Brizz SDK shut down successfully");
2284
- } catch (error) {
2285
- if (error instanceof Error && error.message.includes("ENOTFOUND")) {
2286
- _chunkWC573FCIcjs.logger.debug(`Network error during shutdown (expected in tests): ${error.message}`);
2287
- } else {
2288
- _chunkWC573FCIcjs.logger.error(`Failed to shutdown Brizz SDK: ${String(error)}`);
2289
- throw error;
2290
- }
2291
- }
2292
- }
2293
- }, _class6.__initStatic4(), _class6);
2294
- var Brizz = new _Brizz();
2295
-
2296
- // src/node/runtime.ts
2297
- function detectRuntime() {
2298
- const [major, minor] = process.versions.node.split(".").map(Number);
2299
- const noNodeJSGlobals = typeof __filename === "undefined" && typeof __dirname === "undefined";
2300
- const noModuleSystem = typeof module === "undefined" && typeof exports === "undefined";
2301
- const hasRequire = typeof _chunkOBGZSXTJcjs.__require === "function";
2302
- const isESM = noNodeJSGlobals && noModuleSystem;
2303
- const isCJS = hasRequire && typeof module !== "undefined" && typeof exports !== "undefined" && typeof __filename === "string" && typeof __dirname === "string";
2304
- const supportsLoaderAPI = (_nullishCoalesce(major, () => ( 0))) >= 21 || (_nullishCoalesce(major, () => ( 0))) === 20 && (_nullishCoalesce(minor, () => ( 0))) >= 6 || (_nullishCoalesce(major, () => ( 0))) === 18 && (_nullishCoalesce(minor, () => ( 0))) >= 19;
2305
- const supportsRegister = (
2306
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2307
- !!_optionalChain([process, 'access', _86 => _86.features, 'optionalAccess', _87 => _87.typescript]) || !!_optionalChain([globalThis, 'access', _88 => _88.module, 'optionalAccess', _89 => _89.register])
2308
- );
2309
- _chunkWC573FCIcjs.logger.debug("Runtime detection results:", {
2310
- nodeVersion: `${_nullishCoalesce(major, () => ( 0))}.${_nullishCoalesce(minor, () => ( 0))}`,
2311
- isESM,
2312
- isCJS,
2313
- supportsLoaderAPI,
2314
- supportsRegister,
2315
- detectionLogic: {
2316
- noNodeJSGlobals,
2317
- noModuleSystem,
2318
- hasRequire,
2319
- esmCondition: `${noNodeJSGlobals} && ${noModuleSystem} = ${isESM}`,
2320
- cjsCondition: `require && module && exports && __filename && __dirname = ${isCJS}`
2321
- },
2322
- checks: {
2323
- __filename: typeof __filename,
2324
- __dirname: typeof __dirname,
2325
- require: typeof _chunkOBGZSXTJcjs.__require,
2326
- module: typeof module,
2327
- exports: typeof exports,
2328
- "process.features": process.features,
2329
- "globalThis.module": Reflect.get(globalThis, "module")
2330
- }
2331
- });
2332
- return {
2333
- isESM,
2334
- isCJS,
2335
- nodeVersion: process.versions.node,
2336
- supportsLoaderAPI,
2337
- supportsRegister
2338
- };
2339
- }
2340
-
2341
-
2342
-
2343
-
2344
-
2345
-
2346
-
2347
-
2348
-
2349
-
2350
-
2351
-
2352
-
2353
-
2354
-
2355
-
2356
-
2357
-
2358
-
2359
-
2360
-
2361
-
2362
-
2363
-
2364
-
2365
-
2366
-
2367
-
2368
-
2369
-
2370
-
2371
-
2372
-
2373
-
2374
-
2375
-
2376
-
2377
- exports.setCurrentSpanCustomProperties = setCurrentSpanCustomProperties; exports.callWithProperties = callWithProperties; exports.withProperties = withProperties; exports.setUser = setUser; exports.setOrganization = setOrganization; exports.setMessageId = setMessageId; exports.callWithUser = callWithUser; exports.withUser = withUser; exports.callWithOrganization = callWithOrganization; exports.withOrganization = withOrganization; exports.callWithMessageId = callWithMessageId; exports.withMessageId = withMessageId; exports.callWithMute = callWithMute; exports.withMute = withMute; exports.withSessionId = withSessionId; exports.callWithSessionId = callWithSessionId; exports.Session = Session; exports.SessionTitle = SessionTitle; exports.getActiveSession = getActiveSession; exports.addExternalLink = addExternalLink; exports.recordFeedback = recordFeedback; exports.recordMetric = recordMetric; exports.startSession = startSession; exports.startSessionTitle = startSessionTitle; exports.DEFAULT_PII_PATTERNS = DEFAULT_PII_PATTERNS; exports.maskValue = maskValue; exports.maskAttributes = maskAttributes; exports.emitEvent = emitEvent; exports.emitEventWithSessionId = emitEventWithSessionId; exports.getMetricsExporter = getMetricsExporter; exports.getMetricsReader = getMetricsReader; exports.getSpanExporter = getSpanExporter; exports.getSpanProcessor = getSpanProcessor; exports.Brizz = Brizz; exports.detectRuntime = detectRuntime;