Skip to content

Commit f909997

Browse files
committed
Control enableFirebaseTelemetry with a variable
1 parent d5cd2e7 commit f909997

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
@@ -640,24 +640,16 @@ async function updatePackageJson(nonInteractive: boolean, projectDir: string): P
640640
}
641641

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

663655
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)