@getmicdrop/svelte-components 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/components/Alert/Alert.spec.js +170 -170
  2. package/dist/components/Badges/Badge.spec.js +103 -103
  3. package/dist/components/BottomSheet/BottomSheet.spec.js +127 -127
  4. package/dist/components/Breadcrumb/Breadcrumb.spec.js +120 -120
  5. package/dist/components/Button/Button.spec.js +211 -211
  6. package/dist/components/Button/ButtonSaveDemo.spec.js +48 -48
  7. package/dist/components/Calendar/Calendar.spec.js +131 -131
  8. package/dist/components/Calendar/QuarterView.spec.js +394 -394
  9. package/dist/components/Card.spec.js +47 -47
  10. package/dist/components/CropImage/CropImage.spec.js +216 -216
  11. package/dist/components/DarkModeToggle.spec.js +357 -357
  12. package/dist/components/ErrorDisplay.spec.js +69 -69
  13. package/dist/components/FormActions.spec.js +88 -88
  14. package/dist/components/FormValidationSummary.spec.js +203 -203
  15. package/dist/components/Icons/Icon.spec.js +175 -175
  16. package/dist/components/Icons/MoreHori.spec.js +67 -67
  17. package/dist/components/Icons/WarningIcon.spec.js +30 -30
  18. package/dist/components/Input/Input.spec.js +573 -573
  19. package/dist/components/Input/MultiSelect.spec.js +257 -257
  20. package/dist/components/Input/OTPInput.spec.js +238 -238
  21. package/dist/components/Input/Select.spec.js +218 -218
  22. package/dist/components/Layout/BottomNav.spec.js +130 -130
  23. package/dist/components/Layout/Header.spec.js +203 -203
  24. package/dist/components/Modal/ConfirmationModal.spec.js +191 -191
  25. package/dist/components/Modal/Modal.spec.js +95 -95
  26. package/dist/components/Modal/ModalStateManager.spec.js +100 -100
  27. package/dist/components/PageLoader.spec.js +54 -54
  28. package/dist/components/PasswordStrengthIndicator/PasswordStrengthIndicator.spec.js +173 -173
  29. package/dist/components/PlaceAutocomplete/PlaceAutocomplete.spec.js +300 -300
  30. package/dist/components/Spinner/Spinner.spec.js +75 -75
  31. package/dist/components/StatusIndicator/StatusIndicator.spec.js +129 -129
  32. package/dist/components/Toaster/Toaster.stories.svelte +1 -1
  33. package/dist/components/Toggle.spec.js +158 -158
  34. package/dist/components/ValidationError.spec.js +79 -79
  35. package/dist/components/pages/performers/AvailabilityCalendarModal.spec.js +606 -606
  36. package/dist/components/pages/performers/AvailabilityCalendarModal.svelte +4 -4
  37. package/dist/components/pages/performers/ModalShowInfo.spec.js +124 -124
  38. package/dist/components/pages/performers/ModalShowInfo.svelte +1 -1
  39. package/dist/components/pages/performers/PageBackButton.spec.js +89 -89
  40. package/dist/components/pages/performers/SectionHeader.spec.js +75 -75
  41. package/dist/components/pages/performers/ShowDetails.spec.js +166 -166
  42. package/dist/components/pages/performers/ShowItemCard.spec.js +793 -793
  43. package/dist/components/pages/performers/ShowItemCard.svelte +4 -4
  44. package/dist/components/pages/performers/SwitchOption.spec.js +127 -127
  45. package/dist/components/pages/performers/VenueInfo.spec.js +167 -167
  46. package/dist/components/pages/performers/VenueInfo.svelte +1 -1
  47. package/dist/components/pages/performers/VenueItemCard.spec.js +763 -763
  48. package/dist/components/pages/performers/VenueItemCard.svelte +4 -4
  49. package/dist/components/pages/profile/profile-form.spec.js +9 -9
  50. package/dist/components/pages/settings/tabs/CustomImageDropzone.svelte +3 -3
  51. package/dist/components/pages/shows/ShowList.spec.js +33 -33
  52. package/dist/components/pages/shows/TabContent.spec.js +90 -90
  53. package/dist/components/pages/shows/TabNavigation.spec.js +143 -143
  54. package/dist/config.js +5 -5
  55. package/dist/config.spec.js +29 -29
  56. package/dist/constants/formOptions.js +25 -25
  57. package/dist/constants/formOptions.spec.js +88 -88
  58. package/dist/index.js +111 -111
  59. package/dist/stores/auth.d.ts +9 -0
  60. package/dist/stores/auth.d.ts.map +1 -0
  61. package/dist/stores/auth.js +36 -0
  62. package/dist/stores/auth.spec.d.ts +2 -0
  63. package/dist/stores/auth.spec.d.ts.map +1 -0
  64. package/dist/stores/auth.spec.js +139 -0
  65. package/dist/stores/formDataStore.d.ts +17 -0
  66. package/dist/stores/formDataStore.d.ts.map +1 -0
  67. package/dist/stores/formDataStore.js +25 -0
  68. package/dist/stores/formDataStore.spec.d.ts +2 -0
  69. package/dist/stores/formDataStore.spec.d.ts.map +1 -0
  70. package/dist/stores/formDataStore.spec.js +257 -0
  71. package/dist/stores/formSave.d.ts +24 -0
  72. package/dist/stores/formSave.d.ts.map +1 -0
  73. package/dist/stores/formSave.js +132 -0
  74. package/dist/stores/formSave.spec.d.ts +2 -0
  75. package/dist/stores/formSave.spec.d.ts.map +1 -0
  76. package/dist/stores/formSave.spec.js +296 -0
  77. package/dist/stores/index.d.ts +1 -0
  78. package/dist/stores/index.d.ts.map +1 -0
  79. package/dist/stores/index.js +0 -0
  80. package/dist/stores/navigation.d.ts +5 -0
  81. package/dist/stores/navigation.d.ts.map +1 -0
  82. package/dist/stores/navigation.js +12 -0
  83. package/dist/stores/navigation.spec.d.ts +2 -0
  84. package/dist/stores/navigation.spec.d.ts.map +1 -0
  85. package/dist/stores/navigation.spec.js +136 -0
  86. package/dist/stores/toaster.d.ts +4 -0
  87. package/dist/stores/toaster.d.ts.map +1 -0
  88. package/dist/stores/toaster.js +13 -0
  89. package/dist/stores/toaster.spec.d.ts +2 -0
  90. package/dist/stores/toaster.spec.d.ts.map +1 -0
  91. package/dist/stores/toaster.spec.js +59 -0
  92. package/dist/telemetry.js +357 -357
  93. package/dist/telemetry.server.js +211 -211
  94. package/dist/telemetry.server.spec.js +434 -434
  95. package/dist/telemetry.spec.js +660 -660
  96. package/dist/utils/apiConfig.js +49 -49
  97. package/dist/utils/apiConfig.spec.js +118 -118
  98. package/dist/utils/greetings.js +187 -187
  99. package/dist/utils/greetings.spec.js +337 -337
  100. package/dist/utils/imageValidation.js +121 -121
  101. package/dist/utils/imageValidation.spec.js +220 -220
  102. package/dist/utils/portal.js +25 -25
  103. package/dist/utils/portal.spec.js +143 -143
  104. package/dist/utils/utils/utils.js +323 -323
  105. package/dist/utils/utils/utils.spec.js +698 -698
  106. package/dist/utils/utils.spec.js +643 -643
  107. package/package.json +1 -1
package/dist/telemetry.js CHANGED
@@ -1,358 +1,358 @@
1
- import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
2
- import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
3
- import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
4
- import { Resource } from '@opentelemetry/resources';
5
- import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION, SEMRESATTRS_DEPLOYMENT_ENVIRONMENT } from '@opentelemetry/semantic-conventions';
6
- import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-document-load';
7
- import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
8
- import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
9
- import { UserInteractionInstrumentation } from '@opentelemetry/instrumentation-user-interaction';
10
- import { ZoneContextManager } from '@opentelemetry/context-zone';
11
- import { B3Propagator } from '@opentelemetry/propagator-b3';
12
-
13
- // Telemetry configuration from environment or defaults
14
- const TELEMETRY_CONFIG = {
15
- serviceName: import.meta.env.VITE_OTEL_SERVICE_NAME || 'jetbook-performersportal',
16
- serviceVersion: import.meta.env.VITE_OTEL_SERVICE_VERSION || '1.0.0',
17
- environment: import.meta.env.VITE_ENVIRONMENT || 'development',
18
- otlpEndpoint: import.meta.env.VITE_OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318/v1/traces',
19
- tracesEnabled: import.meta.env.VITE_OTEL_TRACES_ENABLED !== 'false',
20
- sampleRate: parseFloat(import.meta.env.VITE_OTEL_TRACES_SAMPLER_ARG || '0.1'), // 10% sampling by default
21
- consoleDebug: import.meta.env.VITE_OTEL_DEBUG === 'true'
22
- };
23
-
24
- let tracer = null;
25
- let tracerProvider = null;
26
-
27
- // Helper to log telemetry events when debugging
28
- function debugLog(message, data) {
29
- if (TELEMETRY_CONFIG.consoleDebug) {
30
- console.log(`[Telemetry] ${message}`, data || '');
31
- }
32
- }
33
-
34
- // Initialize OpenTelemetry
35
- export function initTelemetry() {
36
- if (!TELEMETRY_CONFIG.tracesEnabled) {
37
- console.log('[Telemetry] Tracing is disabled');
38
- return;
39
- }
40
-
41
- try {
42
- // Create resource with service information
43
- const resource = new Resource({
44
- [SEMRESATTRS_SERVICE_NAME]: TELEMETRY_CONFIG.serviceName,
45
- [SEMRESATTRS_SERVICE_VERSION]: TELEMETRY_CONFIG.serviceVersion,
46
- [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: TELEMETRY_CONFIG.environment,
47
- 'browser.user_agent': navigator.userAgent,
48
- 'browser.language': navigator.language,
49
- 'browser.platform': navigator.platform
50
- });
51
-
52
- // Create tracer provider
53
- tracerProvider = new WebTracerProvider({
54
- resource,
55
- sampler: {
56
- shouldSample: () => {
57
- return {
58
- decision: Math.random() < TELEMETRY_CONFIG.sampleRate ? 1 : 0,
59
- attributes: []
60
- };
61
- }
62
- }
63
- });
64
-
65
- // Configure OTLP exporter
66
- const exporter = new OTLPTraceExporter({
67
- url: TELEMETRY_CONFIG.otlpEndpoint,
68
- headers: {
69
- 'Content-Type': 'application/json'
70
- }
71
- });
72
-
73
- // Add batch span processor
74
- tracerProvider.addSpanProcessor(new BatchSpanProcessor(exporter, {
75
- maxQueueSize: 100,
76
- maxExportBatchSize: 50,
77
- scheduledDelayMillis: 500,
78
- exportTimeoutMillis: 30000
79
- }));
80
-
81
- // Set global provider
82
- tracerProvider.register({
83
- contextManager: new ZoneContextManager(),
84
- propagator: new B3Propagator()
85
- });
86
-
87
- // Enable browser instrumentations
88
- // These auto-register with the global tracer provider when instantiated and enabled
89
- new DocumentLoadInstrumentation({
90
- applyCustomAttributesOnSpan: {
91
- documentLoad: (span) => {
92
- span.setAttribute('page.path', window.location.pathname);
93
- span.setAttribute('page.search', window.location.search);
94
- span.setAttribute('page.hash', window.location.hash);
95
- span.setAttribute('portal.type', 'performers');
96
- },
97
- documentFetch: (span) => {
98
- span.setAttribute('document.referrer', document.referrer);
99
- }
100
- }
101
- }).enable();
102
-
103
- new FetchInstrumentation({
104
- propagateTraceHeaderCorsUrls: [
105
- /^http:\/\/localhost:8080\/.*/,
106
- /^https:\/\/api\.jetbook\.com\/.*/,
107
- /^https:\/\/.*\.get-micdrop\.com\/.*/
108
- ],
109
- clearTimingResources: true,
110
- applyCustomAttributesOnSpan: (span, request, response) => {
111
- const url = new URL(request.url || '');
112
- span.setAttribute('http.url.pathname', url.pathname);
113
- span.setAttribute('http.url.search', url.search);
114
- span.setAttribute('portal.type', 'performers');
115
-
116
- if (response) {
117
- span.setAttribute('http.response.status', response.status);
118
- span.setAttribute('http.response.content_length', response.headers?.get('content-length') || 0);
119
- }
120
- }
121
- }).enable();
122
-
123
- new XMLHttpRequestInstrumentation({
124
- propagateTraceHeaderCorsUrls: [
125
- /^http:\/\/localhost:8080\/.*/,
126
- /^https:\/\/api\.jetbook\.com\/.*/,
127
- /^https:\/\/.*\.get-micdrop\.com\/.*/
128
- ],
129
- clearTimingResources: true
130
- }).enable();
131
-
132
- new UserInteractionInstrumentation({
133
- eventNames: ['click', 'submit', 'change'],
134
- shouldPreventSpanCreation: (eventType, element, span) => {
135
- // Skip telemetry for certain elements
136
- if (element.classList?.contains('no-telemetry')) {
137
- return true;
138
- }
139
- // Skip very frequent events
140
- if (eventType === 'change' && element.tagName === 'INPUT' && element.type === 'text') {
141
- return true;
142
- }
143
- return false;
144
- }
145
- }).enable();
146
-
147
- // Get tracer instance
148
- tracer = tracerProvider.getTracer(
149
- TELEMETRY_CONFIG.serviceName,
150
- TELEMETRY_CONFIG.serviceVersion
151
- );
152
-
153
- debugLog('Telemetry initialized', TELEMETRY_CONFIG);
154
- console.log(`[Telemetry] Initialized with ${TELEMETRY_CONFIG.sampleRate * 100}% sampling rate`);
155
-
156
- } catch (error) {
157
- console.error('[Telemetry] Failed to initialize:', error);
158
- }
159
- }
160
-
161
- // Create custom span for tracking specific operations
162
- export function startSpan(name, options = {}) {
163
- if (!tracer) return null;
164
-
165
- const span = tracer.startSpan(name, {
166
- ...options,
167
- attributes: {
168
- 'span.kind': 'internal',
169
- 'portal.type': 'performers',
170
- ...options.attributes
171
- }
172
- });
173
-
174
- debugLog(`Started span: ${name}`, options.attributes);
175
- return span;
176
- }
177
-
178
- // End a span and set its status
179
- export function endSpan(span, status = { code: 0 }) {
180
- if (!span) return;
181
-
182
- span.setStatus(status);
183
- span.end();
184
- debugLog(`Ended span: ${span.name}`, status);
185
- }
186
-
187
- // Track page views (for SPAs)
188
- export function trackPageView(pagePath, pageTitle) {
189
- if (!tracer) return;
190
-
191
- const span = tracer.startSpan('page_view', {
192
- attributes: {
193
- 'page.path': pagePath,
194
- 'page.title': pageTitle || document.title,
195
- 'page.url': window.location.href,
196
- 'page.referrer': document.referrer,
197
- 'portal.type': 'performers'
198
- }
199
- });
200
-
201
- span.end();
202
- debugLog(`Tracked page view: ${pagePath}`);
203
- }
204
-
205
- // Track custom events
206
- export function trackEvent(eventName, attributes = {}) {
207
- if (!tracer) return;
208
-
209
- const span = tracer.startSpan(`event.${eventName}`, {
210
- attributes: {
211
- 'event.name': eventName,
212
- 'event.timestamp': new Date().toISOString(),
213
- 'portal.type': 'performers',
214
- ...attributes
215
- }
216
- });
217
-
218
- span.end();
219
- debugLog(`Tracked event: ${eventName}`, attributes);
220
- }
221
-
222
- // Track performer-specific actions
223
- export function trackPerformerAction(action, metadata = {}) {
224
- if (!tracer) return;
225
-
226
- const span = tracer.startSpan(`performer.${action}`, {
227
- attributes: {
228
- 'performer.action': action,
229
- 'performer.metadata': JSON.stringify(metadata),
230
- 'portal.type': 'performers',
231
- 'page.url': window.location.href,
232
- 'timestamp': new Date().toISOString()
233
- }
234
- });
235
-
236
- span.end();
237
- debugLog(`Tracked performer action: ${action}`, metadata);
238
- }
239
-
240
- // Track errors
241
- export function trackError(error, context = {}) {
242
- if (!tracer) return;
243
-
244
- const span = tracer.startSpan('error', {
245
- attributes: {
246
- 'error.message': error.message || String(error),
247
- 'error.stack': error.stack,
248
- 'error.type': error.name || 'Error',
249
- 'error.context': JSON.stringify(context),
250
- 'page.url': window.location.href,
251
- 'portal.type': 'performers'
252
- }
253
- });
254
-
255
- span.setStatus({ code: 2, message: error.message });
256
- span.recordException(error);
257
- span.end();
258
-
259
- debugLog(`Tracked error: ${error.message}`, context);
260
- }
261
-
262
- // Track API calls with custom attributes
263
- export function trackAPICall(method, endpoint, status, duration, attributes = {}) {
264
- if (!tracer) return;
265
-
266
- const span = tracer.startSpan('api_call', {
267
- attributes: {
268
- 'http.method': method,
269
- 'http.url': endpoint,
270
- 'http.status_code': status,
271
- 'http.duration_ms': duration,
272
- 'portal.type': 'performers',
273
- ...attributes
274
- }
275
- });
276
-
277
- span.setStatus({ code: status >= 400 ? 2 : 0 });
278
- span.end();
279
-
280
- debugLog(`Tracked API call: ${method} ${endpoint}`, { status, duration });
281
- }
282
-
283
- // Track user actions
284
- export function trackUserAction(action, metadata = {}) {
285
- if (!tracer) return;
286
-
287
- const span = tracer.startSpan(`user.${action}`, {
288
- attributes: {
289
- 'user.action': action,
290
- 'user.metadata': JSON.stringify(metadata),
291
- 'portal.type': 'performers',
292
- 'page.url': window.location.href,
293
- 'timestamp': new Date().toISOString()
294
- }
295
- });
296
-
297
- span.end();
298
- debugLog(`Tracked user action: ${action}`, metadata);
299
- }
300
-
301
- // Shutdown telemetry gracefully
302
- export async function shutdownTelemetry() {
303
- if (tracerProvider) {
304
- try {
305
- await tracerProvider.shutdown();
306
- console.log('[Telemetry] Shutdown complete');
307
- } catch (error) {
308
- console.error('[Telemetry] Shutdown error:', error);
309
- }
310
- }
311
- }
312
-
313
- // Connect client spans with SSR spans using trace context
314
- function connectWithSSRTrace() {
315
- // Check if we have trace context from SSR
316
- const ssrTraceContext = window.__TRACE_CONTEXT__;
317
- if (ssrTraceContext && tracer) {
318
- // Create a span linked to the SSR span
319
- const span = tracer.startSpan('client.performer.init', {
320
- attributes: {
321
- 'span.kind': 'client',
322
- 'client.type': 'browser',
323
- 'portal.type': 'performers',
324
- 'ssr.trace_id': ssrTraceContext.traceId,
325
- 'ssr.span_id': ssrTraceContext.spanId
326
- },
327
- links: [{
328
- context: {
329
- traceId: ssrTraceContext.traceId,
330
- spanId: ssrTraceContext.spanId,
331
- traceFlags: ssrTraceContext.traceFlags || 0
332
- }
333
- }]
334
- });
335
-
336
- span.end();
337
- debugLog('Connected to SSR trace', ssrTraceContext);
338
- }
339
- }
340
-
341
- // Auto-initialize on module load if in browser environment
342
- if (typeof window !== 'undefined') {
343
- // Initialize telemetry when DOM is ready
344
- if (document.readyState === 'loading') {
345
- document.addEventListener('DOMContentLoaded', () => {
346
- initTelemetry();
347
- connectWithSSRTrace();
348
- });
349
- } else {
350
- initTelemetry();
351
- connectWithSSRTrace();
352
- }
353
-
354
- // Cleanup on page unload
355
- window.addEventListener('beforeunload', () => {
356
- shutdownTelemetry();
357
- });
1
+ import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
2
+ import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
3
+ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
4
+ import { Resource } from '@opentelemetry/resources';
5
+ import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION, SEMRESATTRS_DEPLOYMENT_ENVIRONMENT } from '@opentelemetry/semantic-conventions';
6
+ import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-document-load';
7
+ import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
8
+ import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
9
+ import { UserInteractionInstrumentation } from '@opentelemetry/instrumentation-user-interaction';
10
+ import { ZoneContextManager } from '@opentelemetry/context-zone';
11
+ import { B3Propagator } from '@opentelemetry/propagator-b3';
12
+
13
+ // Telemetry configuration from environment or defaults
14
+ const TELEMETRY_CONFIG = {
15
+ serviceName: import.meta.env.VITE_OTEL_SERVICE_NAME || 'jetbook-performersportal',
16
+ serviceVersion: import.meta.env.VITE_OTEL_SERVICE_VERSION || '1.0.0',
17
+ environment: import.meta.env.VITE_ENVIRONMENT || 'development',
18
+ otlpEndpoint: import.meta.env.VITE_OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318/v1/traces',
19
+ tracesEnabled: import.meta.env.VITE_OTEL_TRACES_ENABLED !== 'false',
20
+ sampleRate: parseFloat(import.meta.env.VITE_OTEL_TRACES_SAMPLER_ARG || '0.1'), // 10% sampling by default
21
+ consoleDebug: import.meta.env.VITE_OTEL_DEBUG === 'true'
22
+ };
23
+
24
+ let tracer = null;
25
+ let tracerProvider = null;
26
+
27
+ // Helper to log telemetry events when debugging
28
+ function debugLog(message, data) {
29
+ if (TELEMETRY_CONFIG.consoleDebug) {
30
+ console.log(`[Telemetry] ${message}`, data || '');
31
+ }
32
+ }
33
+
34
+ // Initialize OpenTelemetry
35
+ export function initTelemetry() {
36
+ if (!TELEMETRY_CONFIG.tracesEnabled) {
37
+ console.log('[Telemetry] Tracing is disabled');
38
+ return;
39
+ }
40
+
41
+ try {
42
+ // Create resource with service information
43
+ const resource = new Resource({
44
+ [SEMRESATTRS_SERVICE_NAME]: TELEMETRY_CONFIG.serviceName,
45
+ [SEMRESATTRS_SERVICE_VERSION]: TELEMETRY_CONFIG.serviceVersion,
46
+ [SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]: TELEMETRY_CONFIG.environment,
47
+ 'browser.user_agent': navigator.userAgent,
48
+ 'browser.language': navigator.language,
49
+ 'browser.platform': navigator.platform
50
+ });
51
+
52
+ // Create tracer provider
53
+ tracerProvider = new WebTracerProvider({
54
+ resource,
55
+ sampler: {
56
+ shouldSample: () => {
57
+ return {
58
+ decision: Math.random() < TELEMETRY_CONFIG.sampleRate ? 1 : 0,
59
+ attributes: []
60
+ };
61
+ }
62
+ }
63
+ });
64
+
65
+ // Configure OTLP exporter
66
+ const exporter = new OTLPTraceExporter({
67
+ url: TELEMETRY_CONFIG.otlpEndpoint,
68
+ headers: {
69
+ 'Content-Type': 'application/json'
70
+ }
71
+ });
72
+
73
+ // Add batch span processor
74
+ tracerProvider.addSpanProcessor(new BatchSpanProcessor(exporter, {
75
+ maxQueueSize: 100,
76
+ maxExportBatchSize: 50,
77
+ scheduledDelayMillis: 500,
78
+ exportTimeoutMillis: 30000
79
+ }));
80
+
81
+ // Set global provider
82
+ tracerProvider.register({
83
+ contextManager: new ZoneContextManager(),
84
+ propagator: new B3Propagator()
85
+ });
86
+
87
+ // Enable browser instrumentations
88
+ // These auto-register with the global tracer provider when instantiated and enabled
89
+ new DocumentLoadInstrumentation({
90
+ applyCustomAttributesOnSpan: {
91
+ documentLoad: (span) => {
92
+ span.setAttribute('page.path', window.location.pathname);
93
+ span.setAttribute('page.search', window.location.search);
94
+ span.setAttribute('page.hash', window.location.hash);
95
+ span.setAttribute('portal.type', 'performers');
96
+ },
97
+ documentFetch: (span) => {
98
+ span.setAttribute('document.referrer', document.referrer);
99
+ }
100
+ }
101
+ }).enable();
102
+
103
+ new FetchInstrumentation({
104
+ propagateTraceHeaderCorsUrls: [
105
+ /^http:\/\/localhost:8080\/.*/,
106
+ /^https:\/\/api\.jetbook\.com\/.*/,
107
+ /^https:\/\/.*\.get-micdrop\.com\/.*/
108
+ ],
109
+ clearTimingResources: true,
110
+ applyCustomAttributesOnSpan: (span, request, response) => {
111
+ const url = new URL(request.url || '');
112
+ span.setAttribute('http.url.pathname', url.pathname);
113
+ span.setAttribute('http.url.search', url.search);
114
+ span.setAttribute('portal.type', 'performers');
115
+
116
+ if (response) {
117
+ span.setAttribute('http.response.status', response.status);
118
+ span.setAttribute('http.response.content_length', response.headers?.get('content-length') || 0);
119
+ }
120
+ }
121
+ }).enable();
122
+
123
+ new XMLHttpRequestInstrumentation({
124
+ propagateTraceHeaderCorsUrls: [
125
+ /^http:\/\/localhost:8080\/.*/,
126
+ /^https:\/\/api\.jetbook\.com\/.*/,
127
+ /^https:\/\/.*\.get-micdrop\.com\/.*/
128
+ ],
129
+ clearTimingResources: true
130
+ }).enable();
131
+
132
+ new UserInteractionInstrumentation({
133
+ eventNames: ['click', 'submit', 'change'],
134
+ shouldPreventSpanCreation: (eventType, element, span) => {
135
+ // Skip telemetry for certain elements
136
+ if (element.classList?.contains('no-telemetry')) {
137
+ return true;
138
+ }
139
+ // Skip very frequent events
140
+ if (eventType === 'change' && element.tagName === 'INPUT' && element.type === 'text') {
141
+ return true;
142
+ }
143
+ return false;
144
+ }
145
+ }).enable();
146
+
147
+ // Get tracer instance
148
+ tracer = tracerProvider.getTracer(
149
+ TELEMETRY_CONFIG.serviceName,
150
+ TELEMETRY_CONFIG.serviceVersion
151
+ );
152
+
153
+ debugLog('Telemetry initialized', TELEMETRY_CONFIG);
154
+ console.log(`[Telemetry] Initialized with ${TELEMETRY_CONFIG.sampleRate * 100}% sampling rate`);
155
+
156
+ } catch (error) {
157
+ console.error('[Telemetry] Failed to initialize:', error);
158
+ }
159
+ }
160
+
161
+ // Create custom span for tracking specific operations
162
+ export function startSpan(name, options = {}) {
163
+ if (!tracer) return null;
164
+
165
+ const span = tracer.startSpan(name, {
166
+ ...options,
167
+ attributes: {
168
+ 'span.kind': 'internal',
169
+ 'portal.type': 'performers',
170
+ ...options.attributes
171
+ }
172
+ });
173
+
174
+ debugLog(`Started span: ${name}`, options.attributes);
175
+ return span;
176
+ }
177
+
178
+ // End a span and set its status
179
+ export function endSpan(span, status = { code: 0 }) {
180
+ if (!span) return;
181
+
182
+ span.setStatus(status);
183
+ span.end();
184
+ debugLog(`Ended span: ${span.name}`, status);
185
+ }
186
+
187
+ // Track page views (for SPAs)
188
+ export function trackPageView(pagePath, pageTitle) {
189
+ if (!tracer) return;
190
+
191
+ const span = tracer.startSpan('page_view', {
192
+ attributes: {
193
+ 'page.path': pagePath,
194
+ 'page.title': pageTitle || document.title,
195
+ 'page.url': window.location.href,
196
+ 'page.referrer': document.referrer,
197
+ 'portal.type': 'performers'
198
+ }
199
+ });
200
+
201
+ span.end();
202
+ debugLog(`Tracked page view: ${pagePath}`);
203
+ }
204
+
205
+ // Track custom events
206
+ export function trackEvent(eventName, attributes = {}) {
207
+ if (!tracer) return;
208
+
209
+ const span = tracer.startSpan(`event.${eventName}`, {
210
+ attributes: {
211
+ 'event.name': eventName,
212
+ 'event.timestamp': new Date().toISOString(),
213
+ 'portal.type': 'performers',
214
+ ...attributes
215
+ }
216
+ });
217
+
218
+ span.end();
219
+ debugLog(`Tracked event: ${eventName}`, attributes);
220
+ }
221
+
222
+ // Track performer-specific actions
223
+ export function trackPerformerAction(action, metadata = {}) {
224
+ if (!tracer) return;
225
+
226
+ const span = tracer.startSpan(`performer.${action}`, {
227
+ attributes: {
228
+ 'performer.action': action,
229
+ 'performer.metadata': JSON.stringify(metadata),
230
+ 'portal.type': 'performers',
231
+ 'page.url': window.location.href,
232
+ 'timestamp': new Date().toISOString()
233
+ }
234
+ });
235
+
236
+ span.end();
237
+ debugLog(`Tracked performer action: ${action}`, metadata);
238
+ }
239
+
240
+ // Track errors
241
+ export function trackError(error, context = {}) {
242
+ if (!tracer) return;
243
+
244
+ const span = tracer.startSpan('error', {
245
+ attributes: {
246
+ 'error.message': error.message || String(error),
247
+ 'error.stack': error.stack,
248
+ 'error.type': error.name || 'Error',
249
+ 'error.context': JSON.stringify(context),
250
+ 'page.url': window.location.href,
251
+ 'portal.type': 'performers'
252
+ }
253
+ });
254
+
255
+ span.setStatus({ code: 2, message: error.message });
256
+ span.recordException(error);
257
+ span.end();
258
+
259
+ debugLog(`Tracked error: ${error.message}`, context);
260
+ }
261
+
262
+ // Track API calls with custom attributes
263
+ export function trackAPICall(method, endpoint, status, duration, attributes = {}) {
264
+ if (!tracer) return;
265
+
266
+ const span = tracer.startSpan('api_call', {
267
+ attributes: {
268
+ 'http.method': method,
269
+ 'http.url': endpoint,
270
+ 'http.status_code': status,
271
+ 'http.duration_ms': duration,
272
+ 'portal.type': 'performers',
273
+ ...attributes
274
+ }
275
+ });
276
+
277
+ span.setStatus({ code: status >= 400 ? 2 : 0 });
278
+ span.end();
279
+
280
+ debugLog(`Tracked API call: ${method} ${endpoint}`, { status, duration });
281
+ }
282
+
283
+ // Track user actions
284
+ export function trackUserAction(action, metadata = {}) {
285
+ if (!tracer) return;
286
+
287
+ const span = tracer.startSpan(`user.${action}`, {
288
+ attributes: {
289
+ 'user.action': action,
290
+ 'user.metadata': JSON.stringify(metadata),
291
+ 'portal.type': 'performers',
292
+ 'page.url': window.location.href,
293
+ 'timestamp': new Date().toISOString()
294
+ }
295
+ });
296
+
297
+ span.end();
298
+ debugLog(`Tracked user action: ${action}`, metadata);
299
+ }
300
+
301
+ // Shutdown telemetry gracefully
302
+ export async function shutdownTelemetry() {
303
+ if (tracerProvider) {
304
+ try {
305
+ await tracerProvider.shutdown();
306
+ console.log('[Telemetry] Shutdown complete');
307
+ } catch (error) {
308
+ console.error('[Telemetry] Shutdown error:', error);
309
+ }
310
+ }
311
+ }
312
+
313
+ // Connect client spans with SSR spans using trace context
314
+ function connectWithSSRTrace() {
315
+ // Check if we have trace context from SSR
316
+ const ssrTraceContext = window.__TRACE_CONTEXT__;
317
+ if (ssrTraceContext && tracer) {
318
+ // Create a span linked to the SSR span
319
+ const span = tracer.startSpan('client.performer.init', {
320
+ attributes: {
321
+ 'span.kind': 'client',
322
+ 'client.type': 'browser',
323
+ 'portal.type': 'performers',
324
+ 'ssr.trace_id': ssrTraceContext.traceId,
325
+ 'ssr.span_id': ssrTraceContext.spanId
326
+ },
327
+ links: [{
328
+ context: {
329
+ traceId: ssrTraceContext.traceId,
330
+ spanId: ssrTraceContext.spanId,
331
+ traceFlags: ssrTraceContext.traceFlags || 0
332
+ }
333
+ }]
334
+ });
335
+
336
+ span.end();
337
+ debugLog('Connected to SSR trace', ssrTraceContext);
338
+ }
339
+ }
340
+
341
+ // Auto-initialize on module load if in browser environment
342
+ if (typeof window !== 'undefined') {
343
+ // Initialize telemetry when DOM is ready
344
+ if (document.readyState === 'loading') {
345
+ document.addEventListener('DOMContentLoaded', () => {
346
+ initTelemetry();
347
+ connectWithSSRTrace();
348
+ });
349
+ } else {
350
+ initTelemetry();
351
+ connectWithSSRTrace();
352
+ }
353
+
354
+ // Cleanup on page unload
355
+ window.addEventListener('beforeunload', () => {
356
+ shutdownTelemetry();
357
+ });
358
358
  }