@@ -382,7 +382,21 @@ export async function genkitSetup(
382
382
default : true ,
383
383
} ) )
384
384
) {
385
- generateSampleFile ( modelOptions [ model ] . plugin , plugins , projectDir , genkitInfo . templateVersion ) ;
385
+
386
+ 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." ) ;
387
+ const enableTelemetry =
388
+ options . nonInteractive ||
389
+ ( await confirm ( {
390
+ message : "Would like you to enable telemetry collection?" ,
391
+ default : true
392
+ } ) ) ;
393
+
394
+ generateSampleFile (
395
+ modelOptions [ model ] . plugin ,
396
+ plugins ,
397
+ projectDir ,
398
+ genkitInfo . templateVersion ,
399
+ enableTelemetry ) ;
386
400
}
387
401
}
388
402
@@ -507,6 +521,7 @@ function generateSampleFile(
507
521
configPlugins : string [ ] ,
508
522
projectDir : string ,
509
523
templateVersion : string ,
524
+ enableTelemetry : boolean ,
510
525
) : void {
511
526
let modelImport = "" ;
512
527
if ( modelPlugin && pluginToInfo [ modelPlugin ] . model ) {
@@ -534,6 +549,7 @@ function generateSampleFile(
534
549
? pluginToInfo [ modelPlugin ] . model || pluginToInfo [ modelPlugin ] . modelStr || ""
535
550
: "'' /* TODO: Set a model. */" ,
536
551
) ,
552
+ enableTelemetry ,
537
553
) ;
538
554
logLabeledBullet ( "genkit" , "Generating sample file" ) ;
539
555
try {
@@ -622,16 +638,24 @@ async function updatePackageJson(nonInteractive: boolean, projectDir: string): P
622
638
}
623
639
}
624
640
625
- function renderConfig ( pluginNames : string [ ] , template : string ) : string {
641
+ function renderConfig ( pluginNames : string [ ] , template : string , enableTelemetry : boolean ) : string {
626
642
const imports = pluginNames
627
- . map ( ( pluginName ) => generateImportStatement ( pluginToInfo [ pluginName ] . imports , pluginName ) )
628
- . join ( "\n" ) ;
643
+ . map ( ( pluginName ) => generateImportStatement ( pluginToInfo [ pluginName ] . imports , pluginName ) ) ;
644
+ if ( enableTelemetry ) {
645
+ imports . push ( generateImportStatement ( "enableFirebaseTelemetry" , "@genkit-ai/firebase" ) ) ;
646
+ }
647
+ const telemetryBlock = enableTelemetry
648
+ ? "\n// Collect telemetry data to enable production monitoring.\n" +
649
+ "// See https://firebase.google.com/docs/genkit/observability/telemetry-collection.\n" +
650
+ "enableFirebaseTelemetry();\n"
651
+ : "" ;
629
652
const plugins =
630
653
pluginNames . map ( ( pluginName ) => ` ${ pluginToInfo [ pluginName ] . init } ,` ) . join ( "\n" ) ||
631
654
" /* Add your plugins here. */" ;
632
655
return template
633
- . replace ( "$GENKIT_CONFIG_IMPORTS" , imports )
634
- . replace ( "$GENKIT_CONFIG_PLUGINS" , plugins ) ;
656
+ . replace ( "$GENKIT_CONFIG_IMPORTS" , imports . join ( "\n" ) )
657
+ . replace ( "$GENKIT_CONFIG_PLUGINS" , plugins )
658
+ . replace ( "$GENKIT_ENABLE_TELEMETRY" , telemetryBlock ) ;
635
659
}
636
660
637
661
function generateImportStatement ( imports : string , name : string ) : string {
0 commit comments