Trace a web frontend with Maple: install @maple-dev/browser, link browser and backend traces, add route navigation and data-loading spans, report errors the framework catches, and join the first page load to the server render. Per-framework references for TanStack Router/Start, React Router, Next.js, Vue/Nuxt, SvelteKit, Angular and Astro. Triggers on 'trace my frontend', 'add frontend observability', 'instrument the browser with Maple', 'trace route changes', 'connect frontend and backend traces', 'add session replay'.
95%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Low
Low-risk findings worth noting
The goal: one click is one trace. A navigation span, the data-loading spans under it, the fetch spans they make, and the backend spans behind those. The first page load joins the server render's trace. Errors the framework catches are reported. Session replay links to the traces through a shared session.id.
The human-readable version of this skill is the guide at https://maple.dev/docs/frontend. Read it if you need the reasoning behind a step.
Read the package.json of each web frontend in the repo, then read only the matching reference in frameworks/:
| Dependency | Reference |
|---|---|
@tanstack/react-router, @tanstack/react-start | frameworks/tanstack.md |
react-router (v7, v8), react-router-dom | frameworks/react-router.md |
next | frameworks/nextjs.md |
vue-router, nuxt | frameworks/vue.md |
@sveltejs/kit | frameworks/sveltekit.md |
@angular/router | frameworks/angular.md |
astro | frameworks/astro.md |
| anything else (Solid, Qwik, plain SPA, hand-rolled router) | frameworks/other.md |
The steps below are the same for every framework. The reference tells you where each one goes. If the references are not next to this file, read them from https://github.com/MapleTechLabs/maple/tree/main/skills/maple-frontend-tracing.
Backends are out of scope for this skill. If the API the frontend calls isn't instrumented with OpenTelemetry yet, use the maple-onboard skill for it first, or say in the hand-off that browser traces won't connect to it until it is.
Maple has two regions. A key only works in the region that issued it.
region: "us", dashboard https://app.maple.dev.region: "eu", dashboard https://app.eu.maple.dev. Use it when the prompt mentions the EU or an eu.maple.dev URL.Browser code takes the public ingest key (maple_pk_…) only. It is write-only and safe to ship, like a Sentry DSN. Inline it in the init call. Never put a private key (maple_sk_…) in browser code: if the prompt only has a private key, use MAPLE_TEST in the browser and tell the user to swap in the public key. With no key at all, inline the sentinel MAPLE_TEST (ingest accepts it and stores nothing) and keep going.
Install @maple-dev/browser 0.14.0 or later with the project's package manager. It has two entries only: @maple-dev/browser and @maple-dev/browser/react. There are no per-framework or /server entries; never import @maple-dev/browser/<framework>. Add @opentelemetry/api only if app code imports it (the await rule's context, or where a reference says so): strict package managers (pnpm) won't resolve it as the SDK's transitive dependency. Initialize the SDK once, before the app renders, at the place the framework reference names:
import { MapleBrowser } from "@maple-dev/browser"
MapleBrowser.init({
ingestKey: "MAPLE_TEST", // public key, maple_pk_…
serviceName: "acme-web",
region: "us", // "eu" for EU organizations
serviceVersion: "<commit sha from the build env, if the bundler exposes one>",
environment: import.meta.env.MODE,
tracing: {
// First-party APIs on another origin. Same-origin requests are covered already.
propagateTraceHeaderCorsUrls: [/^https:\/\/api\.acme\.com\//], // RegExp: a plain string only matches as a prefix from 0.14.1
},
})serviceName: distinct from the backend's, usually <app>-web.init() is a no-op on the server, so importing it from code that also runs during SSR is safe.fetch and XMLHttpRequest, so axios, Angular's HttpClient (fetch or XHR backend), ky and ofetch are all covered. Don't add another fetch or XHR instrumentation.fetch (for example @maple-dev/effect-sdk/client), set tracing.instrumentFetch: false.tracing.captureErrors: false so errors aren't counted twice.VITE_API_URL). Same-origin requests already carry traceparent. List each cross-origin first-party API in propagateTraceHeaderCorsUrls as an anchored regex.cors npm package default). If there's an explicit allow-list, add traceparent and keep the existing entries (plus baggage if the app sets OpenTelemetry baggage). Without this, the browser blocks the request after the preflight.React Router (data routers) and TanStack Router: use instrumentReactRouter / instrumentTanStackRouter from @maple-dev/browser/react as the reference says. Every other framework: copy the reference's router glue, which calls the SDK's three navigation methods from the router's hooks:
MapleBrowser.startNavigation(path): call when the router starts a navigation. The first call opens a pageload span (joined to the server render, see Step 6), later calls open navigate spans. A navigation that starts before the previous one ended ends the previous one with maple.navigation.interrupted: true.MapleBrowser.endNavigation(routeTemplate?): call when the new route is ready. Renames the span to <kind> <template> and ends it. It ends whichever navigation is open, so guard against a slow, superseded route calling it late. No-op when nothing is open.MapleBrowser.traced(name, fn, { isFailure }): runs a data-loading function in a child span of the current navigation. Pass isFailure to exclude the framework's control-flow throws (redirects, not-found) from being marked as errors. An error it records isn't reported again by captureException or the global handlers.Rules:
navigate /projects/:id, not navigate /projects/8f2a. The concrete path is already the url.path attribute.load functions, resolvers), named loader <template>. Don't wrap every component fetch or event handler.await rule. The browser has no async context: inside traced, only requests started before the first await nest under the span. Start independent requests together (Promise.all). For a request that depends on an earlier one, capture const ctx = context.active() (from @opentelemetry/api) before the first await and call it inside context.with(ctx, () => …). Don't install ZoneContextManager.Error boundaries stop errors from reaching window.onerror, so the SDK's global handlers never see them. Call MapleBrowser.captureException(error) from the hook the reference names (React: MapleErrorBoundary and mapleReactErrorHandler() from @maple-dev/browser/react). For other frameworks, find the central caught-error hook and call MapleBrowser.captureException(error) there. No dedupe check is needed: it skips errors traced already recorded, and records each error object once.
Keep whatever the hook already does (logging, other vendors, fallback UI). init(), traced and captureException do nothing on the server. To record an SSR error, use trace.getActiveSpan()?.recordException(error) from @opentelemetry/api where the reference says so.
The server needs OpenTelemetry like any backend: follow maple-nodejs-style (or maple-nextjs-style for Next.js) for the SDK bootstrap and inline key. If that skill isn't installed, install it with npx skills add MapleTechLabs/maple/skills --skill maple-nodejs-style -y, or read it at https://github.com/MapleTechLabs/maple/tree/main/skills/maple-nodejs-style.
Make sure a server span is active while the HTML response is built (the framework's own tracing, the HTTP instrumentation, or a span the reference adds). From inside it, write the trace context into the response, as a header or a meta tag:
import { context, propagation } from "@opentelemetry/api"
const carrier: Record<string, string> = {}
propagation.inject(context.active(), carrier)
if (carrier.traceparent) headers.append("server-timing", `traceparent;desc="${carrier.traceparent}"`)
// or: <meta name="traceparent" content="${carrier.traceparent}"> in <head>The SDK reads it from the Navigation Timing API (or the meta tag) and parents the browser's pageload span to it. Only the page load joins the server trace; later navigations are their own traces. An unsampled server trace means no pageload span. On a Node ESM server, the OpenTelemetry SDK must load with its loader hook (--import), or no span is active and the header silently never appears.
Server-side data loading (SSR loaders, Server Components, resolvers) is traced by the server's OpenTelemetry setup, not by MapleBrowser.traced, which only runs fn on the server.
Don't send the trace context on responses a CDN caches, or every visitor joins the same trace.
https://ingest(.eu).maple.dev/v1/traces return 200 (a 401 means wrong key or wrong region);traceparent header, and cross-origin ones pass their CORS preflight;server-timing header containing traceparent, or the HTML a <meta name="traceparent"> tag./v1/traces requests. This works with MAPLE_TEST too:
pageload <template> span, never a bare pageload, and it is exported even when the page's render throws;navigate <template> span; its loader … spans have its spanId as parentSpanId, and the fetch spans sit under those. Repeat for a param-only change (/items/1 to /items/2);exception event, and no browser.unhandled_rejection for the same error. An event handler that throws gives exactly one error span: browser.uncaught_error, or the framework hook's span when the framework catches handler errors (Angular: angular.error). Errors thrown in server-side data loading (Next.js Server Components, server loaders) are on the server's spans, not in the browser's /v1/traces bodies.maple.navigation.interrupted, or merged into the second where the reference says so), the second is navigate <template>, and no navigation span stays open;exception event, on a server span. A URL that matches no route produces no exception event and no Error span other than a 4xx fetch.search_traces for the frontend's serviceName and inspect_trace a navigate … trace: it should contain the loader span, fetch spans and the backend's spans, unless the framework reference says those are separate traces (Next.js App Router). With MAPLE_TEST, nothing is stored; say so instead.3 to 7 bullets: packages installed, files created or changed, which APIs got traceparent (and any CORS change), which framework hooks were wired, and what you could not verify. Also tell the user:
fetch spans for 4xx responses are marked Error (OpenTelemetry's rule for client spans). Maple doesn't open error issues for 4xx spans without exception data, so an expected 404 doesn't create an issue.replay: { enabled: false } turns it off), and the SDK keeps a persistent visitor id in localStorage and a cookie (privacy: { persistVisitorId: false } turns it off). Both matter for their privacy and cookie notices.MAPLE_TEST is inline: copy the public key from Settings → Ingestion (<dashboard>/settings/ingestion) and search-replace MAPLE_TEST.traceparent to third-party origins.MapleTechLabs/maple
ee52189
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.