Skip to content

feat: add OTEL instrumentation for next-server + OTEL example - #46198

Merged
feedthejim merged 46 commits into
canaryfrom
feedthejim/otel
Feb 22, 2023
Merged

feedthejim merged 46 commits into
canaryfrom
feedthejim/otel

Conversation

@feedthejim

@feedthejim feedthejim commented Feb 21, 2023 •

Copy link
Copy Markdown
Contributor

fix NEXT-479 (link)

content

This PR adds a getTracer API to Next.js that uses the otel/api under the hood to provide Next.js level instrumentation through Open Telemetry.

This also adds an example with-opentelemetry to demonstrate how it can be used, assuming you have a collector.

This allows most notably to have getServerSideProps and fetch calls inside Server Components traced.

details

  • we hide most internals spans, if you want to see all of them, use the NEXT_OTEL_VERBOSE=1 env var
  • if you want to use this, you'll need to rely on the config.experimental.instrumentationHook config option to initialise OTEL, like in the example

Bug

  • Related issues linked using fixes #number
  • Integration tests added
  • Errors have a helpful link attached, see contributing.md

Feature

  • Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
  • Related issues linked using fixes #number
  • e2e tests added
  • Documentation added
  • Telemetry added. In case of a feature if it's used or not.
  • Errors have a helpful link attached, see contributing.md

Documentation / Examples

  • Make sure the linting passes by running pnpm build && pnpm lint
  • The "examples guidelines" are followed from our contributing doc

@ijjk ijjk added examples Issue was opened via the examples template. created-by: Next.js team PRs by the Next.js team. type: next labels Feb 21, 2023
@feedthejim feedthejim changed the title feat: add OTEL instrumentation for next-server feat: add OTEL instrumentation for next-server + OTEL example Feb 21, 2023
@feedthejim
feedthejim marked this pull request as ready for review February 21, 2023 17:13
@feedthejim
feedthejim marked this pull request as ready for review February 22, 2023 08:37
@@ -0,0 +1,30 @@
# Data fetch example

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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

timneutkens
timneutkens previously approved these changes Feb 22, 2023
@feedthejim
feedthejim enabled auto-merge (squash) February 22, 2023 14:05
* This should be lazily evaluated.
*/
private getTracerInstance(): Tracer {
return trace.getTracer('next.js', '0.0.1')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's the 0.0.1 version for? should we cache it as a property instead call getTracer each time or this is by designed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this makes much difference in both ways

@@ -0,0 +1,23 @@
export function register() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

@feedthejim
feedthejim merged commit 4072955 into canary Feb 22, 2023
@feedthejim
feedthejim deleted the feedthejim/otel branch February 22, 2023 15:08
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

created-by: Next.js team PRs by the Next.js team. examples Issue was opened via the examples template. type: next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants