Add OpenTelemetry spans across SSR handler and extract pipeline - #226
Open
Uttkarsh-Srivastava wants to merge 3 commits into
Open
Uttkarsh-Srivastava wants to merge 3 commits into
Uttkarsh-Srivastava wants to merge 3 commits into
Conversation
Instrument the SSR request path with withObservability / withSyncObservability wrappers around handler, getMatchRoutes, renderToString dry-run, App.serverSideFunction, serverDataFetcher, getMetaData, renderMarkUp, res.write/end, and user lifecycle hooks. otel.js now exposes the wrappers and supports gRPC/HTTP exporters with parent-based sampling and optional metrics. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
DeputyDev will no longer review pull requests automatically.To request a review, simply comment #review on your pull request—this will trigger an on-demand review whenever you need it. |
Adds the otel packages required by src/otel.js as peerDependencies so consuming apps provide a single shared installation — avoiding duplicate otel instances across the framework and host app. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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 OpenTelemetry tracing across the SSR request pipeline so that individual stages of each request surface as
spans in the trace. Inspiration was taken from
feature/handler-observability-v3; only the observabilityinstrumentation was pulled in — unrelated refactors on that branch (CSS cache rewrite, per-route
ChunkExtractorcache, safe-area removal, new
onAppServerSide*hooks,fetcherData.errorflow change) are intentionally left out.Changes
src/otel.jswithObservability(async-safe) andwithSyncObservabilitywrappers that start an active span, recordexceptions, and close the span in
finally.grpcandhttp), selected via newtraceProtocol/metricProtocoloptions.metricProtocolis provided.ParentBasedSampler+TraceIdRatioBasedSamplerdriven by a newsamplingRateoption (default1.0).batchProcessorConfig,instrumentations, andgrpcCredentialspassthroughs oninit().src/server/renderer/extract.jsextractAssets) andcacheAndFetchAssetswithwithSyncObservability.src/server/renderer/handler.jsSSR_SERVICE(process.env.SERVICE_NAME→pwa-${APPLICATION}-node-server-otel).onRouteMatch,onFetcherSuccess,onFetcherError,onRenderError,onRequestError) via atraceHandlerHookhelper that no-ops when the hook isn't a function.getMatchRoutesinto an internal_getMatchRoutes(recursive, no span-per-frame) and a wrapped outerspan.
renderToStringinsidegetMatchRoutesinto its ownrenderToStringspan.App.serverSideFunction,serverDataFetcher,getMetaData, andrenderMarkUp.res.write(firstFoldCss),res.write(firstFoldJS), andres.end()during theonAllReadystreamcompletion so TTFB-relevant writes are visible on the trace.
withObservability(_handler, "handler")— every request yields a root SSR span.Safe-area header handling, extractor creation per-request, and the existing error-flow semantics are preserved
exactly as on
main.Span tree (per SSR request)
handler
├── getMatchRoutes
│ └── renderToString (dry-run for ChunkExtractor)
├── onRouteMatch (if defined)
├── App.serverSideFunction
├── serverDataFetcher
├── getMetaData
├── onFetcherSuccess / onFetcherError
└── renderMarkUp
├── res.write.firstFoldCss
├── res.write.firstFoldJS
├── res.end
└── onRenderError (on failure)
Dependencies
src/otel.jsnow imports gRPC exporters and sampler primitives in addition to the existing HTTP exporters.Consuming apps must ensure the following are installed (install command for reference):