feat: add @axiomhq/tanstack-start observability package#403
Draft
gabrielelpidio wants to merge 3 commits intomainfrom
Draft
feat: add @axiomhq/tanstack-start observability package#403gabrielelpidio wants to merge 3 commits intomainfrom
gabrielelpidio wants to merge 3 commits intomainfrom
Conversation
@axiomhq/js
@axiomhq/logging
@axiomhq/nextjs
@axiomhq/pino
@axiomhq/react
@axiomhq/tanstack-start
@axiomhq/winston
commit: |
Collaborator
|
looks great, thanks for the initiative! overall satisfied with sdk but have few comments:
|
Collaborator
Author
|
@thesollyz addressed your feedback in the latest commits:
Also aligned |
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.
Send data from TanStack app to Axiom
This PR introduces
@axiomhq/tanstack-startandexamples/tanstack-start.The package supports:
Prerequisites
Install
@axiomhq/tanstack-startSuggested file organization
src/lib/axiom/logger.ts: logger instances and transportssrc/router.tsx: Router setup + SPA observersrc/start.ts: Start middleware setupsrc/routes/api/axiom.ts: optional proxy ingestion routeSet up logger instances
Capture SPA navigation events (TanStack Router)
observeTanStackRouter(logger, options?)options:eventType?: keyof RouterEvents(default:onResolved)flushOnNavigation?: boolean(default:false)logUnchangedNavigations?: boolean(default:false)source?: string(default:tanstack-router)getPath?: (router, event) => string | undefinedgetMessage?: (data, event) => stringCapture server request logs (TanStack Start)
createAxiomRequestMiddleware(createMiddleware, logger, config?)options:include?: StartRequestMatcher | StartRequestMatcher[]exclude?: StartRequestMatcher | StartRequestMatcher[]shouldLog?: (context) => boolean | Promise<boolean>logLevelByStatusCode?: (statusCode, data) => LogLevelstore?: ServerContextFields | (context) => ServerContextFields | Promise<ServerContextFields>onSuccess?: (data, report) => void | Promise<void>onError?: (data, report) => void | Promise<void>StartRequestMatchersupports exact string, wildcard prefix (/api/*),RegExp, and callback function.Capture server function logs (TanStack Start)
createAxiomMiddleware(createMiddleware, logger, config?)options:includeData?: boolean(default:false)correlation?: boolean | StartFunctionCorrelationMiddlewareConfig(default:false)store?: ServerContextFields | (context) => ServerContextFields | Promise<ServerContextFields>onSuccess?: (data, report) => void | Promise<void>onError?: (data, report) => void | Promise<void>StartFunctionCorrelationMiddlewareConfigoptions:headerName?: string(default:x-axiom-correlation-id)contextKey?: string(default:axiom_correlation_id)createRequestId?: () => stringWith correlation enabled, request middleware and function middleware logs share the same
request_idfor one operation.Standalone function correlation middleware
Capture uncaught server-entry errors
captureError(handler, logger, config?)options:source?: string(default:tanstack-start-uncaught)phase?: 'server-entry' | 'start-handler' | 'process'(default:server-entry)rethrow?: boolean(default:true)onError?: (data, report) => void | Promise<void>createResponse?: (data) => Response | Promise<Response>Add a proxy route for client-side ingestion
createAxiomProxyHandler(logger, config?)options:onSuccess?: (events) => void | Promise<void>onError?: (error) => void | Promise<void>Request body must be a JSON array of log events.
AsyncLocalStorage
AsyncLocalStorage is used for server execution context so logs emitted in async call chains keep request-scoped fields such as
request_id.If AsyncLocalStorage is unavailable, logging still works, but context propagation is limited.
Works in both modes
Router SPA only:
observeTanStackRouterFull TanStack Start:
Validation in this PR
pnpm --filter @axiomhq/tanstack-start lintpnpm --filter @axiomhq/tanstack-start buildpnpm --filter @axiomhq/tanstack-start testpnpm --filter tanstack-start buildAll pass.