autotel-tanstack 1.13.35 → 1.13.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -5
- package/src/auto.test.ts +0 -114
- package/src/auto.ts +0 -60
- package/src/browser/context.ts +0 -88
- package/src/browser/debug-headers.ts +0 -19
- package/src/browser/error-reporting.ts +0 -64
- package/src/browser/handlers.ts +0 -23
- package/src/browser/index.ts +0 -66
- package/src/browser/loaders.ts +0 -62
- package/src/browser/metrics.ts +0 -86
- package/src/browser/middleware.ts +0 -77
- package/src/browser/server-functions.ts +0 -31
- package/src/browser/testing.ts +0 -130
- package/src/browser/types.ts +0 -100
- package/src/context.test.ts +0 -90
- package/src/context.ts +0 -145
- package/src/debug-headers.ts +0 -109
- package/src/env.ts +0 -56
- package/src/error-reporting.ts +0 -204
- package/src/handlers.ts +0 -306
- package/src/index.ts +0 -97
- package/src/instrument.test.ts +0 -131
- package/src/instrument.ts +0 -97
- package/src/loaders.test.ts +0 -123
- package/src/loaders.ts +0 -356
- package/src/metrics.ts +0 -184
- package/src/middleware.test.ts +0 -198
- package/src/middleware.ts +0 -435
- package/src/route-filter.test.ts +0 -28
- package/src/route-filter.ts +0 -40
- package/src/server-functions.test.ts +0 -86
- package/src/server-functions.ts +0 -188
- package/src/testing.test.ts +0 -205
- package/src/testing.ts +0 -430
- package/src/types.test.ts +0 -46
- package/src/types.ts +0 -182
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autotel-tanstack",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.36",
|
|
4
4
|
"description": "OpenTelemetry instrumentation for TanStack Start - automatic tracing for server functions, middleware, and route loaders",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -96,7 +96,6 @@
|
|
|
96
96
|
},
|
|
97
97
|
"files": [
|
|
98
98
|
"dist",
|
|
99
|
-
"src",
|
|
100
99
|
"README.md",
|
|
101
100
|
"skills"
|
|
102
101
|
],
|
|
@@ -120,9 +119,9 @@
|
|
|
120
119
|
"license": "MIT",
|
|
121
120
|
"dependencies": {
|
|
122
121
|
"@opentelemetry/api": "^1.9.1",
|
|
123
|
-
"autotel": "4.
|
|
124
|
-
"autotel-adapters": "0.3.
|
|
125
|
-
"autotel-edge": "3.17.
|
|
122
|
+
"autotel": "4.2.0",
|
|
123
|
+
"autotel-adapters": "0.3.13",
|
|
124
|
+
"autotel-edge": "3.17.1"
|
|
126
125
|
},
|
|
127
126
|
"peerDependencies": {
|
|
128
127
|
"@tanstack/react-start": "^1.168.25",
|
package/src/auto.test.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
|
|
3
|
-
// Must mock before importing auto.ts (which runs at module level)
|
|
4
|
-
const mockInit = vi.fn();
|
|
5
|
-
const mockReset = vi.fn();
|
|
6
|
-
const mockGetFinishedSpans = vi.fn(() => []);
|
|
7
|
-
|
|
8
|
-
vi.mock('autotel', () => ({
|
|
9
|
-
init: mockInit,
|
|
10
|
-
// instrument() guards on this; false so every test proceeds to init().
|
|
11
|
-
isInitialized: vi.fn(() => false),
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
const mockExporterInstance = {
|
|
15
|
-
reset: mockReset,
|
|
16
|
-
getFinishedSpans: mockGetFinishedSpans,
|
|
17
|
-
};
|
|
18
|
-
// Use regular function (not arrow) so vi.fn() can be called with `new` in vitest 4.x
|
|
19
|
-
const MockInMemorySpanExporter = vi.fn(function () {
|
|
20
|
-
return mockExporterInstance;
|
|
21
|
-
});
|
|
22
|
-
const MockSimpleSpanProcessor = vi.fn(function (exp: unknown) {
|
|
23
|
-
return { exporter: exp };
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
vi.mock('autotel/exporters', () => ({
|
|
27
|
-
InMemorySpanExporter: MockInMemorySpanExporter,
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
vi.mock('autotel/processors', () => ({
|
|
31
|
-
SimpleSpanProcessor: MockSimpleSpanProcessor,
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
describe('auto.ts E2E mode', () => {
|
|
35
|
-
const originalEnv = { ...process.env };
|
|
36
|
-
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
vi.resetModules();
|
|
39
|
-
mockInit.mockReset();
|
|
40
|
-
MockInMemorySpanExporter.mockClear();
|
|
41
|
-
MockSimpleSpanProcessor.mockClear();
|
|
42
|
-
delete (globalThis as Record<string, unknown>).__testSpanExporter;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
afterEach(() => {
|
|
46
|
-
process.env = { ...originalEnv };
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('uses InMemorySpanExporter when E2E=1', async () => {
|
|
50
|
-
process.env.E2E = '1';
|
|
51
|
-
delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
52
|
-
await import('./auto');
|
|
53
|
-
expect(MockInMemorySpanExporter).toHaveBeenCalledOnce();
|
|
54
|
-
expect(MockSimpleSpanProcessor).toHaveBeenCalledOnce();
|
|
55
|
-
expect(mockInit).toHaveBeenCalledWith(
|
|
56
|
-
expect.objectContaining({ spanProcessors: expect.any(Array) }),
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('sets globalThis.__testSpanExporter when E2E=1', async () => {
|
|
61
|
-
process.env.E2E = '1';
|
|
62
|
-
delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
63
|
-
await import('./auto');
|
|
64
|
-
expect((globalThis as Record<string, unknown>).__testSpanExporter).toBe(
|
|
65
|
-
mockExporterInstance,
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('does not set __testSpanExporter in production mode', async () => {
|
|
70
|
-
delete process.env.E2E;
|
|
71
|
-
delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
72
|
-
await import('./auto');
|
|
73
|
-
expect(
|
|
74
|
-
(globalThis as Record<string, unknown>).__testSpanExporter,
|
|
75
|
-
).toBeUndefined();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// Skipped: constructing a second OTLP BatchSpanProcessor requires
|
|
79
|
-
// @opentelemetry/exporter-trace-otlp-http which is not available in
|
|
80
|
-
// autotel-tanstack's direct dependencies. The combined E2E+OTLP path
|
|
81
|
-
// is tested at the integration level instead.
|
|
82
|
-
it.skip('adds both InMemory and OTLP processors when E2E=1 and endpoint set', async () => {
|
|
83
|
-
process.env.E2E = '1';
|
|
84
|
-
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://localhost:4318';
|
|
85
|
-
await import('./auto');
|
|
86
|
-
const call = mockInit.mock.calls[0][0] as { spanProcessors?: unknown[] };
|
|
87
|
-
expect(call.spanProcessors).toHaveLength(2);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('initializes in production mode without injecting an in-memory processor', async () => {
|
|
91
|
-
// The OTLP endpoint/headers are resolved by autotel core from env, so the
|
|
92
|
-
// zero-config path no longer passes them explicitly — it just inits.
|
|
93
|
-
delete process.env.E2E;
|
|
94
|
-
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://localhost:4318';
|
|
95
|
-
await import('./auto');
|
|
96
|
-
expect(mockInit).toHaveBeenCalledOnce();
|
|
97
|
-
const call = mockInit.mock.calls[0][0] as {
|
|
98
|
-
spanProcessors?: unknown[];
|
|
99
|
-
service?: string;
|
|
100
|
-
};
|
|
101
|
-
expect(call.spanProcessors).toBeUndefined();
|
|
102
|
-
expect(call.service).toBe('tanstack-start');
|
|
103
|
-
expect(MockInMemorySpanExporter).not.toHaveBeenCalled();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('uses OTEL_SERVICE_NAME env var', async () => {
|
|
107
|
-
process.env.E2E = '1';
|
|
108
|
-
process.env.OTEL_SERVICE_NAME = 'my-e2e-app';
|
|
109
|
-
await import('./auto');
|
|
110
|
-
expect(mockInit).toHaveBeenCalledWith(
|
|
111
|
-
expect.objectContaining({ service: 'my-e2e-app' }),
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
});
|
package/src/auto.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zero-config auto-instrumentation for TanStack Start.
|
|
3
|
-
*
|
|
4
|
-
* Importing this module configures OpenTelemetry tracing from environment
|
|
5
|
-
* variables — it is simply `instrument()` with no options. For subscribers,
|
|
6
|
-
* structured logs, canonical log lines, or an explicit endpoint, call
|
|
7
|
-
* `instrument(options)` from `autotel-tanstack` directly (see ./instrument).
|
|
8
|
-
*
|
|
9
|
-
* Environment Variables (resolved by autotel core):
|
|
10
|
-
* - OTEL_SERVICE_NAME: Service name (default: 'tanstack-start')
|
|
11
|
-
* - OTEL_EXPORTER_OTLP_ENDPOINT: OTLP collector URL
|
|
12
|
-
* - OTEL_EXPORTER_OTLP_HEADERS: Auth headers (key=value,key=value)
|
|
13
|
-
* - AUTOTEL_DEBUG: 'true' | 'pretty' to log spans to the server console
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* // app/start.ts
|
|
18
|
-
* import 'autotel-tanstack/auto';
|
|
19
|
-
* import { createStart } from '@tanstack/react-start';
|
|
20
|
-
* export const startInstance = createStart(() => ({}));
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @module
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import { instrument } from './instrument';
|
|
27
|
-
|
|
28
|
-
instrument();
|
|
29
|
-
|
|
30
|
-
// Surface what happened, in development only.
|
|
31
|
-
if (process.env.NODE_ENV === 'development' || process.env.AUTOTEL_DEBUG) {
|
|
32
|
-
console.log('[autotel-tanstack] Auto-initialized', {
|
|
33
|
-
service: process.env.OTEL_SERVICE_NAME || 'tanstack-start',
|
|
34
|
-
endpoint:
|
|
35
|
-
process.env.E2E === '1'
|
|
36
|
-
? '(E2E: in-memory)'
|
|
37
|
-
: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || '(not configured)',
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Re-export the configurable form + middleware/helpers for convenience.
|
|
42
|
-
export { instrument } from './instrument';
|
|
43
|
-
export { tracingMiddleware, functionTracingMiddleware } from './middleware';
|
|
44
|
-
export { traceServerFn } from './server-functions';
|
|
45
|
-
export { traceLoader, traceBeforeLoad } from './loaders';
|
|
46
|
-
|
|
47
|
-
/** Check if auto-instrumentation is active. */
|
|
48
|
-
export function isAutoInstrumentationActive(): boolean {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** The configured service name. */
|
|
53
|
-
export function getServiceName(): string {
|
|
54
|
-
return process.env.OTEL_SERVICE_NAME || 'tanstack-start';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** The configured OTLP endpoint, if any. */
|
|
58
|
-
export function getEndpoint(): string | undefined {
|
|
59
|
-
return process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
60
|
-
}
|
package/src/browser/context.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Intentional for type passthrough
|
|
58
|
-
export function withErrorReporting<T extends (...args: any[]) => any>(
|
|
59
|
-
fn: T,
|
|
60
|
-
context?: Record<string, unknown>,
|
|
61
|
-
): T {
|
|
62
|
-
void context;
|
|
63
|
-
return fn;
|
|
64
|
-
}
|
package/src/browser/handlers.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|
package/src/browser/index.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
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
|
-
createTracingServerHandler,
|
|
27
|
-
type MiddlewareHandler,
|
|
28
|
-
} from './middleware';
|
|
29
|
-
export {
|
|
30
|
-
extractContextFromRequest,
|
|
31
|
-
injectContextToHeaders,
|
|
32
|
-
createTracedHeaders,
|
|
33
|
-
runInContext,
|
|
34
|
-
getActiveContext,
|
|
35
|
-
getTraceParent,
|
|
36
|
-
getTraceState,
|
|
37
|
-
getCurrentTraceId,
|
|
38
|
-
getCurrentSpanId,
|
|
39
|
-
type HeadersInitType,
|
|
40
|
-
} from './context';
|
|
41
|
-
export { wrapStartHandler, type StartHandler } from './handlers';
|
|
42
|
-
export {
|
|
43
|
-
getMetrics,
|
|
44
|
-
recordTiming,
|
|
45
|
-
recordError,
|
|
46
|
-
resetMetrics,
|
|
47
|
-
metricsCollector,
|
|
48
|
-
createMetricsHandler,
|
|
49
|
-
type MetricsData,
|
|
50
|
-
} from './metrics';
|
|
51
|
-
export {
|
|
52
|
-
reportError,
|
|
53
|
-
getRecentErrors,
|
|
54
|
-
clearErrors,
|
|
55
|
-
createErrorReportingHandler,
|
|
56
|
-
withErrorReporting,
|
|
57
|
-
type ErrorEntry,
|
|
58
|
-
} from './error-reporting';
|
|
59
|
-
export { debugHeadersMiddleware } from './debug-headers';
|
|
60
|
-
export {
|
|
61
|
-
createTestCollector,
|
|
62
|
-
assertSpanCreated,
|
|
63
|
-
assertSpanHasAttribute,
|
|
64
|
-
type TestSpan,
|
|
65
|
-
type TestCollector,
|
|
66
|
-
} from './testing';
|
package/src/browser/loaders.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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
|
-
}
|
package/src/browser/metrics.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
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
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Browser stub: Returns pass-through handler for createMiddleware().server()
|
|
65
|
-
*/
|
|
66
|
-
export function createTracingServerHandler<TContext = unknown>(
|
|
67
|
-
config?: TracingMiddlewareConfig,
|
|
68
|
-
): (opts: {
|
|
69
|
-
next: (ctx?: Partial<TContext>) => Promise<TContext>;
|
|
70
|
-
context: TContext;
|
|
71
|
-
request?: Request;
|
|
72
|
-
}) => Promise<TContext> {
|
|
73
|
-
void config;
|
|
74
|
-
return async function noopHandler(opts) {
|
|
75
|
-
return opts.next();
|
|
76
|
-
};
|
|
77
|
-
}
|