- Notifications
You must be signed in to change notification settings - Fork 7
Demo for distributed tracing between react frontend and FastAPI #4
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits Select commit Hold shift + click to select a range
79d2d7e Demo for distributed tracing between react frontend and FastAPI
petyosi 65c1242 Add suggested changes
petyosi 0e64d78 Remove redundant OPTIONS method
petyosi a7ab1e7 Address review comments
petyosi 4f738fc Clarify why maxExportBatchSize
petyosi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| images |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| v22.17.0 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "makefile.configureOnOpen": false | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| .PHONY: install | ||
| install: | ||
| cd frontend && npm install | ||
| uv sync | ||
| | ||
| .PHONY: frontend-dev | ||
| frontend-dev: | ||
| cd frontend && npm run dev | ||
| | ||
| .PHONY: backend-dev | ||
| backend-dev: | ||
| uv run main.py |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Distributed tracing demo | ||
| | ||
| This project demonstrates distributed Logfire tracing from the browser (React | ||
| app) to the backend (FastAPI Python app using PydanticAI). | ||
| | ||
| # Key concepts | ||
| | ||
| The React application (`frontend/`) is instrumented using the | ||
| `@pydantic/logfire-browser` NPM package. Details about the instrumentation | ||
| specifics can be found in the `ClientInstrumentationProvider.tsx` file. | ||
| | ||
| The browser instrumentation does not send traces to Logfire directly, but | ||
| instead sends them to the backend. The backend then proxies the traces to | ||
| Logfire - the `/client-traces` FastAPI endpoint in `main.py`. | ||
| | ||
| # Running the demo | ||
| | ||
| To run the demo, you need to have Python 3.10+ and Node.js 22+ installed. First, | ||
| install the dependencies: | ||
| | ||
| ```bash | ||
| make install | ||
| ``` | ||
| | ||
| Then, export the following environment variables: | ||
| | ||
| ```bash | ||
| export LOGFIRE_TOKEN=<your-logfire-token> | ||
| export LOGFIRE_BASE_URL=https://logfire-us.pydantic.dev/ # e.g. https://logfire-eu.pydantic.dev/ or https://logfire-us.pydantic.dev/ | ||
| export OPENAI_API_KEY=<your-openai-api-key> # you can get one from https://platform.openai.com/account/api-keys | ||
| ``` | ||
| | ||
| Run the backend: | ||
| | ||
| ```bash | ||
| make backend-dev | ||
| ``` | ||
| | ||
| Then, in another shell, run the frontend: | ||
| | ||
| ```bash | ||
| make frontend-dev | ||
| ``` | ||
| | ||
| The App will be available at (http://localhost:5173)[http://localhost:5173]. You | ||
| can open your Logfire live view and interact with the App to see the traces in | ||
| real-time. | ||
| | ||
| # Further reading | ||
| | ||
| - [Distributed tracing with Logfire](https://logfire.pydantic.dev/docs/how-to-guides/distributed-tracing/) | ||
| - [Logfire Python SDK](https://github.com/pydantic/logfire) | ||
| - [Logfire JS](https://github.com/pydantic/logfire-js) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| VITE_FAST_API_BACKEND_BASE_URL=http://127.0.0.1:8000 |
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| pnpm-debug.log* | ||
| lerna-debug.log* | ||
| | ||
| node_modules | ||
| dist | ||
| dist-ssr | ||
| *.local | ||
| | ||
| # Editor directories and files | ||
| .vscode/* | ||
| !.vscode/extensions.json | ||
| .idea | ||
| .DS_Store | ||
| *.suo | ||
| *.ntvs* | ||
| *.njsproj | ||
| *.sln | ||
| *.sw? |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import js from '@eslint/js' | ||
| import globals from 'globals' | ||
| import reactHooks from 'eslint-plugin-react-hooks' | ||
| import reactRefresh from 'eslint-plugin-react-refresh' | ||
| import tseslint from 'typescript-eslint' | ||
| import { globalIgnores } from 'eslint/config' | ||
| | ||
| export default tseslint.config([ | ||
| globalIgnores(['dist']), | ||
| { | ||
| files: ['**/*.{ts,tsx}'], | ||
| extends: [ | ||
| js.configs.recommended, | ||
| tseslint.configs.recommended, | ||
| reactHooks.configs['recommended-latest'], | ||
| reactRefresh.configs.vite, | ||
| ], | ||
| languageOptions: { | ||
| ecmaVersion: 2020, | ||
| globals: globals.browser, | ||
| }, | ||
| }, | ||
| ]) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Pydantic Stack Image Generator</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="/src/main.tsx"></script> | ||
| </body> | ||
| </html> |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.