Conversation
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
react-server-docs | 111cfe8 | Mar 08 2026, 04:35 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds built-in OpenTelemetry integration to
@lazarv/react-server, providing distributed tracing and metrics for both development and production environments. When enabled, the runtime automatically instruments HTTP requests, SSR rendering, server functions, middleware, and cache operations — with zero runtime overhead when disabled.Motivation
Production React Server applications need observability to debug performance issues, trace requests across services, and monitor runtime behavior. Rather than requiring users to manually instrument their code, this PR bakes OpenTelemetry support directly into the framework — covering the full request lifecycle out of the box.
What's Included
Core Telemetry Engine (
server/telemetry.mjs— 609 lines)NodeSDKwith batch span processing, OTLP/HTTP trace & metric exporters, W3C trace context propagationBasicTracerProviderwithSimpleSpanProcessorfor immediate span output (no collector needed)getTracer(),getMeter(),withSpan(), etc.) resolve to no-op objects — zero allocations, zero overhead@opentelemetry/*packages are imported dynamically on first useshutdownTelemetry()flushes pending spans/metrics on server closeBuilt-in Instrumentation
Trace Spans:
HTTP RequestMiddleware: {name}Render(RSC / SSR)Server FunctionCache Lookup→Cache Hit/Cache Miss → RecomputeServer StartupVite Dev Server InitVite plugin [{name}].{hook}Metrics (7 instruments):
http.server.request.durationhttp.server.active_requestsreact_server.server_function.durationreact_server.rsc.render.durationreact_server.dom.render.durationreact_server.cache.hitsreact_server.cache.missesDev Console Exporter (
server/dev-trace-exporter.mjs— 419 lines)A pretty-printed terminal exporter that renders compact trace trees with:
Configuration & Validation
Config schema (
config/schema.mjs,config/schema.json,config/schema.d.ts):Environment variables:
REACT_SERVER_TELEMETRY=trueOTEL_EXPORTER_OTLP_ENDPOINTOTEL_SERVICE_NAMEValidation (
config/validate.mjs) — runtime validation with descriptive error messages for all telemetry config fields.Public API (
@lazarv/react-server/telemetry)New package export with full TypeScript types (
telemetry/index.d.ts— 156 lines):withSpan(name, attributes?, fn)— execute code within a child spangetSpan()— get the current request spangetTracer()— get the OpenTelemetry tracergetMeter()— get the OpenTelemetry metergetMetrics()— get built-in metric instrumentsgetOtelContext()— get the OTel context for the current requestinjectTraceContext(headers)— inject W3C trace context into outgoing headersBuild-time Tree Shaking
When telemetry is disabled at build time, all
@opentelemetry/*imports are force-resolved to empty modules via a newoptional-depsVite plugin, ensuring zero bundle impact.Edge Runtime Support
Lightweight telemetry for edge runtimes (Cloudflare Workers, Netlify Edge Functions) using
BasicTracerProvider+SimpleSpanProcessor. Traces only — metrics are not supported due to platform constraints.Documentation
Comprehensive documentation page (
docs/src/pages/en/(pages)/features/observability.mdx— 417 lines) covering:Tests
config-schema.spec.mjs— 62 lines testing schema generationconfig-validate.spec.mjs— 178 lines testing telemetry config validation (valid configs, invalid types, boundary values)Key Design Decisions
serviceNameoption over customResource— avoids cross-version@opentelemetry/resourcesclass incompatibilities under pnpm's strict hoisting (theresource.getRawAttributes is not a functionfix)OTEL_EXPORTER_OTLP_ENDPOINTis set