Skip to content

Commit 80fdb10

Browse files
committed
Control enableFirebaseTelemetry with a variable
1 parent 4254403 commit 80fdb10

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/init/features/genkit/index.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -641,24 +641,16 @@ async function updatePackageJson(nonInteractive: boolean, projectDir: string): P
641641
}
642642

643643
function renderConfig(pluginNames: string[], template: string, enableTelemetry: boolean): string {
644-
const imports = pluginNames.map((pluginName) =>
645-
generateImportStatement(pluginToInfo[pluginName].imports, pluginName),
646-
);
647-
if (enableTelemetry) {
648-
imports.push(generateImportStatement("enableFirebaseTelemetry", "@genkit-ai/firebase"));
649-
}
650-
const telemetryBlock = enableTelemetry
651-
? "\n// Collect telemetry data to enable production monitoring.\n" +
652-
"// See https://firebase.google.com/docs/genkit/observability/telemetry-collection.\n" +
653-
"enableFirebaseTelemetry();\n"
654-
: "";
644+
const imports = pluginNames
645+
.map((pluginName) => generateImportStatement(pluginToInfo[pluginName].imports, pluginName))
646+
.join("\n");
655647
const plugins =
656648
pluginNames.map((pluginName) => ` ${pluginToInfo[pluginName].init},`).join("\n") ||
657649
" /* Add your plugins here. */";
658650
return template
659-
.replace("$GENKIT_CONFIG_IMPORTS", imports.join("\n"))
651+
.replace("$GENKIT_CONFIG_IMPORTS", imports)
660652
.replace("$GENKIT_CONFIG_PLUGINS", plugins)
661-
.replace("$GENKIT_ENABLE_TELEMETRY", telemetryBlock);
653+
.replace("$GENKIT_ENABLE_TELEMETRY", enableTelemetry.toString());
662654
}
663655

664656
function generateImportStatement(imports: string, name: string): string {

templates/genkit/firebase.1.0.0.template

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Import the Genkit core libraries and plugins.
22
import {genkit, z} from "genkit";
3+
import {enableFirebaseTelemetry} from "@genkit-ai/firebase";
34
$GENKIT_CONFIG_IMPORTS
45
$GENKIT_MODEL_IMPORT
56

@@ -20,7 +21,14 @@ const ai = genkit({
2021
$GENKIT_CONFIG_PLUGINS
2122
],
2223
});
23-
$GENKIT_ENABLE_TELEMETRY
24+
25+
// Collect telemetry on your deployed app to be used in production monitoring.
26+
// See https://firebase.google.com/docs/genkit/observability/telemetry-collection.
27+
const enableTelemetry = $GENKIT_ENABLE_TELEMETRY;
28+
if (enableTelemetry) {
29+
enableFirebaseTelemetry();
30+
}
31+
2432
// Define a simple flow that prompts an LLM to generate menu suggestions.
2533
const menuSuggestionFlow = ai.defineFlow({
2634
name: "menuSuggestionFlow",

0 commit comments

Comments
 (0)