Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add axiom logger, nextjs and react libraries #257

Draft
wants to merge 60 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
f377645
feat: Add axiom logger, nextjs and react libraries
gabrielelpidio Jan 16, 2025
449d292
feat: Add proxy transport and proxy route handler
gabrielelpidio Jan 16, 2025
98b829b
docs: add nextjs example
gabrielelpidio Jan 16, 2025
4235bb3
feat: add and extend from new SimpleFetchTransport
gabrielelpidio Jan 16, 2025
73b29ac
feat: Add prettyPrint to ConsoleTransport
gabrielelpidio Jan 16, 2025
93ab4f6
docs: move handler to component body in example
gabrielelpidio Jan 16, 2025
a1f8f46
fix: make ConsoleTransport config optional in constructor
gabrielelpidio Jan 16, 2025
654733e
feat: add autoFlush option to fetch transports
gabrielelpidio Jan 16, 2025
8c0906b
fix: move report under request: to match current data shape
gabrielelpidio Jan 17, 2025
9535c53
refactor: rename withAxiom to routeHandler
gabrielelpidio Jan 17, 2025
78a3db4
feat: add middleware support for Next.js
gabrielelpidio Jan 17, 2025
0ef11fb
feat: Add onRequestError helpers
gabrielelpidio Jan 20, 2025
c68b2d5
refactor: rename folder from core to logger
gabrielelpidio Jan 20, 2025
a8506ff
refactor: rename logger back to logging
gabrielelpidio Jan 21, 2025
f6baf4a
chore: add build step
gabrielelpidio Jan 21, 2025
56c5e4d
feat: add pkg.pr.new for continuous release
gabrielelpidio Jan 21, 2025
903f53d
chore: temporary disable of lint
gabrielelpidio Jan 21, 2025
1226d66
chore: remove empty test commands
gabrielelpidio Jan 21, 2025
d876e88
fix: remove compact until package is released
gabrielelpidio Jan 21, 2025
c71c516
chore: add build step and turbo cache to preview-release
gabrielelpidio Jan 21, 2025
e9bd526
ci: cache after node setup
gabrielelpidio Jan 22, 2025
cb792bd
refactor: export everything from index in logger, remove unused trans…
gabrielelpidio Jan 22, 2025
196d390
chore: add .env.example
gabrielelpidio Jan 23, 2025
20d0a80
fix: add missing request key to transformErrorResult
gabrielelpidio Jan 23, 2025
875acba
refactor: replace logErrorByStatusCode with getLogLevelFromStatusCode
gabrielelpidio Jan 24, 2025
1cb9283
fix: ensure request data shape match current next-axiom implementation
gabrielelpidio Jan 24, 2025
e682005
chore: add unit testing for nextjs package
gabrielelpidio Jan 24, 2025
33abade
fix: use prettyPrint in console transport
gabrielelpidio Jan 26, 2025
163f31e
test: add unit tests for logging package
gabrielelpidio Jan 26, 2025
eb565a0
test: add unit tests for react package
gabrielelpidio Jan 27, 2025
03b18c6
fix: test issue fetch transport
gabrielelpidio Jan 27, 2025
b2d5444
fix: error properties handling
gabrielelpidio Jan 28, 2025
6b12dfb
ci: update cache directory
gabrielelpidio Jan 28, 2025
6ecbaec
ci: add cache to e2e and integration tests
gabrielelpidio Jan 28, 2025
db9076e
chore: add eslint configuration
gabrielelpidio Jan 28, 2025
6115522
chore: use workspace:* instead of ^
gabrielelpidio Jan 29, 2025
4ca5448
refactor: rename shared.ts to runtime.ts
gabrielelpidio Jan 29, 2025
090bb27
chore: update dependencies of react package
gabrielelpidio Jan 29, 2025
e35921a
chore: add correct package metadata to next, logging and react
gabrielelpidio Jan 29, 2025
dd991ac
feat: add log level filtering to transports
gabrielelpidio Jan 30, 2025
9dac150
feat: Add webvitals to react
gabrielelpidio Feb 3, 2025
a27bddb
feat: Add field formatter to logger
gabrielelpidio Feb 3, 2025
d0aaa67
refactor: Axiom route handler callbacks & tracing strategy
gabrielelpidio Feb 3, 2025
e0c8b26
refactor: web-vitals
gabrielelpidio Feb 3, 2025
f4eb123
refactor: web-vitals
gabrielelpidio Feb 4, 2025
0efc67d
chore: update deps and example
gabrielelpidio Feb 4, 2025
06ce3fd
fix: import AsyncLocalStorage from node:async_hooks
gabrielelpidio Feb 4, 2025
5f12d07
tests: fix logging test
gabrielelpidio Feb 4, 2025
2c35c11
chore: add globals to vitest
gabrielelpidio Feb 4, 2025
b481f71
fix: avoid circular deps
gabrielelpidio Feb 4, 2025
1d7c8aa
fix: axiom-js without batch handling
gabrielelpidio Feb 4, 2025
5a9f24b
test: Add tests for logLevel
gabrielelpidio Feb 4, 2025
e603b58
refactor: extract context into it's own file
gabrielelpidio Feb 4, 2025
764b67a
refactor: add crypto and AsyncLocalStorage utility imports
gabrielelpidio Feb 4, 2025
b79b6cc
refactor: move LogLevel from enum to object
gabrielelpidio Feb 5, 2025
16ae787
feat: handle non-standard log events in prettyPrint
gabrielelpidio Feb 5, 2025
77365d5
refactor: update server context handling
gabrielelpidio Feb 5, 2025
3423b4c
refactor: rename AxiomProxyTransport to ProxyTransport
gabrielelpidio Feb 7, 2025
b019f8e
refactor: make axiom routeHandler builder consistent with other builders
gabrielelpidio Feb 7, 2025
38f948e
fix: context types
gabrielelpidio Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,42 @@ jobs:
with:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: ./node_modules/.cache/turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- run: pnpm install --frozen-lockfile
- run: pnpm build && pnpm build:cjs
- run: pnpm lint
- run: pnpm test


preview-release:
name: Preview release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'pnpm'
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: ./node_modules/.cache/turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- run: pnpm install --frozen-lockfile
- run: pnpm run build --filter='./packages/*' && pnpm run build:cjs --filter='./packages/*'
- run: pnpx pkg-pr-new publish './packages/*'

check-winston-example:
name: Check Winston example
runs-on: ubuntu-latest
Expand Down Expand Up @@ -87,6 +118,13 @@ jobs:
with:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: ./node_modules/.cache/turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- run: pnpm install --frozen-lockfile
- run: pnpm build && pnpm build:cjs
- env:
Expand Down Expand Up @@ -134,6 +172,13 @@ jobs:
with:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: ./node_modules/.cache/turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- run: pnpm install --frozen-lockfile
- run: pnpm build && pnpm build:cjs # cjs build needed to run tests
- env:
Expand Down
2 changes: 1 addition & 1 deletion examples/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"winston": "^3.14.2"
},
"devDependencies": {
"@repo/eslint-config": "workspace:^"
"@repo/eslint-config": "workspace:*"
}
}
3 changes: 3 additions & 0 deletions examples/nextjs/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AXIOM_TOKEN=""
AXIOM_DATASET=""
NEXT_PUBLIC_AXIOM_PROXY_URL="/api/axiom"
42 changes: 42 additions & 0 deletions examples/nextjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*
!.env.example

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions examples/nextjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
16 changes: 16 additions & 0 deletions examples/nextjs/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
];

export default eslintConfig;
7 changes: 7 additions & 0 deletions examples/nextjs/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
};

export default nextConfig;
31 changes: 31 additions & 0 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "nextjs",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@axiomhq/logging": "workspace:*",
"@axiomhq/nextjs": "workspace:*",
"@axiomhq/react": "workspace:*",
"next": "15.1.4",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.1.4",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5",
"vite": "^5.2.14"
}
}
8 changes: 8 additions & 0 deletions examples/nextjs/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};

export default config;
23 changes: 23 additions & 0 deletions examples/nextjs/src/app/[[...path]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Button from '@/app/_components/button';
import { logger } from '@/lib/axiom/server';
import Link from 'next/link';
import { after } from 'next/server';

export default function Home() {
logger.info('Hello World!', { key: 'value' });

after(() => {
logger.flush();
});

return (
<div>
<Button />
<div className="flex gap-2">
<Link href="/about">About</Link>
<Link href="/blog">Blog</Link>
<Link href="/home">Home</Link>
</div>
</div>
);
}
19 changes: 19 additions & 0 deletions examples/nextjs/src/app/_components/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use client';

import { useLogger } from '@/lib/axiom/client';

export default function Button() {
const logger = useLogger();
gabrielelpidio marked this conversation as resolved.
Show resolved Hide resolved

const handleClick = () => {
logger.info('Hello World from Client Side!', { key: 'value' });
};

return (
<div>
<button style={{ color: 'red' }} onClick={handleClick}>
Log
</button>
</div>
);
}
4 changes: 4 additions & 0 deletions examples/nextjs/src/app/api/axiom/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { logger } from '@/lib/axiom/server';
import { createProxyRouteHandler } from '@axiomhq/nextjs';

export const POST = createProxyRouteHandler(logger);
11 changes: 11 additions & 0 deletions examples/nextjs/src/app/api/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { logger, withAxiom } from '@/lib/axiom/server';

export const GET = withAxiom(async () => {
logger.info('Hello World!');
return new Response('Hello World!');
});

export const POST = withAxiom(async (req) => {
logger.info('Hello World!');
return new Response(JSON.stringify(req.body));
});
Binary file added examples/nextjs/src/app/favicon.ico
Binary file not shown.
21 changes: 21 additions & 0 deletions examples/nextjs/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--background: #ffffff;
--foreground: #171717;
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}

body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
}
33 changes: 33 additions & 0 deletions examples/nextjs/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Metadata } from 'next';
import { Geist, Geist_Mono } from 'next/font/google';

import './globals.css';
import { WebVitals } from '@/lib/axiom/client';

const geistSans = Geist({
variable: '--font-geist-sans',
subsets: ['latin'],
});

const geistMono = Geist_Mono({
variable: '--font-geist-mono',
subsets: ['latin'],
});

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<WebVitals />
<body className={`${geistSans.variable} ${geistMono.variable} antialiased`}>{children}</body>
</html>
);
}
4 changes: 4 additions & 0 deletions examples/nextjs/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { logger } from '@/lib/axiom/server';
import { createOnRequestError } from '@axiomhq/nextjs';

export const onRequestError = createOnRequestError(logger);
16 changes: 16 additions & 0 deletions examples/nextjs/src/lib/axiom/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client';

import { Logger, ProxyTransport, ConsoleTransport } from '@axiomhq/logging';
import { createUseLogger, createWebVitalsComponent } from '@axiomhq/react';

export const logger = new Logger({
transports: [
new ProxyTransport({ url: process.env.NEXT_PUBLIC_AXIOM_PROXY_URL!, autoFlush: true }),
new ConsoleTransport(),
],
});

const useLogger = createUseLogger(logger);
const WebVitals = createWebVitalsComponent(logger);

export { useLogger, WebVitals };
15 changes: 15 additions & 0 deletions examples/nextjs/src/lib/axiom/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Logger, AxiomFetchTransport, ConsoleTransport } from '@axiomhq/logging';
import { createAxiomRouteHandler, serverContextFieldsFormatter } from '@axiomhq/nextjs';

export const logger = new Logger({
transports: [
new AxiomFetchTransport({
dataset: process.env.AXIOM_DATASET!,
token: process.env.AXIOM_TOKEN!,
}),
new ConsoleTransport({ prettyPrint: true }),
],
formatters: [serverContextFieldsFormatter],
});

export const withAxiom = createAxiomRouteHandler(logger);
Loading
Loading