UNPKG

@genkit-ai/google-cloud

Version:

Genkit AI framework plugin for Google Cloud Platform including Firestore trace/state store and deployment helpers for Cloud Functions for Firebase.

1 lines 2.76 kB
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getCurrentEnv } from 'genkit';\nimport { logger } from 'genkit/logging';\nimport { enableTelemetry } from 'genkit/tracing';\nimport { credentialsFromEnvironment } from './auth.js';\nimport { GcpLogger } from './gcpLogger.js';\nimport { GcpOpenTelemetry } from './gcpOpenTelemetry.js';\nimport { TelemetryConfigs } from './telemetry/defaults.js';\nimport type { GcpTelemetryConfig, GcpTelemetryConfigOptions } from './types.js';\n\n/**\n * Enables telemetry export to the Google Cloud Observability suite.\n *\n * @param options configuration options\n */\nexport function enableGoogleCloudTelemetry(\n options?: GcpTelemetryConfigOptions\n) {\n return enableTelemetry(\n configureGcpPlugin(options).then(async (pluginConfig) => {\n logger.init(await new GcpLogger(pluginConfig).getLogger(getCurrentEnv()));\n return new GcpOpenTelemetry(pluginConfig).getConfig();\n })\n );\n}\n\n/**\n * Create a configuration object for the plugin.\n * Not normally needed, but exposed for use by the Firebase plugin.\n */\nasync function configureGcpPlugin(\n options?: GcpTelemetryConfigOptions\n): Promise<GcpTelemetryConfig> {\n const envOptions = await credentialsFromEnvironment();\n return {\n projectId: options?.projectId || envOptions.projectId,\n credentials: options?.credentials || envOptions.credentials,\n ...TelemetryConfigs.defaults(options),\n };\n}\n\nexport * from './gcpLogger.js';\nexport * from './gcpOpenTelemetry.js';\nexport type { GcpTelemetryConfigOptions } from './types.js';\n"],"mappings":"AAgBA,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AACvB,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AAQ1B,SAAS,2BACd,SACA;AACA,SAAO;AAAA,IACL,mBAAmB,OAAO,EAAE,KAAK,OAAO,iBAAiB;AACvD,aAAO,KAAK,MAAM,IAAI,UAAU,YAAY,EAAE,UAAU,cAAc,CAAC,CAAC;AACxE,aAAO,IAAI,iBAAiB,YAAY,EAAE,UAAU;AAAA,IACtD,CAAC;AAAA,EACH;AACF;AAMA,eAAe,mBACb,SAC6B;AAC7B,QAAM,aAAa,MAAM,2BAA2B;AACpD,SAAO;AAAA,IACL,WAAW,SAAS,aAAa,WAAW;AAAA,IAC5C,aAAa,SAAS,eAAe,WAAW;AAAA,IAChD,GAAG,iBAAiB,SAAS,OAAO;AAAA,EACtC;AACF;AAEA,cAAc;AACd,cAAc;","names":[]}