Skip to content

Optionally enable telemetry collection during Genkit init #8530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/init/features/genkit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,23 @@ export async function genkitSetup(
default: true,
}))
) {
generateSampleFile(modelOptions[model].plugin, plugins, projectDir, genkitInfo.templateVersion);
logger.info(
"Telemetry data can be used to monitor and gain insights into your AI features. There may be a cost associated with using this feature. See https://firebase.google.com/docs/genkit/observability/telemetry-collection.",
);
const enableTelemetry =
options.nonInteractive ||
(await confirm({
message: "Would like you to enable telemetry collection?",
default: true,
}));

generateSampleFile(
modelOptions[model].plugin,
plugins,
projectDir,
genkitInfo.templateVersion,
enableTelemetry,
);
}
}

Expand Down Expand Up @@ -507,6 +523,7 @@ function generateSampleFile(
configPlugins: string[],
projectDir: string,
templateVersion: string,
enableTelemetry: boolean,
): void {
let modelImport = "";
if (modelPlugin && pluginToInfo[modelPlugin].model) {
Expand Down Expand Up @@ -534,6 +551,7 @@ function generateSampleFile(
? pluginToInfo[modelPlugin].model || pluginToInfo[modelPlugin].modelStr || ""
: "'' /* TODO: Set a model. */",
),
enableTelemetry,
);
logLabeledBullet("genkit", "Generating sample file");
try {
Expand Down Expand Up @@ -622,7 +640,7 @@ async function updatePackageJson(nonInteractive: boolean, projectDir: string): P
}
}

function renderConfig(pluginNames: string[], template: string): string {
function renderConfig(pluginNames: string[], template: string, enableTelemetry: boolean): string {
const imports = pluginNames
.map((pluginName) => generateImportStatement(pluginToInfo[pluginName].imports, pluginName))
.join("\n");
Expand All @@ -631,7 +649,8 @@ function renderConfig(pluginNames: string[], template: string): string {
" /* Add your plugins here. */";
return template
.replace("$GENKIT_CONFIG_IMPORTS", imports)
.replace("$GENKIT_CONFIG_PLUGINS", plugins);
.replace("$GENKIT_CONFIG_PLUGINS", plugins)
.replace("$GENKIT_ENABLE_TELEMETRY", enableTelemetry.toString());
}

function generateImportStatement(imports: string, name: string): string {
Expand Down
8 changes: 8 additions & 0 deletions templates/genkit/firebase.1.0.0.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Import the Genkit core libraries and plugins.
import {genkit, z} from "genkit";
import {enableFirebaseTelemetry} from "@genkit-ai/firebase";
$GENKIT_CONFIG_IMPORTS
$GENKIT_MODEL_IMPORT

Expand All @@ -21,6 +22,13 @@ $GENKIT_CONFIG_PLUGINS
],
});

// Collect telemetry on your deployed app to be used in production monitoring.
// See https://firebase.google.com/docs/genkit/observability/telemetry-collection.
const enableTelemetry = $GENKIT_ENABLE_TELEMETRY;
if (enableTelemetry) {
enableFirebaseTelemetry();
}

// Define a simple flow that prompts an LLM to generate menu suggestions.
const menuSuggestionFlow = ai.defineFlow({
name: "menuSuggestionFlow",
Expand Down
Loading