Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions docs/plugins/google-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ The `googleCloud()` plugin takes an optional configuration object:
```ts
{
projectId?: string,
forceDevExport?: boolean,
telemetryConfig?: TelemetryConfig
}
```
Expand All @@ -71,12 +70,6 @@ The `googleCloud()` plugin takes an optional configuration object:

This option allows specifying the Google Cloud project ID explicitly. In most cases, this is unnecessary.

### forceDevExport

This option will force Genkit to export telemetry and log data when running in the `dev` environment (e.g. locally).

> Note: When running locally, internal telemetry buffers may not fully flush prior to the process exiting, resulting in an incomplete telemetry export.

### telemetryConfig

This option configures the [OpenTelemetry NodeSDK](https://open-telemetry.github.io/opentelemetry-js/classes/_opentelemetry_sdk_node.NodeSDK.html) instance.
Expand All @@ -85,8 +78,8 @@ This option configures the [OpenTelemetry NodeSDK](https://open-telemetry.github
import { AlwaysOnSampler } from '@opentelemetry/sdk-trace-base';

googleCloud({
forceDevExport: false, // Set this to true to export telemetry for local runs
telemetryConfig: {
forceDevExport: false, // Set this to true to export telemetry for local runs
sampler: new AlwaysOnSampler(),
autoInstrumentation: true,
autoInstrumentationConfig: {
Expand All @@ -99,6 +92,12 @@ googleCloud({
});
```

#### forceDevExport

This option will force Genkit to export telemetry and log data when running in the `dev` environment (e.g. locally).

> Note: When running locally, internal telemetry buffers may not fully flush prior to the process exiting, resulting in an incomplete telemetry export.

#### sampler

For cases where exporting all traces isn't practical, OpenTelemetry allows trace [sampling](https://opentelemetry.io/docs/languages/java/instrumentation/#sampler).
Expand Down
1 change: 1 addition & 0 deletions js/plugins/firebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@genkit-ai/ai": "workspace:*",
"@genkit-ai/core": "workspace:*",
"@genkit-ai/flow": "workspace:*",
"@genkit-ai/google-cloud": "workspace:*",
"express": "^4.19.2",
"google-auth-library": "^9.6.3",
"zod": "^3.22.4"
Expand Down
16 changes: 16 additions & 0 deletions js/plugins/firebase/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

import { genkitPlugin, Plugin } from '@genkit-ai/core';
import { FirestoreStateStore } from '@genkit-ai/flow';
import {
GcpLogger,
GcpOpenTelemetry,
TelemetryConfig,
} from '@genkit-ai/google-cloud';
import { FirestoreTraceStore } from './firestoreTraceStore.js';
export { defineFirestoreRetriever } from './firestoreRetriever.js';

Expand All @@ -29,6 +34,7 @@ interface FirestorePluginParams {
collection?: string;
databaseId?: string;
};
telemetryConfig?: TelemetryConfig;
}

export const firebase: Plugin<[FirestorePluginParams] | []> = genkitPlugin(
Expand All @@ -42,5 +48,15 @@ export const firebase: Plugin<[FirestorePluginParams] | []> = genkitPlugin(
id: 'firestore',
value: new FirestoreTraceStore(params?.traceStore),
},
telemetry: {
instrumentation: {
id: 'firebase',
value: new GcpOpenTelemetry(params),
},
logger: {
id: 'firebase',
value: new GcpLogger(params),
},
},
})
);
2 changes: 1 addition & 1 deletion js/plugins/google-cloud/src/gcpLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ export class GcpLogger implements LoggerConfig {
}

private shouldExport(env: string) {
return this.options.forceDevExport || env !== 'dev';
return this.options.telemetryConfig?.forceDevExport || env !== 'dev';
}
}
6 changes: 4 additions & 2 deletions js/plugins/google-cloud/src/gcpOpenTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,16 @@ export class GcpOpenTelemetry implements TelemetryConfig {

private shouldExportTraces(): boolean {
return (
(this.options.forceDevExport || process.env.GENKIT_ENV !== 'dev') &&
(this.options.telemetryConfig?.forceDevExport ||
process.env.GENKIT_ENV !== 'dev') &&
!this.options.telemetryConfig?.disableTraces
);
}

private shouldExportMetrics(): boolean {
return (
(this.options.forceDevExport || process.env.GENKIT_ENV !== 'dev') &&
(this.options.telemetryConfig?.forceDevExport ||
process.env.GENKIT_ENV !== 'dev') &&
!this.options.telemetryConfig?.disableMetrics
);
}
Expand Down
5 changes: 4 additions & 1 deletion js/plugins/google-cloud/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { GcpOpenTelemetry } from './gcpOpenTelemetry.js';

export interface PluginOptions {
projectId?: string;
forceDevExport?: boolean;
telemetryConfig?: TelemetryConfig;
}

Expand All @@ -41,6 +40,9 @@ export interface TelemetryConfig {

/** When true, traces are not sent to GCP. */
disableTraces?: boolean;

/** When true, telemetry data will be exported, even for local runs */
forceDevExport?: boolean;
}

/**
Expand Down Expand Up @@ -72,4 +74,5 @@ export const googleCloud: Plugin<[PluginOptions] | []> = genkitPlugin(
);

export default googleCloud;
export * from './gcpLogger.js';
export * from './gcpOpenTelemetry.js';
6 changes: 3 additions & 3 deletions js/plugins/google-cloud/tests/metrics_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe('GoogleCloudMetrics', () => {
// Force GCP Plugin to use in-memory metrics exporter
plugins: [
googleCloud({
forceDevExport: false,
telemetryConfig: {
forceDevExport: false,
metricExportIntervalMillis: 100,
metricExportTimeoutMillis: 100,
},
Expand Down Expand Up @@ -390,8 +390,8 @@ describe('GoogleCloudMetrics', () => {
describe('Configuration', () => {
it('should export only traces', async () => {
const telemetry = new GcpOpenTelemetry({
forceDevExport: true,
telemetryConfig: {
forceDevExport: true,
disableMetrics: true,
},
});
Expand All @@ -401,8 +401,8 @@ describe('GoogleCloudMetrics', () => {

it('should export only metrics', async () => {
const telemetry = new GcpOpenTelemetry({
forceDevExport: true,
telemetryConfig: {
forceDevExport: true,
disableTraces: true,
disableMetrics: false,
},
Expand Down
3 changes: 3 additions & 0 deletions js/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.