Skip to content

[JS] [Nextjs] googleCloud telemetry does not work due to bundling issues #937

@MichaelDoyle

Description

@MichaelDoyle

Describe the bug

Init a new next.js project using the genkit CLI. Then add the googleCloud plugin and enable telemetry. google-proto-files are stripped by the bundler, unless explicitly externalized and/or required.

failed to create client: ENOENT: no such file or directory, open '/<REDACTED>/.next/google/devtools/cloudtrace/v2/tracing.proto'
{"stack":"Error: failed to create client: ENOENT: no such file or directory, open '/<REDACTED>/.next/google/devtools/cloudtrace/v2/tracing.proto'","message":"failed to create client: ENOENT: no such file or directory, open '/<REDACTED>/.next/google/devtools/cloudtrace/v2/tracing.proto'","errno":"-2","code":"ENOENT","syscall":"open","path":"/<REDACTED>/.next/google/devtools/cloudtrace/v2/tracing.proto","name":"Error"}

Resolution is to externalize this dependency and manually require it

nextjs.config.mjs

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: [
      'google-proto-files',
    ],
  },
};

export default nextConfig;

genkit.ts

require('google-proto-files')

Runtime (please complete the following information):

Node: 20.17.0
Genkit: 0.5.13
Next: 14.2.12

** Node version**

v20.17.0

Additional context
This issue broadly applies to the use of bundlers. Issue was reported upstream GoogleCloudPlatform/opentelemetry-operations-js Issue 404 and a fix has been proposed, that we should track GoogleCloudPlatform/opentelemetry-operations-js PR 741.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingjs

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions