Skip to content

feat: add Fastify support#138

Merged
HugoRCD merged 8 commits intomainfrom
claude/competent-elgamal
Mar 7, 2026
Merged

feat: add Fastify support#138
HugoRCD merged 8 commits intomainfrom
claude/competent-elgamal

Conversation

@HugoRCD
Copy link
Copy Markdown
Owner

@HugoRCD HugoRCD commented Mar 7, 2026

Overview

Adds a Fastify plugin for evlog that provides request-scoped logging with wide-event emission.

Changes

  • New Fastify Plugin (packages/evlog/src/fastify/index.ts)

    • Auto-creates request-scoped logger accessible via request.evlog
    • Emits wide events on response completion with status codes
    • Supports full evlog pipeline: drain adapters, enrichers, tail sampling
    • Implements useLogger() for accessing logger from call stack via AsyncLocalStorage
    • Lifecycle hooks: onRequest (setup) → onResponse (emit) → onError (error capture)
  • Example Application (examples/fastify/)

    • Complete working example with routes for testing
    • Demonstrates context accumulation, email masking, error handling
    • Includes interactive web UI for testing endpoints
  • Documentation (AGENTS.md, installation.md)

    • API reference and usage examples
    • Configuration guide with include/exclude patterns
    • Notes on Fastify-specific behavior and pino integration
  • Dependencies

    • Added fastify-plugin@^5.0.1 as core dependency
    • Added fastify@^5.2.1 as dev/peer dependency
  • Tests (packages/evlog/test/fastify.test.ts)

    • Comprehensive test coverage for plugin functionality

Implements EVL-107. Adds `evlog/fastify` — a Fastify plugin for
automatic wide-event logging with full pipeline support (drain,
enrich, keep). Exposes `request.evlog` for typed per-request access
and `useLogger()` via AsyncLocalStorage for call-stack access.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, Comment, Open in v0 Mar 7, 2026 11:32am

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 7, 2026

Thank you for following the naming conventions! 🙏

@HugoRCD HugoRCD changed the title feat: add Fastify plugin integration (evlog/fastify) feat: add Fastify support Mar 7, 2026
…est.log

- Remove `fastify-plugin` runtime dependency (evlog must have zero deps)
- Inline `Symbol.for('skip-override')` to break encapsulation without a package
- Rename `request.evlog` → `request.log` to match Express/Elysia ergonomics
- Update tests, example, docs, and AGENTS.md accordingly

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Add `fastify` scope to PR template and semantic PR CI workflow
- Add `example:fastify` script to root package.json
- Add Fastify to FeatureFrameworks.vue component (tab 6)
- Add #fastify code snippet to landing page
- Create docs example page at 6.examples/6.fastify.md

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Remove unused eslint-disable directive, fix no-extra-semi by splitting
leading-semicolon expressions, and remove async from route handlers
that don't use await (require-await rule).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@HugoRCD HugoRCD marked this pull request as ready for review March 7, 2026 10:55
@HugoRCD HugoRCD requested a review from Copilot March 7, 2026 10:55
@HugoRCD HugoRCD self-assigned this Mar 7, 2026
storage.enterWith() permanently modifies the async context, so the
"throws outside middleware context" test must run before any request
that calls enterWith, otherwise the storage is non-null and useLogger()
won't throw.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a Fastify plugin for the evlog structured logging library, providing request-scoped wide-event logging with the same pipeline features (drain adapters, enrichers, tail sampling) as existing framework integrations (Express, Elysia, Hono).

Changes:

  • Adds evlog/fastify plugin with onRequest/onResponse/onError lifecycle hooks, useLogger() via AsyncLocalStorage, and plugin encapsulation bypass via Symbol.for('skip-override')
  • Adds comprehensive tests and a complete example application with an interactive UI
  • Adds documentation, dependency declarations, and build configuration

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/evlog/src/fastify/index.ts Core plugin implementation
packages/evlog/test/fastify.test.ts Comprehensive test suite
packages/evlog/tsdown.config.ts Adds fastify entry point to build config
packages/evlog/package.json Adds fastify as dev/peer dependency and export paths
bun.lock Lock file updated with fastify and transitive dependencies
apps/docs/content/6.examples/6.fastify.md Detailed Fastify example documentation
apps/docs/content/1.getting-started/2.installation.md Fastify section in installation guide
apps/docs/content/0.landing.md Fastify tab added to landing page framework showcase
apps/docs/app/components/features/FeatureFrameworks.vue Fastify tab added to framework selector component
examples/fastify/src/index.ts Example Fastify application
examples/fastify/src/ui.ts Interactive web UI for example app
examples/fastify/package.json Example app package configuration
examples/fastify/tsconfig.json TypeScript config for example app
package.json Root script for running the fastify example
AGENTS.md AI agent documentation for Fastify integration
.github/workflows/semantic-pull-request.yml Adds fastify as valid PR scope
.github/pull_request_template.md Adds fastify as valid PR scope in template

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

storage.enterWith() permanently modifies the current async context.
In test environments where app.handle() doesn't create a new async
context per request, the storage from one request leaks into the next,
causing useLogger() to not throw when called outside middleware.

Clear the storage at the end of onAfterHandle and onError so that
each request leaves a clean state. Also move the "throws outside
middleware context" test first in its describe block as an extra guard.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- elysia: replace storage.enterWith(undefined) cleanup with activeLoggers
  WeakSet so useLogger() reliably throws when called outside a live request,
  regardless of async context persistence in Bun test environments
- elysia: use state.logger in onError instead of storage.getStore()
- fastify: use (request as any).log in onError instead of storage.getStore()
- docs: fix Fastify landing slot (evlog({ drain }) → app.register(evlog, { drain }))
- docs: add { logger: false } to Fastify() in landing and installation docs

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 7, 2026

npm i https://pkg.pr.new/evlog@138
npm i https://pkg.pr.new/@evlog/nuxthub@138

commit: 7f2d543

@HugoRCD HugoRCD merged commit 75f88cd into main Mar 7, 2026
11 checks passed
@HugoRCD HugoRCD deleted the claude/competent-elgamal branch March 7, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants