autotel-tanstack 1.1.0

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 (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +294 -0
  3. package/dist/auto.d.ts +44 -0
  4. package/dist/auto.js +47 -0
  5. package/dist/auto.js.map +1 -0
  6. package/dist/browser/context.d.ts +48 -0
  7. package/dist/browser/context.js +3 -0
  8. package/dist/browser/context.js.map +1 -0
  9. package/dist/browser/debug-headers.d.ts +16 -0
  10. package/dist/browser/debug-headers.js +3 -0
  11. package/dist/browser/debug-headers.js.map +1 -0
  12. package/dist/browser/error-reporting.d.ts +37 -0
  13. package/dist/browser/error-reporting.js +3 -0
  14. package/dist/browser/error-reporting.js.map +1 -0
  15. package/dist/browser/handlers.d.ts +19 -0
  16. package/dist/browser/handlers.js +3 -0
  17. package/dist/browser/handlers.js.map +1 -0
  18. package/dist/browser/index.d.ts +10 -0
  19. package/dist/browser/index.js +12 -0
  20. package/dist/browser/index.js.map +1 -0
  21. package/dist/browser/loaders.d.ts +36 -0
  22. package/dist/browser/loaders.js +3 -0
  23. package/dist/browser/loaders.js.map +1 -0
  24. package/dist/browser/metrics.d.ts +54 -0
  25. package/dist/browser/metrics.js +3 -0
  26. package/dist/browser/metrics.js.map +1 -0
  27. package/dist/browser/middleware.d.ts +39 -0
  28. package/dist/browser/middleware.js +3 -0
  29. package/dist/browser/middleware.js.map +1 -0
  30. package/dist/browser/server-functions.d.ts +19 -0
  31. package/dist/browser/server-functions.js +3 -0
  32. package/dist/browser/server-functions.js.map +1 -0
  33. package/dist/browser/testing.d.ts +45 -0
  34. package/dist/browser/testing.js +3 -0
  35. package/dist/browser/testing.js.map +1 -0
  36. package/dist/browser/types.d.ts +85 -0
  37. package/dist/browser/types.js +3 -0
  38. package/dist/browser/types.js.map +1 -0
  39. package/dist/chunk-4C7T5ZIM.js +20 -0
  40. package/dist/chunk-4C7T5ZIM.js.map +1 -0
  41. package/dist/chunk-CSFIPJC2.js +11 -0
  42. package/dist/chunk-CSFIPJC2.js.map +1 -0
  43. package/dist/chunk-DTZCOB4W.js +32 -0
  44. package/dist/chunk-DTZCOB4W.js.map +1 -0
  45. package/dist/chunk-EGRHWZRV.js +3 -0
  46. package/dist/chunk-EGRHWZRV.js.map +1 -0
  47. package/dist/chunk-EUYFVNYE.js +16 -0
  48. package/dist/chunk-EUYFVNYE.js.map +1 -0
  49. package/dist/chunk-HIQYW2HB.js +20 -0
  50. package/dist/chunk-HIQYW2HB.js.map +1 -0
  51. package/dist/chunk-HKM7LMO6.js +129 -0
  52. package/dist/chunk-HKM7LMO6.js.map +1 -0
  53. package/dist/chunk-I4LX3LOG.js +35 -0
  54. package/dist/chunk-I4LX3LOG.js.map +1 -0
  55. package/dist/chunk-JSI6QG7M.js +96 -0
  56. package/dist/chunk-JSI6QG7M.js.map +1 -0
  57. package/dist/chunk-JXO7H6KO.js +10 -0
  58. package/dist/chunk-JXO7H6KO.js.map +1 -0
  59. package/dist/chunk-MFYOV2SF.js +32 -0
  60. package/dist/chunk-MFYOV2SF.js.map +1 -0
  61. package/dist/chunk-MNP65ZX7.js +21 -0
  62. package/dist/chunk-MNP65ZX7.js.map +1 -0
  63. package/dist/chunk-NTY64BKS.js +38 -0
  64. package/dist/chunk-NTY64BKS.js.map +1 -0
  65. package/dist/chunk-OLBHLVLE.js +220 -0
  66. package/dist/chunk-OLBHLVLE.js.map +1 -0
  67. package/dist/chunk-TNOQTZ3N.js +92 -0
  68. package/dist/chunk-TNOQTZ3N.js.map +1 -0
  69. package/dist/chunk-UMEJU65Q.js +34 -0
  70. package/dist/chunk-UMEJU65Q.js.map +1 -0
  71. package/dist/chunk-UTPW3QRT.js +52 -0
  72. package/dist/chunk-UTPW3QRT.js.map +1 -0
  73. package/dist/chunk-V3RO5N2M.js +8 -0
  74. package/dist/chunk-V3RO5N2M.js.map +1 -0
  75. package/dist/chunk-XXBHZR3M.js +99 -0
  76. package/dist/chunk-XXBHZR3M.js.map +1 -0
  77. package/dist/chunk-Z3MJ3GZ6.js +18 -0
  78. package/dist/chunk-Z3MJ3GZ6.js.map +1 -0
  79. package/dist/chunk-Z5D2V4DU.js +216 -0
  80. package/dist/chunk-Z5D2V4DU.js.map +1 -0
  81. package/dist/context.d.ts +94 -0
  82. package/dist/context.js +4 -0
  83. package/dist/context.js.map +1 -0
  84. package/dist/debug-headers.d.ts +43 -0
  85. package/dist/debug-headers.js +5 -0
  86. package/dist/debug-headers.js.map +1 -0
  87. package/dist/error-reporting.d.ts +118 -0
  88. package/dist/error-reporting.js +4 -0
  89. package/dist/error-reporting.js.map +1 -0
  90. package/dist/handlers.d.ts +70 -0
  91. package/dist/handlers.js +6 -0
  92. package/dist/handlers.js.map +1 -0
  93. package/dist/index.d.ts +34 -0
  94. package/dist/index.js +14 -0
  95. package/dist/index.js.map +1 -0
  96. package/dist/loaders.d.ts +124 -0
  97. package/dist/loaders.js +6 -0
  98. package/dist/loaders.js.map +1 -0
  99. package/dist/metrics.d.ts +113 -0
  100. package/dist/metrics.js +4 -0
  101. package/dist/metrics.js.map +1 -0
  102. package/dist/middleware.d.ts +104 -0
  103. package/dist/middleware.js +7 -0
  104. package/dist/middleware.js.map +1 -0
  105. package/dist/server-functions.d.ts +71 -0
  106. package/dist/server-functions.js +6 -0
  107. package/dist/server-functions.js.map +1 -0
  108. package/dist/testing.d.ts +128 -0
  109. package/dist/testing.js +110 -0
  110. package/dist/testing.js.map +1 -0
  111. package/dist/types-C37KSxMN.d.ts +152 -0
  112. package/package.json +166 -0
  113. package/src/auto.ts +86 -0
  114. package/src/browser/context.ts +88 -0
  115. package/src/browser/debug-headers.ts +19 -0
  116. package/src/browser/error-reporting.ts +63 -0
  117. package/src/browser/handlers.ts +23 -0
  118. package/src/browser/index.ts +65 -0
  119. package/src/browser/loaders.ts +62 -0
  120. package/src/browser/metrics.ts +86 -0
  121. package/src/browser/middleware.ts +61 -0
  122. package/src/browser/server-functions.ts +31 -0
  123. package/src/browser/testing.ts +67 -0
  124. package/src/browser/types.ts +100 -0
  125. package/src/context.test.ts +90 -0
  126. package/src/context.ts +145 -0
  127. package/src/debug-headers.ts +109 -0
  128. package/src/env.ts +56 -0
  129. package/src/error-reporting.ts +204 -0
  130. package/src/handlers.ts +339 -0
  131. package/src/index.ts +92 -0
  132. package/src/loaders.test.ts +123 -0
  133. package/src/loaders.ts +267 -0
  134. package/src/metrics.ts +183 -0
  135. package/src/middleware.test.ts +191 -0
  136. package/src/middleware.ts +400 -0
  137. package/src/server-functions.test.ts +86 -0
  138. package/src/server-functions.ts +184 -0
  139. package/src/testing.test.ts +72 -0
  140. package/src/testing.ts +276 -0
  141. package/src/types.test.ts +46 -0
  142. package/src/types.ts +182 -0
package/src/auto.ts ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Zero-config auto-instrumentation for TanStack Start
3
+ *
4
+ * Import this module to automatically instrument TanStack Start applications
5
+ * with OpenTelemetry tracing. Configuration is read from environment variables.
6
+ *
7
+ * Environment Variables:
8
+ * - OTEL_SERVICE_NAME: Service name (default: 'tanstack-start')
9
+ * - OTEL_EXPORTER_OTLP_ENDPOINT: OTLP collector URL
10
+ * - OTEL_EXPORTER_OTLP_HEADERS: Authentication headers (key=value,key=value)
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * // app/start.ts
15
+ * import 'autotel-tanstack/auto';
16
+ * import { createStart } from '@tanstack/react-start';
17
+ *
18
+ * // Tracing is automatically configured!
19
+ * export const startInstance = createStart(() => ({}));
20
+ * ```
21
+ *
22
+ * @module
23
+ */
24
+
25
+ import { init } from 'autotel';
26
+
27
+ // Parse service name
28
+ const service = process.env.OTEL_SERVICE_NAME || 'tanstack-start';
29
+
30
+ // Parse endpoint
31
+ const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
32
+
33
+ // Parse headers
34
+ let headers: Record<string, string> | undefined;
35
+ if (process.env.OTEL_EXPORTER_OTLP_HEADERS) {
36
+ headers = {};
37
+ const pairs = process.env.OTEL_EXPORTER_OTLP_HEADERS.split(',');
38
+ for (const pair of pairs) {
39
+ const [key, value] = pair.split('=');
40
+ if (key && value) {
41
+ headers[key.trim()] = value.trim();
42
+ }
43
+ }
44
+ }
45
+
46
+ // Initialize autotel
47
+ init({
48
+ service,
49
+ endpoint,
50
+ headers,
51
+ });
52
+
53
+ // Log initialization (only in development)
54
+ if (process.env.NODE_ENV === 'development' || process.env.AUTOTEL_DEBUG) {
55
+ console.log('[autotel-tanstack] Auto-initialized with:', {
56
+ service,
57
+ endpoint: endpoint || '(not configured)',
58
+ hasHeaders: !!headers,
59
+ });
60
+ }
61
+
62
+ // Re-export middleware for convenience
63
+ export { tracingMiddleware, functionTracingMiddleware } from './middleware';
64
+ export { traceServerFn } from './server-functions';
65
+ export { traceLoader, traceBeforeLoad } from './loaders';
66
+
67
+ /**
68
+ * Check if auto-instrumentation is active
69
+ */
70
+ export function isAutoInstrumentationActive(): boolean {
71
+ return true;
72
+ }
73
+
74
+ /**
75
+ * Get the configured service name
76
+ */
77
+ export function getServiceName(): string {
78
+ return service;
79
+ }
80
+
81
+ /**
82
+ * Get the configured endpoint
83
+ */
84
+ export function getEndpoint(): string | undefined {
85
+ return endpoint;
86
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Browser stub for context module
3
+ *
4
+ * In browser environments, context propagation is not needed.
5
+ * These functions return empty/default values.
6
+ */
7
+
8
+ /**
9
+ * Type representing values that can be used to initialize Headers
10
+ */
11
+ export type HeadersInitType =
12
+ | Headers
13
+ | Record<string, string>
14
+ | [string, string][];
15
+
16
+ /**
17
+ * Browser stub: Returns root context (no parent)
18
+ */
19
+ export function extractContextFromRequest(_request: Request): unknown {
20
+ void _request;
21
+ // Return an empty context-like object
22
+ return {};
23
+ }
24
+
25
+ /**
26
+ * Browser stub: Returns headers unchanged
27
+ */
28
+ export function injectContextToHeaders(
29
+ headers: Headers,
30
+ ctx?: unknown,
31
+ ): Headers {
32
+ void ctx;
33
+ return headers;
34
+ }
35
+
36
+ /**
37
+ * Browser stub: Create headers with optional initial values
38
+ */
39
+ export function createTracedHeaders(
40
+ existingHeaders?: HeadersInitType,
41
+ ctx?: unknown,
42
+ ): Headers {
43
+ void ctx;
44
+ return new Headers(existingHeaders);
45
+ }
46
+
47
+ /**
48
+ * Browser stub: Run function and return result
49
+ */
50
+ export function runInContext<T>(parentContext: unknown, fn: () => T): T {
51
+ void parentContext;
52
+ return fn();
53
+ }
54
+
55
+ /**
56
+ * Browser stub: Returns empty context object
57
+ */
58
+ export function getActiveContext(): unknown {
59
+ return {};
60
+ }
61
+
62
+ /**
63
+ * Browser stub: Returns empty string
64
+ */
65
+ export function getTraceParent(): string {
66
+ return '';
67
+ }
68
+
69
+ /**
70
+ * Browser stub: Returns empty string
71
+ */
72
+ export function getTraceState(): string {
73
+ return '';
74
+ }
75
+
76
+ /**
77
+ * Browser stub: Returns undefined
78
+ */
79
+ export function getCurrentTraceId(): string | undefined {
80
+ return undefined;
81
+ }
82
+
83
+ /**
84
+ * Browser stub: Returns undefined
85
+ */
86
+ export function getCurrentSpanId(): string | undefined {
87
+ return undefined;
88
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Browser stub for debug-headers module
3
+ *
4
+ * Debug headers are server-side only.
5
+ * In browser, this returns pass-through middleware.
6
+ */
7
+
8
+ import type { MiddlewareHandler } from './middleware';
9
+
10
+ /**
11
+ * Browser stub: Returns pass-through middleware
12
+ */
13
+ export function debugHeadersMiddleware<
14
+ TContext = unknown,
15
+ >(): MiddlewareHandler<TContext> {
16
+ return async function noopMiddleware(opts) {
17
+ return opts.next();
18
+ };
19
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Browser stub for error-reporting module
3
+ *
4
+ * Error reporting/collection only happens on the server.
5
+ * In browser, these are no-op functions.
6
+ */
7
+
8
+ /**
9
+ * Error entry structure (stub)
10
+ */
11
+ export interface ErrorEntry {
12
+ timestamp: string;
13
+ message: string;
14
+ stack?: string;
15
+ context?: Record<string, unknown>;
16
+ }
17
+
18
+ /**
19
+ * Browser stub: No-op
20
+ */
21
+ export function reportError(
22
+ error: Error,
23
+ context?: Record<string, unknown>,
24
+ ): void {
25
+ void error;
26
+ void context;
27
+ // No-op in browser
28
+ }
29
+
30
+ /**
31
+ * Browser stub: Returns empty array
32
+ */
33
+ export function getRecentErrors(limit?: number): ErrorEntry[] {
34
+ void limit;
35
+ return [];
36
+ }
37
+
38
+ /**
39
+ * Browser stub: No-op
40
+ */
41
+ export function clearErrors(): void {
42
+ // No-op in browser
43
+ }
44
+
45
+ /**
46
+ * Browser stub: Returns JSON Response with empty errors
47
+ */
48
+ export function createErrorReportingHandler(): () => Response {
49
+ return () => {
50
+ return Response.json({ errors: [], count: 0 });
51
+ };
52
+ }
53
+
54
+ /**
55
+ * Browser stub: Returns function unchanged
56
+ */
57
+ export function withErrorReporting<T extends (...args: unknown[]) => unknown>(
58
+ fn: T,
59
+ context?: Record<string, unknown>,
60
+ ): T {
61
+ void context;
62
+ return fn;
63
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Browser stub for handlers module
3
+ *
4
+ * Handler wrapping only applies on the server side.
5
+ * In browser, we just return the handler unchanged.
6
+ */
7
+
8
+ import type { WrapStartHandlerConfig } from './types';
9
+
10
+ /**
11
+ * Handler type
12
+ */
13
+ export type StartHandler<T = unknown> = (request: Request) => Promise<T>;
14
+
15
+ /**
16
+ * Browser stub: Returns the handler unchanged
17
+ */
18
+ export function wrapStartHandler<T>(
19
+ config?: WrapStartHandlerConfig,
20
+ ): (handler: StartHandler<T>) => StartHandler<T> {
21
+ void config;
22
+ return (handler) => handler;
23
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Browser entry point for autotel-tanstack
3
+ *
4
+ * This module provides no-op stubs for all exports to prevent
5
+ * @opentelemetry/api and autotel from being bundled in client code.
6
+ */
7
+
8
+ // Export types from types.ts (single source of truth)
9
+ export type {
10
+ Attributes,
11
+ TanStackInstrumentationConfig,
12
+ TracingMiddlewareConfig,
13
+ TraceServerFnConfig,
14
+ TraceLoaderConfig,
15
+ WrapStartHandlerConfig,
16
+ } from './types';
17
+ export { DEFAULT_CONFIG, SPAN_ATTRIBUTES } from './types';
18
+
19
+ // Export functions from each module (excluding their duplicate type exports)
20
+ export { traceLoader, traceBeforeLoad, createTracedRoute } from './loaders';
21
+ export { traceServerFn, createTracedServerFnFactory } from './server-functions';
22
+ export {
23
+ createTracingMiddleware,
24
+ tracingMiddleware,
25
+ functionTracingMiddleware,
26
+ type MiddlewareHandler,
27
+ } from './middleware';
28
+ export {
29
+ extractContextFromRequest,
30
+ injectContextToHeaders,
31
+ createTracedHeaders,
32
+ runInContext,
33
+ getActiveContext,
34
+ getTraceParent,
35
+ getTraceState,
36
+ getCurrentTraceId,
37
+ getCurrentSpanId,
38
+ type HeadersInitType,
39
+ } from './context';
40
+ export { wrapStartHandler, type StartHandler } from './handlers';
41
+ export {
42
+ getMetrics,
43
+ recordTiming,
44
+ recordError,
45
+ resetMetrics,
46
+ metricsCollector,
47
+ createMetricsHandler,
48
+ type MetricsData,
49
+ } from './metrics';
50
+ export {
51
+ reportError,
52
+ getRecentErrors,
53
+ clearErrors,
54
+ createErrorReportingHandler,
55
+ withErrorReporting,
56
+ type ErrorEntry,
57
+ } from './error-reporting';
58
+ export { debugHeadersMiddleware } from './debug-headers';
59
+ export {
60
+ createTestCollector,
61
+ assertSpanCreated,
62
+ assertSpanHasAttribute,
63
+ type TestSpan,
64
+ type TestCollector,
65
+ } from './testing';
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Browser stub for loaders module
3
+ *
4
+ * In browser environments, these functions are no-ops that just call the
5
+ * original functions without any tracing overhead.
6
+ */
7
+
8
+ import type { TraceLoaderConfig } from './types';
9
+
10
+ /**
11
+ * Loader context type (compatible with TanStack router loader context)
12
+ */
13
+ interface LoaderContext {
14
+ params?: Record<string, string>;
15
+ route?: {
16
+ id?: string;
17
+ };
18
+ [key: string]: unknown;
19
+ }
20
+
21
+ /**
22
+ * Browser stub: Returns the loader function unchanged
23
+ */
24
+ export function traceLoader<
25
+ T extends (context: LoaderContext) => Promise<unknown>,
26
+ >(loaderFn: T, config?: TraceLoaderConfig): T {
27
+ void config;
28
+ return loaderFn;
29
+ }
30
+
31
+ /**
32
+ * Browser stub: Returns the beforeLoad function unchanged
33
+ */
34
+ export function traceBeforeLoad<
35
+ T extends (context: LoaderContext) => Promise<unknown>,
36
+ >(beforeLoadFn: T, config?: TraceLoaderConfig): T {
37
+ void config;
38
+ return beforeLoadFn;
39
+ }
40
+
41
+ /**
42
+ * Browser stub: Returns object with pass-through wrappers
43
+ */
44
+ export function createTracedRoute(
45
+ routeId: string,
46
+ config?: Omit<TraceLoaderConfig, 'name'>,
47
+ ) {
48
+ void routeId;
49
+ void config;
50
+ return {
51
+ loader<T extends (context: LoaderContext) => Promise<unknown>>(
52
+ loaderFn: T,
53
+ ): T {
54
+ return loaderFn;
55
+ },
56
+ beforeLoad<T extends (context: LoaderContext) => Promise<unknown>>(
57
+ beforeLoadFn: T,
58
+ ): T {
59
+ return beforeLoadFn;
60
+ },
61
+ };
62
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Browser stub for metrics module
3
+ *
4
+ * Metrics collection only happens on the server.
5
+ * In browser, these are no-op functions.
6
+ */
7
+
8
+ /**
9
+ * Metrics data structure (stub)
10
+ */
11
+ export interface MetricsData {
12
+ requestCount: number;
13
+ errorCount: number;
14
+ avgLatency: number;
15
+ p50Latency: number;
16
+ p95Latency: number;
17
+ p99Latency: number;
18
+ requestsPerSecond: number;
19
+ endpoints: Record<
20
+ string,
21
+ {
22
+ count: number;
23
+ errors: number;
24
+ avgLatency: number;
25
+ }
26
+ >;
27
+ }
28
+
29
+ /**
30
+ * Browser stub: Returns empty metrics
31
+ */
32
+ export function getMetrics(): MetricsData {
33
+ return {
34
+ requestCount: 0,
35
+ errorCount: 0,
36
+ avgLatency: 0,
37
+ p50Latency: 0,
38
+ p95Latency: 0,
39
+ p99Latency: 0,
40
+ requestsPerSecond: 0,
41
+ endpoints: {},
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Browser stub: No-op
47
+ */
48
+ export function recordTiming(name: string, durationMs: number): void {
49
+ void name;
50
+ void durationMs;
51
+ // No-op in browser
52
+ }
53
+
54
+ /**
55
+ * Browser stub: No-op
56
+ */
57
+ export function recordError(name: string): void {
58
+ void name;
59
+ // No-op in browser
60
+ }
61
+
62
+ /**
63
+ * Browser stub: No-op
64
+ */
65
+ export function resetMetrics(): void {
66
+ // No-op in browser
67
+ }
68
+
69
+ /**
70
+ * Browser stub: No-op metrics collector
71
+ */
72
+ export const metricsCollector = {
73
+ recordTiming: recordTiming,
74
+ recordError: recordError,
75
+ getMetrics: getMetrics,
76
+ reset: resetMetrics,
77
+ };
78
+
79
+ /**
80
+ * Browser stub: Returns JSON Response with empty metrics
81
+ */
82
+ export function createMetricsHandler(): () => Response {
83
+ return () => {
84
+ return Response.json(getMetrics());
85
+ };
86
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Browser stub for middleware module
3
+ *
4
+ * In browser environments, these functions return pass-through middleware
5
+ * that just calls next() without any tracing overhead.
6
+ */
7
+
8
+ import type { TracingMiddlewareConfig } from './types';
9
+
10
+ /**
11
+ * Generic middleware handler type
12
+ */
13
+ export interface MiddlewareHandler<TContext = unknown> {
14
+ (opts: {
15
+ next: (ctx?: Partial<TContext>) => Promise<TContext>;
16
+ context: TContext;
17
+ request?: Request;
18
+ pathname?: string;
19
+ data?: unknown;
20
+ method?: string;
21
+ filename?: string;
22
+ functionId?: string;
23
+ signal?: AbortSignal;
24
+ }): Promise<TContext>;
25
+ }
26
+
27
+ /**
28
+ * Browser stub: Returns pass-through middleware
29
+ */
30
+ export function createTracingMiddleware<TContext = unknown>(
31
+ config?: TracingMiddlewareConfig,
32
+ ): MiddlewareHandler<TContext> {
33
+ void config;
34
+ return async function noopMiddleware(opts) {
35
+ return opts.next();
36
+ };
37
+ }
38
+
39
+ /**
40
+ * Browser stub: Returns pass-through middleware
41
+ */
42
+ export function tracingMiddleware<TContext = unknown>(
43
+ config?: TracingMiddlewareConfig,
44
+ ): MiddlewareHandler<TContext> {
45
+ void config;
46
+ return async function noopMiddleware(opts) {
47
+ return opts.next();
48
+ };
49
+ }
50
+
51
+ /**
52
+ * Browser stub: Returns pass-through middleware
53
+ */
54
+ export function functionTracingMiddleware<TContext = unknown>(
55
+ config?: Omit<TracingMiddlewareConfig, 'type'>,
56
+ ): MiddlewareHandler<TContext> {
57
+ void config;
58
+ return async function noopMiddleware(opts) {
59
+ return opts.next();
60
+ };
61
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Browser stub for server-functions module
3
+ *
4
+ * In browser environments, these functions are no-ops that just return
5
+ * the original functions without any tracing overhead.
6
+ */
7
+
8
+ import type { TraceServerFnConfig } from './types';
9
+
10
+ /**
11
+ * Browser stub: Returns the server function unchanged
12
+ */
13
+ export function traceServerFn<
14
+ T extends (...args: unknown[]) => Promise<unknown>,
15
+ >(serverFn: T, config?: TraceServerFnConfig): T {
16
+ void config;
17
+ return serverFn;
18
+ }
19
+
20
+ /**
21
+ * Browser stub: Returns the createServerFn unchanged
22
+ */
23
+ export function createTracedServerFnFactory<
24
+ TCreateServerFn extends (...args: unknown[]) => unknown,
25
+ >(
26
+ createServerFnOriginal: TCreateServerFn,
27
+ defaultConfig?: Omit<TraceServerFnConfig, 'name'>,
28
+ ): TCreateServerFn {
29
+ void defaultConfig;
30
+ return createServerFnOriginal;
31
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Browser stub for testing module
3
+ *
4
+ * Testing utilities are server-side only.
5
+ * In browser, these return no-op implementations.
6
+ */
7
+
8
+ /**
9
+ * Test span structure (stub)
10
+ */
11
+ export interface TestSpan {
12
+ name: string;
13
+ attributes: Record<string, unknown>;
14
+ status: { code: number; message?: string };
15
+ events: Array<{ name: string; attributes?: Record<string, unknown> }>;
16
+ duration: number;
17
+ }
18
+
19
+ /**
20
+ * Test collector structure (stub)
21
+ */
22
+ export interface TestCollector {
23
+ getSpans(): TestSpan[];
24
+ getSpansByName(name: string): TestSpan[];
25
+ clear(): void;
26
+ waitForSpans(count: number, timeout?: number): Promise<TestSpan[]>;
27
+ }
28
+
29
+ /**
30
+ * Browser stub: Returns empty collector
31
+ */
32
+ export function createTestCollector(): TestCollector {
33
+ return {
34
+ getSpans: () => [],
35
+ getSpansByName: () => [],
36
+ clear: () => {},
37
+ waitForSpans: async () => [],
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Browser stub: No-op
43
+ */
44
+ export function assertSpanCreated(
45
+ collector: TestCollector,
46
+ name: string,
47
+ ): void {
48
+ void collector;
49
+ void name;
50
+ // No-op in browser
51
+ }
52
+
53
+ /**
54
+ * Browser stub: No-op
55
+ */
56
+ export function assertSpanHasAttribute(
57
+ collector: TestCollector,
58
+ name: string,
59
+ key: string,
60
+ value?: unknown,
61
+ ): void {
62
+ void collector;
63
+ void name;
64
+ void key;
65
+ void value;
66
+ // No-op in browser
67
+ }