Skip to content

feat: expand telemetry β€” Sentry spans, GA4 events, Sentry init fix#859

Draft
thostetler wants to merge 2 commits intoadsabs:masterfrom
thostetler:feat/telemetry-expansion
Draft

feat: expand telemetry β€” Sentry spans, GA4 events, Sentry init fix#859
thostetler wants to merge 2 commits intoadsabs:masterfrom
thostetler:feat/telemetry-expansion

Conversation

@thostetler
Copy link
Copy Markdown
Member

@thostetler thostetler commented Apr 23, 2026

Next.js 16 Turbopack bypasses the Sentry webpack plugin, so sentry.client.config.ts was never loaded in dev. This adds a runtime guard to require it manually when Turbopack is active.

Instruments key user flows with Sentry performance spans and GA4 behavioral events for production latency and engagement tracking.

Sentry spans:

  • search.submit.total, search.pagination.total β€” query lifecycle
  • search.results.render, search.facets.render β€” paint timing after docs arrive
  • export.generate.total β€” full export flow
  • abstract.load.total, abstract.citations.load, abstract.references.load β€” SSR fetches
  • auth.login.total, auth.register.total, auth.session.validate β€” auth flows
  • orcid.oauth.total, orcid.claim.total, orcid.sync.total β€” ORCID flows
  • ux.full_text_time β€” time from search results to full-text link click

GA4 events:

  • result_click β€” user clicks an abstract link
  • full_text_click β€” user opens a full-text resource (mark as conversion in GA4)
  • abstract_tab_view β€” user switches abstract tabs
  • search_no_results β€” query returns zero results

Note: full_text_click must be manually marked as a key event in GA4 Admin > Events.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 61.84971% with 66 lines in your changes missing coverage. Please review.
βœ… Project coverage is 62.6%. Comparing base (da070fc) to head (afe019d).

Files with missing lines Patch % Lines
src/lib/performance.ts 54.5% 31 Missing ⚠️
src/api/orcid/orcid.ts 0.0% 11 Missing ⚠️
...mponents/ResultList/Item/ItemResourceDropdowns.tsx 47.7% 11 Missing ⚠️
src/lib/useExportSpan.ts 72.3% 10 Missing ⚠️
src/lib/serverside/absCanonicalization.ts 86.7% 2 Missing ⚠️
...components/CitationExporter/useCitationExporter.ts 94.5% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #859     +/-   ##
========================================
- Coverage    62.7%   62.6%   -0.0%     
========================================
  Files         323     324      +1     
  Lines       38011   38143    +132     
  Branches     1723    1728      +5     
========================================
+ Hits        23803   23876     +73     
- Misses      14168   14226     +58     
- Partials       40      41      +1     
Files with missing lines Coverage Ξ”
src/lib/serverside/bootstrap.ts 76.6% <100.0%> (+0.6%) ⬆️
...components/CitationExporter/useCitationExporter.ts 91.0% <94.5%> (+0.4%) ⬆️
src/lib/serverside/absCanonicalization.ts 64.3% <86.7%> (+0.7%) ⬆️
src/lib/useExportSpan.ts 72.3% <72.3%> (ΓΈ)
src/api/orcid/orcid.ts 26.6% <0.0%> (-0.2%) ⬇️
...mponents/ResultList/Item/ItemResourceDropdowns.tsx 77.1% <47.7%> (-1.7%) ⬇️
src/lib/performance.ts 78.3% <54.5%> (-10.6%) ⬇️

... and 6 files with indirect coverage changes

πŸš€ New features to boost your workflow:
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thostetler thostetler force-pushed the feat/telemetry-expansion branch from 77f60b7 to e3e2936 Compare April 23, 2026 19:22
Next.js 16 defaults to Turbopack for `next dev`, which bypasses the
Sentry webpack plugin and skips sentry.client.config.ts. Guard on
`process.env.TURBOPACK` (truthy as 'auto' under default Turbopack,
undefined under webpack/production) and require the config manually
in browser context only.
Instruments key user flows end-to-end with Sentry inactive spans and
GA4 behavioral events so latency and engagement can be tracked in
production dashboards.

Sentry spans added (all in PERF_SPANS):
- search.submit.total / search.pagination.total β€” query lifecycle
- search.results.render / search.facets.render β€” paint timing via useResultsRenderSpan
- export.generate.total β€” full export flow in useCitationExporter
- abstract.load.total / abstract.citations.load / abstract.references.load β€” SSR fetches
- auth.login.total / auth.register.total / auth.session.validate β€” auth flows
- orcid.oauth.total / orcid.claim.total / orcid.sync.total β€” ORCID flows
- ux.full_text_time β€” time from results to full-text link click

GA4 events added:
- result_click β€” user clicks an abstract link in results
- full_text_click β€” user opens a full-text resource (marked as conversion)
- abstract_tab_view β€” user navigates between abstract tabs
- search_no_results β€” query returns zero results

Infrastructure:
- makeSpanSlot factory for coordinated open/close across component boundaries
- useResultsRenderSpan hook (closes both results and facets spans after paint)
- useExportSpan hook for export span lifecycle
- sendQueryAsTags with PII-safe allowlist (sort/start/rows/d/boostType only)
- trackUserFlow wraps async server-side fetches with span + status
- Sentry.setUser uses anonymous flag only β€” no credentials or PII
@thostetler thostetler force-pushed the feat/telemetry-expansion branch from e3e2936 to afe019d Compare April 23, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant