-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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 OTEL instrumentation for next-server + OTEL example #46198
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
3f39345
initial implem
feedthejim 1cffc9b
rename
feedthejim 182a58c
rename hook file
feedthejim 5eb8974
rename
feedthejim 42621c1
remove vscode set
feedthejim 18ef6c5
remove testfiles
feedthejim 77cd616
add error message
feedthejim f501bed
add error message
feedthejim f92dc3c
fix rebase artifact + fix build
feedthejim 10f657f
fix
feedthejim 2371da1
fix conflict with pages/instrumentation
feedthejim 7ae8c72
fix test + fix edge
feedthejim 38ca451
Merge branch 'canary' into add-server-hooks
feedthejim 8b7e859
add initial implem
feedthejim 5a70b3d
Merge branch 'canary' into feedthejim/otel
feedthejim f8bfdda
fix merge artifact
feedthejim f09d192
add tracer
feedthejim 961241d
update lockfile
feedthejim 2687478
add example
feedthejim e4611f9
revert middleplware plugin changes
feedthejim 297edf8
remove test fixture
feedthejim e4e432c
remove test fixture
feedthejim 56ee77e
fix express-static types
feedthejim 501cf62
Merge branch 'canary' into feedthejim/otel
feedthejim 05dfe85
pre-compiled
feedthejim ccfdde7
Merge branch 'canary' into feedthejim/otel
feedthejim 3ea12ee
update precompiled
feedthejim c59bda4
add dev deps
feedthejim fb405c7
Merge branch 'canary' into feedthejim/otel
feedthejim eb8a698
fix merge artefact
feedthejim 3d1ea13
Merge branch 'canary' into feedthejim/otel
feedthejim fc4f264
add back fetch patch
feedthejim 2e929a9
fix types + revert lockfile weird changes
feedthejim bb1c383
fix precompiled
feedthejim 852c63c
fix patch error
feedthejim 39f5a18
update example
feedthejim 643ac92
add file to manifest
feedthejim f0c6c5e
Merge branch 'canary' into feedthejim/otel
feedthejim 2fada0f
remove prebundled file
feedthejim 41fcf78
change order of prebundled file compile
feedthejim 55bb6a7
revert precompiled
feedthejim 3924658
revert precompiled
feedthejim 12a3939
Merge branch 'canary' into feedthejim/otel
feedthejim dc428b9
Revert "revert precompiled"
feedthejim f53df6e
fix edge warning
feedthejim 58515d1
Merge branch 'canary' into feedthejim/otel
feedthejim 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 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,36 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# 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* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains 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,4 @@ | ||
{ | ||
"typescript.tsdk": "../../node_modules/.pnpm/typescript@4.7.4/node_modules/typescript/lib", | ||
"typescript.enablePromptUseWorkspaceTsdk": true | ||
} |
This file contains 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,30 @@ | ||
# Data fetch example | ||
|
||
Next.js was conceived to make it easy to create universal apps. That's why fetching data | ||
on the server and the client when necessary is so easy with Next.js. | ||
|
||
By using `getStaticProps` Next.js will fetch data at build time from a page, and pre-render the page to static assets. | ||
|
||
## Deploy your own | ||
|
||
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/data-fetch) | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/data-fetch&project-name=data-fetch&repository-name=data-fetch) | ||
|
||
## How to use | ||
|
||
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example: | ||
|
||
```bash | ||
npx create-next-app --example data-fetch data-fetch-app | ||
``` | ||
|
||
```bash | ||
yarn create next-app --example data-fetch data-fetch-app | ||
``` | ||
|
||
```bash | ||
pnpm create next-app --example data-fetch data-fetch-app | ||
``` | ||
|
||
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). |
This file contains 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 @@ | ||
export default function Layout({ children }) { | ||
return ( | ||
<html> | ||
<head> | ||
<title>Next.js with OpenTelemetry</title> | ||
</head> | ||
<body> | ||
<main>{children}</main> | ||
</body> | ||
</html> | ||
) | ||
} |
This file contains 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 @@ | ||
import Link from 'next/link' | ||
import { fetchGithubStars } from '../shared/fetch-github-stars' | ||
|
||
export default async function Page() { | ||
const stars = await fetchGithubStars() | ||
return ( | ||
<> | ||
<p>Next.js has {stars} ⭐️</p> | ||
<Link href="/preact-stars">How about preact?</Link> | ||
</> | ||
) | ||
} |
This file contains 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 @@ | ||
export function register() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to align this file with other pages should either be js or ts |
||
if (process.env.NEXT_RUNTIME === 'nodejs') { | ||
const opentelemetry = require('@opentelemetry/sdk-node') | ||
const { | ||
OTLPTraceExporter, | ||
} = require('@opentelemetry/exporter-trace-otlp-http') | ||
const { Resource } = require('@opentelemetry/resources') | ||
const { | ||
SemanticResourceAttributes, | ||
} = require('@opentelemetry/semantic-conventions') | ||
|
||
const sdk = new opentelemetry.NodeSDK({ | ||
traceExporter: new OTLPTraceExporter({}), | ||
instrumentations: [], | ||
resource: new Resource({ | ||
[SemanticResourceAttributes.SERVICE_NAME]: 'my-next-app', | ||
[SemanticResourceAttributes.SERVICE_VERSION]: '1.0.0', | ||
}), | ||
}) | ||
|
||
sdk.start() | ||
} | ||
} |
This file contains 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,6 @@ | ||
module.exports = { | ||
experimental: { | ||
instrumentationHook: true, | ||
appDir: true, | ||
}, | ||
} |
This file contains 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,28 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start", | ||
"start:otel-verbose": "NEXT_OTEL_VERBOSE=1 next start" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/api": "1.4.0", | ||
"@opentelemetry/auto-instrumentations-node": "0.36.3", | ||
"@opentelemetry/exporter-trace-otlp-grpc": "0.35.1", | ||
"@opentelemetry/exporter-trace-otlp-http": "0.35.1", | ||
"@opentelemetry/instrumentation-fetch": "0.35.1", | ||
"@opentelemetry/resources": "1.9.1", | ||
"@opentelemetry/sdk-node": "0.35.1", | ||
"@opentelemetry/sdk-trace-base": "1.9.1", | ||
"@opentelemetry/semantic-conventions": "1.9.1", | ||
"next": "latest", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "18.7.11", | ||
"@types/react": "18.0.17", | ||
"typescript": "4.7.4" | ||
} | ||
} |
This file contains 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,11 @@ | ||
// hello world api route | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { fetchGithubStars } from '../../shared/fetch-github-stars' | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const stars = await fetchGithubStars() | ||
res.status(200).json({ stars }) | ||
} |
This file contains 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,20 @@ | ||
import Link from 'next/link' | ||
import { fetchGithubStars } from '../shared/fetch-github-stars' | ||
|
||
export async function getServerSideProps() { | ||
const stars = await fetchGithubStars() | ||
return { | ||
props: { | ||
stars, | ||
}, | ||
} | ||
} | ||
|
||
export default function IndexPage({ stars }) { | ||
return ( | ||
<> | ||
<p>Next.js has {stars} ⭐️</p> | ||
<Link href="/preact-stars">How about preact?</Link> | ||
</> | ||
) | ||
} |
This file contains 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,15 @@ | ||
import { trace } from '@opentelemetry/api' | ||
|
||
export async function fetchGithubStars() { | ||
const span = trace.getTracer('nextjs-example').startSpan('fetchGithubStars') | ||
return fetch('https://api.github.com/repos/vercel/next.js', { | ||
next: { | ||
revalidate: 0, | ||
}, | ||
}) | ||
.then((res) => res.json()) | ||
.then((data) => data.stargazers_count) | ||
.finally(() => { | ||
span.end() | ||
}) | ||
} |
This file contains 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,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true, | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
], | ||
"strictNullChecks": true | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a reminder to update the readme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do in a subsequent pr