Skip to content

Commit

Permalink
drop conds, refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jul 16, 2024
1 parent 14982bb commit a6fbf3a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
11 changes: 4 additions & 7 deletions packages/next/src/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ export default class DevServer extends Server {
const telemetry = new Telemetry({ distDir: this.distDir })

await super.prepareImpl()
await this.startServerSpan
.traceChild('run-instrumentation-hook')
.traceAsyncFn(() => this.runInstrumentationHookIfAvailable())
await this.matchers.reload()

// Store globals again to preserve changes made by the instrumentation hook.
Expand Down Expand Up @@ -623,10 +620,10 @@ export default class DevServer extends Server {
return instrumentationModule
}

private async runInstrumentationHookIfAvailable() {
if (this.instrumentation) {
await this.instrumentation.register?.()
}
protected async runInstrumentationHookIfAvailable() {
await this.startServerSpan
.traceChild('run-instrumentation-hook')
.traceAsyncFn(() => this.instrumentation?.register?.())
}

protected async ensureEdgeFunction({
Expand Down
17 changes: 7 additions & 10 deletions packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,11 @@ export default class NextNodeServer extends BaseServer<
// development.
}

private isProductionInstrumentationEnabled = () => {
return (
protected async loadInstrumentationModule() {
if (
!this.serverOptions.dev &&
!!this.nextConfig.experimental.instrumentationHook
)
}

protected async loadInstrumentationModule() {
if (this.isProductionInstrumentationEnabled()) {
) {
try {
this.instrumentation = await dynamicRequire(
resolve(
Expand All @@ -336,10 +332,11 @@ export default class NextNodeServer extends BaseServer<

protected async prepareImpl() {
await super.prepareImpl()
await this.runInstrumentationHookIfAvailable()
}

if (this.isProductionInstrumentationEnabled()) {
await this.instrumentation?.register?.()
}
protected async runInstrumentationHookIfAvailable() {
await this.instrumentation?.register?.()
}

protected loadEnvConfig({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ describe('instrumentation-hook - register-once', () => {

it('should only register once', async () => {
await next.fetch('/foo')
expect(next.cliOutput.split('register-log').length).toBe(2)
expect(next.cliOutput).toIncludeRepeated('register-log', 1)
})
})

0 comments on commit a6fbf3a

Please sign in to comment.