google-logging-utils-internal 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/LICENSE +203 -0
- package/package/README.md +83 -0
- package/package/lib/auth.d.mts +33 -0
- package/package/lib/auth.d.ts +33 -0
- package/package/lib/auth.js +70 -0
- package/package/lib/auth.js.map +1 -0
- package/package/lib/auth.mjs +45 -0
- package/package/lib/auth.mjs.map +1 -0
- package/package/lib/gcpLogger.d.mts +25 -0
- package/package/lib/gcpLogger.d.ts +25 -0
- package/package/lib/gcpLogger.js +118 -0
- package/package/lib/gcpLogger.js.map +1 -0
- package/package/lib/gcpLogger.mjs +82 -0
- package/package/lib/gcpLogger.mjs.map +1 -0
- package/package/lib/gcpOpenTelemetry.d.mts +59 -0
- package/package/lib/gcpOpenTelemetry.d.ts +59 -0
- package/package/lib/gcpOpenTelemetry.js +374 -0
- package/package/lib/gcpOpenTelemetry.js.map +1 -0
- package/package/lib/gcpOpenTelemetry.mjs +364 -0
- package/package/lib/gcpOpenTelemetry.mjs.map +1 -0
- package/package/lib/index.d.mts +36 -0
- package/package/lib/index.d.ts +36 -0
- package/package/lib/index.js +56 -0
- package/package/lib/index.js.map +1 -0
- package/package/lib/index.mjs +29 -0
- package/package/lib/index.mjs.map +1 -0
- package/package/lib/metrics.d.mts +65 -0
- package/package/lib/metrics.d.ts +65 -0
- package/package/lib/metrics.js +91 -0
- package/package/lib/metrics.js.map +1 -0
- package/package/lib/metrics.mjs +65 -0
- package/package/lib/metrics.mjs.map +1 -0
- package/package/lib/model-armor.d.mts +59 -0
- package/package/lib/model-armor.d.ts +59 -0
- package/package/lib/model-armor.js +205 -0
- package/package/lib/model-armor.js.map +1 -0
- package/package/lib/model-armor.mjs +181 -0
- package/package/lib/model-armor.mjs.map +1 -0
- package/package/lib/telemetry/action.d.mts +27 -0
- package/package/lib/telemetry/action.d.ts +27 -0
- package/package/lib/telemetry/action.js +92 -0
- package/package/lib/telemetry/action.js.map +1 -0
- package/package/lib/telemetry/action.mjs +73 -0
- package/package/lib/telemetry/action.mjs.map +1 -0
- package/package/lib/telemetry/defaults.d.mts +30 -0
- package/package/lib/telemetry/defaults.d.ts +30 -0
- package/package/lib/telemetry/defaults.js +70 -0
- package/package/lib/telemetry/defaults.js.map +1 -0
- package/package/lib/telemetry/defaults.mjs +46 -0
- package/package/lib/telemetry/defaults.mjs.map +1 -0
- package/package/lib/telemetry/engagement.d.mts +35 -0
- package/package/lib/telemetry/engagement.d.ts +35 -0
- package/package/lib/telemetry/engagement.js +106 -0
- package/package/lib/telemetry/engagement.js.map +1 -0
- package/package/lib/telemetry/engagement.mjs +85 -0
- package/package/lib/telemetry/engagement.mjs.map +1 -0
- package/package/lib/telemetry/feature.d.mts +35 -0
- package/package/lib/telemetry/feature.d.ts +35 -0
- package/package/lib/telemetry/feature.js +142 -0
- package/package/lib/telemetry/feature.js.map +1 -0
- package/package/lib/telemetry/feature.mjs +127 -0
- package/package/lib/telemetry/feature.mjs.map +1 -0
- package/package/lib/telemetry/generate.d.mts +53 -0
- package/package/lib/telemetry/generate.d.ts +53 -0
- package/package/lib/telemetry/generate.js +326 -0
- package/package/lib/telemetry/generate.js.map +1 -0
- package/package/lib/telemetry/generate.mjs +314 -0
- package/package/lib/telemetry/generate.mjs.map +1 -0
- package/package/lib/telemetry/path.d.mts +32 -0
- package/package/lib/telemetry/path.d.ts +32 -0
- package/package/lib/telemetry/path.js +91 -0
- package/package/lib/telemetry/path.js.map +1 -0
- package/package/lib/telemetry/path.mjs +78 -0
- package/package/lib/telemetry/path.mjs.map +1 -0
- package/package/lib/types.d.mts +121 -0
- package/package/lib/types.d.ts +121 -0
- package/package/lib/types.js +17 -0
- package/package/lib/types.js.map +1 -0
- package/package/lib/types.mjs +1 -0
- package/package/lib/types.mjs.map +1 -0
- package/package/lib/utils.d.mts +57 -0
- package/package/lib/utils.d.ts +57 -0
- package/package/lib/utils.js +143 -0
- package/package/lib/utils.js.map +1 -0
- package/package/lib/utils.mjs +104 -0
- package/package/lib/utils.mjs.map +1 -0
- package/package/package.json +90 -0
- package/package/src/auth.ts +89 -0
- package/package/src/gcpLogger.ts +124 -0
- package/package/src/gcpOpenTelemetry.ts +485 -0
- package/package/src/index.ts +59 -0
- package/package/src/metrics.ts +122 -0
- package/package/src/model-armor.ts +317 -0
- package/package/src/telemetry/action.ts +106 -0
- package/package/src/telemetry/defaults.ts +72 -0
- package/package/src/telemetry/engagement.ts +120 -0
- package/package/src/telemetry/feature.ts +170 -0
- package/package/src/telemetry/generate.ts +454 -0
- package/package/src/telemetry/path.ts +111 -0
- package/package/src/types.ts +133 -0
- package/package/src/utils.ts +175 -0
- package/package/tests/logs_no_input_output_test.ts +267 -0
- package/package/tests/logs_session_test.ts +219 -0
- package/package/tests/logs_test.ts +633 -0
- package/package/tests/metrics_test.ts +792 -0
- package/package/tests/model_armor_test.ts +336 -0
- package/package/tests/traces_test.ts +380 -0
- package/package/typedoc.json +3 -0
- package/package.json +10 -0
package/package/LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Google Cloud Plugin for Genkit
|
|
2
|
+
|
|
3
|
+
The Google Cloud plugin provides integrations with Google Cloud Platform services for Genkit.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
* **Google Cloud Observability**: Exports telemetry (traces, metrics) and logs to Google Cloud's operations suite.
|
|
8
|
+
* **Model Armor**: Middleware for sanitizing user prompts and model responses using Google Cloud Model Armor.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @genkit-ai/google-cloud
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Google Cloud Observability
|
|
17
|
+
|
|
18
|
+
The plugin allows you to export telemetry data to Google Cloud. This is useful for monitoring your Genkit flows and models in production.
|
|
19
|
+
|
|
20
|
+
To enable it, use `enableGoogleCloudTelemetry`:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { enableGoogleCloudTelemetry } from '@genkit-ai/google-cloud';
|
|
24
|
+
|
|
25
|
+
enableGoogleCloudTelemetry({
|
|
26
|
+
// Optional configuration
|
|
27
|
+
// projectId: 'your-project-id',
|
|
28
|
+
// forceDevMode: false, // Set to true to enable export in dev environment
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This will configure Genkit to send OpenTelemetry traces and metrics to Cloud Trace and Cloud Monitoring, and logs to Cloud Logging.
|
|
33
|
+
|
|
34
|
+
## Model Armor
|
|
35
|
+
|
|
36
|
+
[Google Cloud Model Armor](https://docs.cloud.google.com/model-armor/overview) helps you mitigate risks when using Large Language Models (LLMs) by providing a layer of protection that sanitizes both user prompts and model responses.
|
|
37
|
+
|
|
38
|
+
### Usage
|
|
39
|
+
|
|
40
|
+
You can use the `modelArmor` middleware in your generation requests:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { modelArmor } from '@genkit-ai/google-cloud/model-armor';
|
|
44
|
+
import { googleAI } from '@genkit-ai/google-genai';
|
|
45
|
+
import { genkit } from 'genkit';
|
|
46
|
+
|
|
47
|
+
const ai = genkit({
|
|
48
|
+
plugins: [googleAI()],
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const response = await ai.generate({
|
|
52
|
+
model: googleAI.model('gemini-2.5-flash'),
|
|
53
|
+
prompt: 'your prompt here',
|
|
54
|
+
use: [
|
|
55
|
+
modelArmor({
|
|
56
|
+
templateName: 'projects/your-project/locations/your-location/templates/your-template',
|
|
57
|
+
// Optional configuration
|
|
58
|
+
filters: ['pi_and_jailbreak', 'malicious_uris'], // Specific filters to enforce
|
|
59
|
+
strictSdpEnforcement: true, // Block if sensitive data is found even if masked
|
|
60
|
+
protectionTarget: 'all', // 'all', 'userPrompt', or 'modelResponse'
|
|
61
|
+
clientOptions: {
|
|
62
|
+
apiEndpoint: 'modelarmor.us-central1.rep.googleapis.com',
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Configuration Options
|
|
70
|
+
|
|
71
|
+
* `templateName` (Required): The resource name of your Model Armor template (e.g., `projects/.../locations/.../templates/...`).
|
|
72
|
+
* `filters` (Optional): A list of filters to enforce (e.g., `rai`, `pi_and_jailbreak`, `malicious_uris`, `csam`, `sdp`). If not specified, all filters enabled in the template are enforced.
|
|
73
|
+
* `strictSdpEnforcement` (Optional): If `true`, blocks execution if Sensitive Data Protection (SDP) detects sensitive info, even if it was successfully de-identified. Defaults to `false`.
|
|
74
|
+
* `protectionTarget` (Optional): specificies what to sanitize. Options: `'all'` (default), `'userPrompt'`, `'modelResponse'`.
|
|
75
|
+
* `clientOptions` (Optional): Additional options for the underlying Model Armor client.
|
|
76
|
+
|
|
77
|
+
## Reference
|
|
78
|
+
|
|
79
|
+
Visit the [official Genkit documentation](https://genkit.dev/docs/get-started/) for more information.
|
|
80
|
+
|
|
81
|
+
The sources for this package are in the main [Genkit](https://github.com/genkit-ai/genkit) repo. Please file issues and pull requests against that repo.
|
|
82
|
+
|
|
83
|
+
License: Apache 2.0
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { GcpTelemetryConfig, GcpPrincipal } from './types.mjs';
|
|
2
|
+
import '@opentelemetry/auto-instrumentations-node';
|
|
3
|
+
import '@opentelemetry/instrumentation';
|
|
4
|
+
import '@opentelemetry/sdk-trace-base';
|
|
5
|
+
import 'google-auth-library';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Allows Google Cloud credentials to be to passed in "raw" as an environment
|
|
9
|
+
* variable. This is helpful in environments where the developer has limited
|
|
10
|
+
* ability to configure their compute environment, but does have the ablilty to
|
|
11
|
+
* set environment variables.
|
|
12
|
+
*
|
|
13
|
+
* This is different from the GOOGLE_APPLICATION_CREDENTIALS used by ADC, which
|
|
14
|
+
* represents a path to a credential file on disk. In *most* cases, even for
|
|
15
|
+
* 3rd party cloud providers, developers *should* attempt to use ADC, which
|
|
16
|
+
* searches for credential files in standard locations, before using this
|
|
17
|
+
* method.
|
|
18
|
+
*
|
|
19
|
+
* See also: https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#loading-credentials-from-environment-variables
|
|
20
|
+
*/
|
|
21
|
+
declare function credentialsFromEnvironment(): Promise<Partial<GcpTelemetryConfig>>;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve the currently configured principal, either from the Genkit specific
|
|
24
|
+
* GCLOUD_SERVICE_ACCOUNT_CREDS environment variable, or from ADC.
|
|
25
|
+
*
|
|
26
|
+
* Since the Google Cloud Telemetry Exporter will discover credentials on its
|
|
27
|
+
* own, we don't immediately have access to the current principal. This method
|
|
28
|
+
* can be handy to get access to the current credential for logging debugging
|
|
29
|
+
* information or other purposes.
|
|
30
|
+
**/
|
|
31
|
+
declare function resolveCurrentPrincipal(): Promise<GcpPrincipal>;
|
|
32
|
+
|
|
33
|
+
export { credentialsFromEnvironment, resolveCurrentPrincipal };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { GcpTelemetryConfig, GcpPrincipal } from './types.js';
|
|
2
|
+
import '@opentelemetry/auto-instrumentations-node';
|
|
3
|
+
import '@opentelemetry/instrumentation';
|
|
4
|
+
import '@opentelemetry/sdk-trace-base';
|
|
5
|
+
import 'google-auth-library';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Allows Google Cloud credentials to be to passed in "raw" as an environment
|
|
9
|
+
* variable. This is helpful in environments where the developer has limited
|
|
10
|
+
* ability to configure their compute environment, but does have the ablilty to
|
|
11
|
+
* set environment variables.
|
|
12
|
+
*
|
|
13
|
+
* This is different from the GOOGLE_APPLICATION_CREDENTIALS used by ADC, which
|
|
14
|
+
* represents a path to a credential file on disk. In *most* cases, even for
|
|
15
|
+
* 3rd party cloud providers, developers *should* attempt to use ADC, which
|
|
16
|
+
* searches for credential files in standard locations, before using this
|
|
17
|
+
* method.
|
|
18
|
+
*
|
|
19
|
+
* See also: https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#loading-credentials-from-environment-variables
|
|
20
|
+
*/
|
|
21
|
+
declare function credentialsFromEnvironment(): Promise<Partial<GcpTelemetryConfig>>;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve the currently configured principal, either from the Genkit specific
|
|
24
|
+
* GCLOUD_SERVICE_ACCOUNT_CREDS environment variable, or from ADC.
|
|
25
|
+
*
|
|
26
|
+
* Since the Google Cloud Telemetry Exporter will discover credentials on its
|
|
27
|
+
* own, we don't immediately have access to the current principal. This method
|
|
28
|
+
* can be handy to get access to the current credential for logging debugging
|
|
29
|
+
* information or other purposes.
|
|
30
|
+
**/
|
|
31
|
+
declare function resolveCurrentPrincipal(): Promise<GcpPrincipal>;
|
|
32
|
+
|
|
33
|
+
export { credentialsFromEnvironment, resolveCurrentPrincipal };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var auth_exports = {};
|
|
20
|
+
__export(auth_exports, {
|
|
21
|
+
credentialsFromEnvironment: () => credentialsFromEnvironment,
|
|
22
|
+
resolveCurrentPrincipal: () => resolveCurrentPrincipal
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(auth_exports);
|
|
25
|
+
var import_logging = require("genkit/logging");
|
|
26
|
+
var import_google_auth_library = require("google-auth-library");
|
|
27
|
+
async function credentialsFromEnvironment() {
|
|
28
|
+
let authClient;
|
|
29
|
+
const options = {};
|
|
30
|
+
if (process.env.GCLOUD_SERVICE_ACCOUNT_CREDS) {
|
|
31
|
+
import_logging.logger.debug("Retrieving credentials from GCLOUD_SERVICE_ACCOUNT_CREDS");
|
|
32
|
+
const serviceAccountCreds = JSON.parse(
|
|
33
|
+
process.env.GCLOUD_SERVICE_ACCOUNT_CREDS
|
|
34
|
+
);
|
|
35
|
+
const authOptions = { credentials: serviceAccountCreds };
|
|
36
|
+
authClient = new import_google_auth_library.GoogleAuth(authOptions);
|
|
37
|
+
options.credentials = await authClient.getCredentials();
|
|
38
|
+
} else {
|
|
39
|
+
authClient = new import_google_auth_library.GoogleAuth();
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const projectId = await authClient.getProjectId();
|
|
43
|
+
if (projectId && projectId.length > 0) {
|
|
44
|
+
options.projectId = projectId;
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
import_logging.logger.warn(error);
|
|
48
|
+
}
|
|
49
|
+
return options;
|
|
50
|
+
}
|
|
51
|
+
async function resolveCurrentPrincipal() {
|
|
52
|
+
const envCredentials = await credentialsFromEnvironment();
|
|
53
|
+
let adcCredentials = {};
|
|
54
|
+
try {
|
|
55
|
+
adcCredentials = await import_google_auth_library.auth.getCredentials();
|
|
56
|
+
} catch (e) {
|
|
57
|
+
import_logging.logger.debug("Could not retrieve client_email from ADC.");
|
|
58
|
+
}
|
|
59
|
+
const serviceAccountEmail = envCredentials.credentials?.client_email ?? adcCredentials.client_email;
|
|
60
|
+
return {
|
|
61
|
+
projectId: envCredentials.projectId,
|
|
62
|
+
serviceAccountEmail
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
credentialsFromEnvironment,
|
|
68
|
+
resolveCurrentPrincipal
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auth.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 */\nimport { logger } from 'genkit/logging';\nimport { GoogleAuth, auth, type CredentialBody } from 'google-auth-library';\nimport type { GcpPrincipal, GcpTelemetryConfig } from './types.js';\n\n/**\n * Allows Google Cloud credentials to be to passed in \"raw\" as an environment\n * variable. This is helpful in environments where the developer has limited\n * ability to configure their compute environment, but does have the ablilty to\n * set environment variables.\n *\n * This is different from the GOOGLE_APPLICATION_CREDENTIALS used by ADC, which\n * represents a path to a credential file on disk. In *most* cases, even for\n * 3rd party cloud providers, developers *should* attempt to use ADC, which\n * searches for credential files in standard locations, before using this\n * method.\n *\n * See also: https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#loading-credentials-from-environment-variables\n */\nexport async function credentialsFromEnvironment(): Promise<\n Partial<GcpTelemetryConfig>\n> {\n let authClient: GoogleAuth;\n const options: Partial<GcpTelemetryConfig> = {};\n\n if (process.env.GCLOUD_SERVICE_ACCOUNT_CREDS) {\n logger.debug('Retrieving credentials from GCLOUD_SERVICE_ACCOUNT_CREDS');\n const serviceAccountCreds = JSON.parse(\n process.env.GCLOUD_SERVICE_ACCOUNT_CREDS\n );\n const authOptions = { credentials: serviceAccountCreds };\n authClient = new GoogleAuth(authOptions);\n options.credentials = await authClient.getCredentials();\n } else {\n authClient = new GoogleAuth();\n }\n try {\n const projectId = await authClient.getProjectId();\n if (projectId && projectId.length > 0) {\n options.projectId = projectId;\n }\n } catch (error) {\n logger.warn(error);\n }\n return options;\n}\n\n/**\n * Resolve the currently configured principal, either from the Genkit specific\n * GCLOUD_SERVICE_ACCOUNT_CREDS environment variable, or from ADC.\n *\n * Since the Google Cloud Telemetry Exporter will discover credentials on its\n * own, we don't immediately have access to the current principal. This method\n * can be handy to get access to the current credential for logging debugging\n * information or other purposes.\n **/\nexport async function resolveCurrentPrincipal(): Promise<GcpPrincipal> {\n const envCredentials = await credentialsFromEnvironment();\n let adcCredentials = {} as CredentialBody;\n try {\n adcCredentials = await auth.getCredentials();\n } catch (e) {\n logger.debug('Could not retrieve client_email from ADC.');\n }\n\n // TODO(michaeldoyle): How to look up if the user provided credentials in the\n // plugin config (i.e. GcpTelemetryOptions)\n const serviceAccountEmail =\n envCredentials.credentials?.client_email ?? adcCredentials.client_email;\n\n return {\n projectId: envCredentials.projectId,\n serviceAccountEmail,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,qBAAuB;AACvB,iCAAsD;AAiBtD,eAAsB,6BAEpB;AACA,MAAI;AACJ,QAAM,UAAuC,CAAC;AAE9C,MAAI,QAAQ,IAAI,8BAA8B;AAC5C,0BAAO,MAAM,0DAA0D;AACvE,UAAM,sBAAsB,KAAK;AAAA,MAC/B,QAAQ,IAAI;AAAA,IACd;AACA,UAAM,cAAc,EAAE,aAAa,oBAAoB;AACvD,iBAAa,IAAI,sCAAW,WAAW;AACvC,YAAQ,cAAc,MAAM,WAAW,eAAe;AAAA,EACxD,OAAO;AACL,iBAAa,IAAI,sCAAW;AAAA,EAC9B;AACA,MAAI;AACF,UAAM,YAAY,MAAM,WAAW,aAAa;AAChD,QAAI,aAAa,UAAU,SAAS,GAAG;AACrC,cAAQ,YAAY;AAAA,IACtB;AAAA,EACF,SAAS,OAAO;AACd,0BAAO,KAAK,KAAK;AAAA,EACnB;AACA,SAAO;AACT;AAWA,eAAsB,0BAAiD;AACrE,QAAM,iBAAiB,MAAM,2BAA2B;AACxD,MAAI,iBAAiB,CAAC;AACtB,MAAI;AACF,qBAAiB,MAAM,gCAAK,eAAe;AAAA,EAC7C,SAAS,GAAG;AACV,0BAAO,MAAM,2CAA2C;AAAA,EAC1D;AAIA,QAAM,sBACJ,eAAe,aAAa,gBAAgB,eAAe;AAE7D,SAAO;AAAA,IACL,WAAW,eAAe;AAAA,IAC1B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { logger } from "genkit/logging";
|
|
2
|
+
import { GoogleAuth, auth } from "google-auth-library";
|
|
3
|
+
async function credentialsFromEnvironment() {
|
|
4
|
+
let authClient;
|
|
5
|
+
const options = {};
|
|
6
|
+
if (process.env.GCLOUD_SERVICE_ACCOUNT_CREDS) {
|
|
7
|
+
logger.debug("Retrieving credentials from GCLOUD_SERVICE_ACCOUNT_CREDS");
|
|
8
|
+
const serviceAccountCreds = JSON.parse(
|
|
9
|
+
process.env.GCLOUD_SERVICE_ACCOUNT_CREDS
|
|
10
|
+
);
|
|
11
|
+
const authOptions = { credentials: serviceAccountCreds };
|
|
12
|
+
authClient = new GoogleAuth(authOptions);
|
|
13
|
+
options.credentials = await authClient.getCredentials();
|
|
14
|
+
} else {
|
|
15
|
+
authClient = new GoogleAuth();
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const projectId = await authClient.getProjectId();
|
|
19
|
+
if (projectId && projectId.length > 0) {
|
|
20
|
+
options.projectId = projectId;
|
|
21
|
+
}
|
|
22
|
+
} catch (error) {
|
|
23
|
+
logger.warn(error);
|
|
24
|
+
}
|
|
25
|
+
return options;
|
|
26
|
+
}
|
|
27
|
+
async function resolveCurrentPrincipal() {
|
|
28
|
+
const envCredentials = await credentialsFromEnvironment();
|
|
29
|
+
let adcCredentials = {};
|
|
30
|
+
try {
|
|
31
|
+
adcCredentials = await auth.getCredentials();
|
|
32
|
+
} catch (e) {
|
|
33
|
+
logger.debug("Could not retrieve client_email from ADC.");
|
|
34
|
+
}
|
|
35
|
+
const serviceAccountEmail = envCredentials.credentials?.client_email ?? adcCredentials.client_email;
|
|
36
|
+
return {
|
|
37
|
+
projectId: envCredentials.projectId,
|
|
38
|
+
serviceAccountEmail
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
credentialsFromEnvironment,
|
|
43
|
+
resolveCurrentPrincipal
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=auth.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auth.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 */\nimport { logger } from 'genkit/logging';\nimport { GoogleAuth, auth, type CredentialBody } from 'google-auth-library';\nimport type { GcpPrincipal, GcpTelemetryConfig } from './types.js';\n\n/**\n * Allows Google Cloud credentials to be to passed in \"raw\" as an environment\n * variable. This is helpful in environments where the developer has limited\n * ability to configure their compute environment, but does have the ablilty to\n * set environment variables.\n *\n * This is different from the GOOGLE_APPLICATION_CREDENTIALS used by ADC, which\n * represents a path to a credential file on disk. In *most* cases, even for\n * 3rd party cloud providers, developers *should* attempt to use ADC, which\n * searches for credential files in standard locations, before using this\n * method.\n *\n * See also: https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#loading-credentials-from-environment-variables\n */\nexport async function credentialsFromEnvironment(): Promise<\n Partial<GcpTelemetryConfig>\n> {\n let authClient: GoogleAuth;\n const options: Partial<GcpTelemetryConfig> = {};\n\n if (process.env.GCLOUD_SERVICE_ACCOUNT_CREDS) {\n logger.debug('Retrieving credentials from GCLOUD_SERVICE_ACCOUNT_CREDS');\n const serviceAccountCreds = JSON.parse(\n process.env.GCLOUD_SERVICE_ACCOUNT_CREDS\n );\n const authOptions = { credentials: serviceAccountCreds };\n authClient = new GoogleAuth(authOptions);\n options.credentials = await authClient.getCredentials();\n } else {\n authClient = new GoogleAuth();\n }\n try {\n const projectId = await authClient.getProjectId();\n if (projectId && projectId.length > 0) {\n options.projectId = projectId;\n }\n } catch (error) {\n logger.warn(error);\n }\n return options;\n}\n\n/**\n * Resolve the currently configured principal, either from the Genkit specific\n * GCLOUD_SERVICE_ACCOUNT_CREDS environment variable, or from ADC.\n *\n * Since the Google Cloud Telemetry Exporter will discover credentials on its\n * own, we don't immediately have access to the current principal. This method\n * can be handy to get access to the current credential for logging debugging\n * information or other purposes.\n **/\nexport async function resolveCurrentPrincipal(): Promise<GcpPrincipal> {\n const envCredentials = await credentialsFromEnvironment();\n let adcCredentials = {} as CredentialBody;\n try {\n adcCredentials = await auth.getCredentials();\n } catch (e) {\n logger.debug('Could not retrieve client_email from ADC.');\n }\n\n // TODO(michaeldoyle): How to look up if the user provided credentials in the\n // plugin config (i.e. GcpTelemetryOptions)\n const serviceAccountEmail =\n envCredentials.credentials?.client_email ?? adcCredentials.client_email;\n\n return {\n projectId: envCredentials.projectId,\n serviceAccountEmail,\n };\n}\n"],"mappings":"AAeA,SAAS,cAAc;AACvB,SAAS,YAAY,YAAiC;AAiBtD,eAAsB,6BAEpB;AACA,MAAI;AACJ,QAAM,UAAuC,CAAC;AAE9C,MAAI,QAAQ,IAAI,8BAA8B;AAC5C,WAAO,MAAM,0DAA0D;AACvE,UAAM,sBAAsB,KAAK;AAAA,MAC/B,QAAQ,IAAI;AAAA,IACd;AACA,UAAM,cAAc,EAAE,aAAa,oBAAoB;AACvD,iBAAa,IAAI,WAAW,WAAW;AACvC,YAAQ,cAAc,MAAM,WAAW,eAAe;AAAA,EACxD,OAAO;AACL,iBAAa,IAAI,WAAW;AAAA,EAC9B;AACA,MAAI;AACF,UAAM,YAAY,MAAM,WAAW,aAAa;AAChD,QAAI,aAAa,UAAU,SAAS,GAAG;AACrC,cAAQ,YAAY;AAAA,IACtB;AAAA,EACF,SAAS,OAAO;AACd,WAAO,KAAK,KAAK;AAAA,EACnB;AACA,SAAO;AACT;AAWA,eAAsB,0BAAiD;AACrE,QAAM,iBAAiB,MAAM,2BAA2B;AACxD,MAAI,iBAAiB,CAAC;AACtB,MAAI;AACF,qBAAiB,MAAM,KAAK,eAAe;AAAA,EAC7C,SAAS,GAAG;AACV,WAAO,MAAM,2CAA2C;AAAA,EAC1D;AAIA,QAAM,sBACJ,eAAe,aAAa,gBAAgB,eAAe;AAE7D,SAAO;AAAA,IACL,WAAW,eAAe;AAAA,IAC1B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as winston from 'winston';
|
|
2
|
+
import { Writable } from 'stream';
|
|
3
|
+
import { GcpTelemetryConfig } from './types.mjs';
|
|
4
|
+
import '@opentelemetry/auto-instrumentations-node';
|
|
5
|
+
import '@opentelemetry/instrumentation';
|
|
6
|
+
import '@opentelemetry/sdk-trace-base';
|
|
7
|
+
import 'google-auth-library';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Provides a logger for exporting Genkit debug logs to GCP Cloud
|
|
11
|
+
* logs.
|
|
12
|
+
*/
|
|
13
|
+
declare class GcpLogger {
|
|
14
|
+
private readonly config;
|
|
15
|
+
constructor(config: GcpTelemetryConfig);
|
|
16
|
+
getLogger(env: string): Promise<winston.Logger>;
|
|
17
|
+
private getErrorHandler;
|
|
18
|
+
private shouldExport;
|
|
19
|
+
}
|
|
20
|
+
/** @hidden */
|
|
21
|
+
declare function __addTransportStreamForTesting(stream: Writable): void;
|
|
22
|
+
/** @hidden */
|
|
23
|
+
declare function __useJsonFormatForTesting(): void;
|
|
24
|
+
|
|
25
|
+
export { GcpLogger, __addTransportStreamForTesting, __useJsonFormatForTesting };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as winston from 'winston';
|
|
2
|
+
import { Writable } from 'stream';
|
|
3
|
+
import { GcpTelemetryConfig } from './types.js';
|
|
4
|
+
import '@opentelemetry/auto-instrumentations-node';
|
|
5
|
+
import '@opentelemetry/instrumentation';
|
|
6
|
+
import '@opentelemetry/sdk-trace-base';
|
|
7
|
+
import 'google-auth-library';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Provides a logger for exporting Genkit debug logs to GCP Cloud
|
|
11
|
+
* logs.
|
|
12
|
+
*/
|
|
13
|
+
declare class GcpLogger {
|
|
14
|
+
private readonly config;
|
|
15
|
+
constructor(config: GcpTelemetryConfig);
|
|
16
|
+
getLogger(env: string): Promise<winston.Logger>;
|
|
17
|
+
private getErrorHandler;
|
|
18
|
+
private shouldExport;
|
|
19
|
+
}
|
|
20
|
+
/** @hidden */
|
|
21
|
+
declare function __addTransportStreamForTesting(stream: Writable): void;
|
|
22
|
+
/** @hidden */
|
|
23
|
+
declare function __useJsonFormatForTesting(): void;
|
|
24
|
+
|
|
25
|
+
export { GcpLogger, __addTransportStreamForTesting, __useJsonFormatForTesting };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var gcpLogger_exports = {};
|
|
30
|
+
__export(gcpLogger_exports, {
|
|
31
|
+
GcpLogger: () => GcpLogger,
|
|
32
|
+
__addTransportStreamForTesting: () => __addTransportStreamForTesting,
|
|
33
|
+
__useJsonFormatForTesting: () => __useJsonFormatForTesting
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(gcpLogger_exports);
|
|
36
|
+
var import_logging_winston = require("@google-cloud/logging-winston");
|
|
37
|
+
var import_genkit = require("genkit");
|
|
38
|
+
var import_logging = require("genkit/logging");
|
|
39
|
+
var import_utils = require("./utils.js");
|
|
40
|
+
let additionalStream;
|
|
41
|
+
let useJsonFormatOverride = false;
|
|
42
|
+
class GcpLogger {
|
|
43
|
+
constructor(config) {
|
|
44
|
+
this.config = config;
|
|
45
|
+
}
|
|
46
|
+
async getLogger(env) {
|
|
47
|
+
const winston = await import("winston");
|
|
48
|
+
const format = useJsonFormatOverride || this.shouldExport(env) ? { format: winston.format.json() } : {
|
|
49
|
+
format: winston.format.printf((info) => {
|
|
50
|
+
return `[${info.level}] ${info.message}`;
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
const transports = [];
|
|
54
|
+
transports.push(
|
|
55
|
+
this.shouldExport(env) ? new import_logging_winston.LoggingWinston({
|
|
56
|
+
labels: { module: "genkit" },
|
|
57
|
+
prefix: "genkit",
|
|
58
|
+
logName: "genkit_log",
|
|
59
|
+
projectId: this.config.projectId,
|
|
60
|
+
credentials: this.config.credentials,
|
|
61
|
+
autoRetry: true,
|
|
62
|
+
defaultCallback: await this.getErrorHandler()
|
|
63
|
+
}) : new winston.transports.Console()
|
|
64
|
+
);
|
|
65
|
+
if (additionalStream) {
|
|
66
|
+
transports.push(
|
|
67
|
+
new winston.transports.Stream({ stream: additionalStream })
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return winston.createLogger({
|
|
71
|
+
transports,
|
|
72
|
+
...format,
|
|
73
|
+
exceptionHandlers: [new winston.transports.Console()]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async getErrorHandler() {
|
|
77
|
+
let instructionsLogged = false;
|
|
78
|
+
const helpInstructions = await (0, import_utils.loggingDeniedHelpText)();
|
|
79
|
+
return async (err) => {
|
|
80
|
+
const defaultLogger = import_logging.logger.defaultLogger;
|
|
81
|
+
if (err && (0, import_utils.loggingDenied)(err)) {
|
|
82
|
+
if (!instructionsLogged) {
|
|
83
|
+
instructionsLogged = true;
|
|
84
|
+
defaultLogger.error(
|
|
85
|
+
`Unable to send logs to Google Cloud: ${err.message}
|
|
86
|
+
|
|
87
|
+
${helpInstructions}
|
|
88
|
+
`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
} else if (err) {
|
|
92
|
+
defaultLogger.error(`Unable to send logs to Google Cloud: ${err}`);
|
|
93
|
+
}
|
|
94
|
+
if (err) {
|
|
95
|
+
import_logging.logger.init(
|
|
96
|
+
await new GcpLogger(this.config).getLogger((0, import_genkit.getCurrentEnv)())
|
|
97
|
+
);
|
|
98
|
+
defaultLogger.info("Initialized a new GcpLogger.");
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
shouldExport(env) {
|
|
103
|
+
return this.config.export;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function __addTransportStreamForTesting(stream) {
|
|
107
|
+
additionalStream = stream;
|
|
108
|
+
}
|
|
109
|
+
function __useJsonFormatForTesting() {
|
|
110
|
+
useJsonFormatOverride = true;
|
|
111
|
+
}
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
GcpLogger,
|
|
115
|
+
__addTransportStreamForTesting,
|
|
116
|
+
__useJsonFormatForTesting
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=gcpLogger.js.map
|