mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
* style(convex): apply prettier formatting to example-convex * refactor(convex): replace @opentelemetry/sdk-node with runtime-agnostic sdk-trace-base Remove "use node" directive from all Convex example files by switching from @opentelemetry/sdk-node (Node.js-only) to @opentelemetry/sdk-trace-base with BasicTracerProvider + BatchSpanProcessor. Add a performance polyfill for Convex's V8 isolate which lacks the performance global that @opentelemetry/core expects. * fix(convex): use class-based performance polyfill with relative timing * fix(convex): move tracer provider to module scope to avoid silent no-op trace.setGlobalTracerProvider() only applies on the first call — subsequent calls are silently ignored. Since Convex V8 isolates are warm-reused, the provider must be initialized at module scope. Per-request distinctId is already passed via experimental_telemetry metadata. * refactor(convex): extract OTEL provider setup into shared otelSetup.ts Move provider creation and global registration out of action files into a shared setup file. PostHogTraceExporter is now clearly framed as a standard OTEL span processor that sits alongside other exporters in the user's OTEL config, rather than owning the entire provider. * refactor(convex): inline OTEL setup back into individual example files Keep the provider setup co-located with the action so each example is self-contained and easy to follow without jumping between files. * fix(convex): remove competitor names from comments * style(convex): format example-convex files * fix(convex): use SimpleSpanProcessor instead of BatchSpanProcessor Convex actions terminate immediately after returning, so BatchSpanProcessor never gets a chance to flush. SimpleSpanProcessor sends spans synchronously, ensuring they're exported before the action completes.
15 lines
500 B
TypeScript
15 lines
500 B
TypeScript
// Convex runs in a V8 isolate that may not provide globals that
|
|
// @opentelemetry/core expects at module evaluation time. This file
|
|
// must be imported before any OTEL module.
|
|
|
|
// polyfill performance without using node:perf_hooks
|
|
if (typeof performance === 'undefined') {
|
|
class MockPerformance {
|
|
timeOrigin = Date.now()
|
|
now() {
|
|
return Date.now() - this.timeOrigin
|
|
}
|
|
}
|
|
globalThis.performance = new MockPerformance() as unknown as typeof performance
|
|
}
|