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.
Files changed (109) hide show
  1. package/package/LICENSE +203 -0
  2. package/package/README.md +83 -0
  3. package/package/lib/auth.d.mts +33 -0
  4. package/package/lib/auth.d.ts +33 -0
  5. package/package/lib/auth.js +70 -0
  6. package/package/lib/auth.js.map +1 -0
  7. package/package/lib/auth.mjs +45 -0
  8. package/package/lib/auth.mjs.map +1 -0
  9. package/package/lib/gcpLogger.d.mts +25 -0
  10. package/package/lib/gcpLogger.d.ts +25 -0
  11. package/package/lib/gcpLogger.js +118 -0
  12. package/package/lib/gcpLogger.js.map +1 -0
  13. package/package/lib/gcpLogger.mjs +82 -0
  14. package/package/lib/gcpLogger.mjs.map +1 -0
  15. package/package/lib/gcpOpenTelemetry.d.mts +59 -0
  16. package/package/lib/gcpOpenTelemetry.d.ts +59 -0
  17. package/package/lib/gcpOpenTelemetry.js +374 -0
  18. package/package/lib/gcpOpenTelemetry.js.map +1 -0
  19. package/package/lib/gcpOpenTelemetry.mjs +364 -0
  20. package/package/lib/gcpOpenTelemetry.mjs.map +1 -0
  21. package/package/lib/index.d.mts +36 -0
  22. package/package/lib/index.d.ts +36 -0
  23. package/package/lib/index.js +56 -0
  24. package/package/lib/index.js.map +1 -0
  25. package/package/lib/index.mjs +29 -0
  26. package/package/lib/index.mjs.map +1 -0
  27. package/package/lib/metrics.d.mts +65 -0
  28. package/package/lib/metrics.d.ts +65 -0
  29. package/package/lib/metrics.js +91 -0
  30. package/package/lib/metrics.js.map +1 -0
  31. package/package/lib/metrics.mjs +65 -0
  32. package/package/lib/metrics.mjs.map +1 -0
  33. package/package/lib/model-armor.d.mts +59 -0
  34. package/package/lib/model-armor.d.ts +59 -0
  35. package/package/lib/model-armor.js +205 -0
  36. package/package/lib/model-armor.js.map +1 -0
  37. package/package/lib/model-armor.mjs +181 -0
  38. package/package/lib/model-armor.mjs.map +1 -0
  39. package/package/lib/telemetry/action.d.mts +27 -0
  40. package/package/lib/telemetry/action.d.ts +27 -0
  41. package/package/lib/telemetry/action.js +92 -0
  42. package/package/lib/telemetry/action.js.map +1 -0
  43. package/package/lib/telemetry/action.mjs +73 -0
  44. package/package/lib/telemetry/action.mjs.map +1 -0
  45. package/package/lib/telemetry/defaults.d.mts +30 -0
  46. package/package/lib/telemetry/defaults.d.ts +30 -0
  47. package/package/lib/telemetry/defaults.js +70 -0
  48. package/package/lib/telemetry/defaults.js.map +1 -0
  49. package/package/lib/telemetry/defaults.mjs +46 -0
  50. package/package/lib/telemetry/defaults.mjs.map +1 -0
  51. package/package/lib/telemetry/engagement.d.mts +35 -0
  52. package/package/lib/telemetry/engagement.d.ts +35 -0
  53. package/package/lib/telemetry/engagement.js +106 -0
  54. package/package/lib/telemetry/engagement.js.map +1 -0
  55. package/package/lib/telemetry/engagement.mjs +85 -0
  56. package/package/lib/telemetry/engagement.mjs.map +1 -0
  57. package/package/lib/telemetry/feature.d.mts +35 -0
  58. package/package/lib/telemetry/feature.d.ts +35 -0
  59. package/package/lib/telemetry/feature.js +142 -0
  60. package/package/lib/telemetry/feature.js.map +1 -0
  61. package/package/lib/telemetry/feature.mjs +127 -0
  62. package/package/lib/telemetry/feature.mjs.map +1 -0
  63. package/package/lib/telemetry/generate.d.mts +53 -0
  64. package/package/lib/telemetry/generate.d.ts +53 -0
  65. package/package/lib/telemetry/generate.js +326 -0
  66. package/package/lib/telemetry/generate.js.map +1 -0
  67. package/package/lib/telemetry/generate.mjs +314 -0
  68. package/package/lib/telemetry/generate.mjs.map +1 -0
  69. package/package/lib/telemetry/path.d.mts +32 -0
  70. package/package/lib/telemetry/path.d.ts +32 -0
  71. package/package/lib/telemetry/path.js +91 -0
  72. package/package/lib/telemetry/path.js.map +1 -0
  73. package/package/lib/telemetry/path.mjs +78 -0
  74. package/package/lib/telemetry/path.mjs.map +1 -0
  75. package/package/lib/types.d.mts +121 -0
  76. package/package/lib/types.d.ts +121 -0
  77. package/package/lib/types.js +17 -0
  78. package/package/lib/types.js.map +1 -0
  79. package/package/lib/types.mjs +1 -0
  80. package/package/lib/types.mjs.map +1 -0
  81. package/package/lib/utils.d.mts +57 -0
  82. package/package/lib/utils.d.ts +57 -0
  83. package/package/lib/utils.js +143 -0
  84. package/package/lib/utils.js.map +1 -0
  85. package/package/lib/utils.mjs +104 -0
  86. package/package/lib/utils.mjs.map +1 -0
  87. package/package/package.json +90 -0
  88. package/package/src/auth.ts +89 -0
  89. package/package/src/gcpLogger.ts +124 -0
  90. package/package/src/gcpOpenTelemetry.ts +485 -0
  91. package/package/src/index.ts +59 -0
  92. package/package/src/metrics.ts +122 -0
  93. package/package/src/model-armor.ts +317 -0
  94. package/package/src/telemetry/action.ts +106 -0
  95. package/package/src/telemetry/defaults.ts +72 -0
  96. package/package/src/telemetry/engagement.ts +120 -0
  97. package/package/src/telemetry/feature.ts +170 -0
  98. package/package/src/telemetry/generate.ts +454 -0
  99. package/package/src/telemetry/path.ts +111 -0
  100. package/package/src/types.ts +133 -0
  101. package/package/src/utils.ts +175 -0
  102. package/package/tests/logs_no_input_output_test.ts +267 -0
  103. package/package/tests/logs_session_test.ts +219 -0
  104. package/package/tests/logs_test.ts +633 -0
  105. package/package/tests/metrics_test.ts +792 -0
  106. package/package/tests/model_armor_test.ts +336 -0
  107. package/package/tests/traces_test.ts +380 -0
  108. package/package/typedoc.json +3 -0
  109. package/package.json +10 -0
@@ -0,0 +1,181 @@
1
+ import { ModelArmorClient } from "@google-cloud/modelarmor";
2
+ import { GenkitError } from "genkit";
3
+ import { runInNewSpan } from "genkit/tracing";
4
+ function extractText(parts) {
5
+ return parts.map((p) => p.text || "").join("");
6
+ }
7
+ function applySdp(messages, targetIndex, result, options) {
8
+ const sdpFilterResult = result.filterResults?.["sdp"]?.sdpFilterResult;
9
+ if (!sdpFilterResult) {
10
+ return { sdpApplied: false, messages };
11
+ }
12
+ if (typeof options.applyDeidentificationResults === "function") {
13
+ const newMessages = options.applyDeidentificationResults({
14
+ messages,
15
+ sdpResult: sdpFilterResult
16
+ });
17
+ if (!newMessages) {
18
+ return { sdpApplied: false, messages };
19
+ }
20
+ const sdpApplied = !!sdpFilterResult.deidentifyResult?.data?.text;
21
+ return { sdpApplied, messages: newMessages };
22
+ }
23
+ if (options.applyDeidentificationResults === true) {
24
+ const deidentifyResult = sdpFilterResult.deidentifyResult;
25
+ if (deidentifyResult && deidentifyResult.data?.text) {
26
+ const targetMessage = messages[targetIndex];
27
+ const nonTextParts = targetMessage.content.filter((p) => !p.text);
28
+ const newContent = [
29
+ ...nonTextParts,
30
+ { text: deidentifyResult.data.text }
31
+ ];
32
+ const newMessages = [...messages];
33
+ newMessages[targetIndex] = { ...targetMessage, content: newContent };
34
+ return {
35
+ sdpApplied: true,
36
+ messages: newMessages
37
+ };
38
+ }
39
+ }
40
+ return { sdpApplied: false, messages };
41
+ }
42
+ function shouldBlock(result, options, sdpApplied) {
43
+ if (result.filterMatchState !== "MATCH_FOUND") {
44
+ return false;
45
+ }
46
+ if (options.strictSdpEnforcement && sdpApplied) {
47
+ return true;
48
+ }
49
+ if (result.filterResults) {
50
+ for (const [key, filterResult] of Object.entries(result.filterResults)) {
51
+ if (options.filters && !options.filters.includes(key)) continue;
52
+ if (key === "sdp" && sdpApplied) continue;
53
+ const nestedResult = Object.values(filterResult)[0];
54
+ if (nestedResult?.matchState === "MATCH_FOUND") {
55
+ return true;
56
+ }
57
+ }
58
+ }
59
+ return false;
60
+ }
61
+ async function sanitizeUserPrompt(req, client, options) {
62
+ let targetMessageIndex = -1;
63
+ for (let i = req.messages.length - 1; i >= 0; i--) {
64
+ if (req.messages[i].role === "user") {
65
+ targetMessageIndex = i;
66
+ break;
67
+ }
68
+ }
69
+ if (targetMessageIndex !== -1) {
70
+ const userMessage = req.messages[targetMessageIndex];
71
+ const promptText = extractText(userMessage.content);
72
+ if (promptText) {
73
+ await runInNewSpan(
74
+ { metadata: { name: "sanitizeUserPrompt" } },
75
+ async (meta) => {
76
+ meta.input = {
77
+ name: options.templateName,
78
+ userPromptData: {
79
+ text: promptText
80
+ }
81
+ };
82
+ const [response] = await client.sanitizeUserPrompt({
83
+ name: options.templateName,
84
+ userPromptData: {
85
+ text: promptText
86
+ }
87
+ });
88
+ meta.output = response;
89
+ if (response.sanitizationResult) {
90
+ const result = response.sanitizationResult;
91
+ const { sdpApplied, messages: modifiedMessages } = applySdp(
92
+ req.messages,
93
+ targetMessageIndex,
94
+ result,
95
+ options
96
+ );
97
+ if (sdpApplied || typeof options.applyDeidentificationResults === "function") {
98
+ req.messages = modifiedMessages;
99
+ }
100
+ if (shouldBlock(result, options, sdpApplied)) {
101
+ throw new GenkitError({
102
+ status: "PERMISSION_DENIED",
103
+ message: "Model Armor blocked user prompt.",
104
+ detail: result
105
+ });
106
+ }
107
+ }
108
+ }
109
+ );
110
+ }
111
+ }
112
+ }
113
+ async function sanitizeModelResponse(response, client, options) {
114
+ const usingMessageProp = !!response.message;
115
+ const candidates = response.message ? [{ index: 0, message: response.message, finishReason: "stop" }] : response.candidates || [];
116
+ for (const candidate of candidates) {
117
+ const modelText = extractText(candidate.message.content);
118
+ if (modelText) {
119
+ await runInNewSpan(
120
+ { metadata: { name: "sanitizeModelResponse" } },
121
+ async (meta) => {
122
+ meta.input = {
123
+ name: options.templateName,
124
+ modelResponseData: {
125
+ text: modelText
126
+ }
127
+ };
128
+ const [apiResponse] = await client.sanitizeModelResponse({
129
+ name: options.templateName,
130
+ modelResponseData: {
131
+ text: modelText
132
+ }
133
+ });
134
+ meta.output = apiResponse;
135
+ if (apiResponse.sanitizationResult) {
136
+ const result = apiResponse.sanitizationResult;
137
+ const { sdpApplied, messages: modifiedMessages } = applySdp(
138
+ [candidate.message],
139
+ 0,
140
+ result,
141
+ options
142
+ );
143
+ if (sdpApplied || typeof options.applyDeidentificationResults === "function") {
144
+ candidate.message = modifiedMessages[0];
145
+ }
146
+ if (shouldBlock(result, options, sdpApplied)) {
147
+ throw new GenkitError({
148
+ status: "PERMISSION_DENIED",
149
+ message: "Model Armor blocked model response.",
150
+ detail: result
151
+ });
152
+ }
153
+ }
154
+ }
155
+ );
156
+ }
157
+ }
158
+ if (usingMessageProp && candidates.length > 0) {
159
+ response.message = candidates[0].message;
160
+ }
161
+ }
162
+ function modelArmor(options) {
163
+ const client = options.client || new ModelArmorClient(options.clientOptions);
164
+ const protectionTarget = options.protectionTarget ?? "all";
165
+ const protectUserPrompt = protectionTarget === "all" || protectionTarget === "userPrompt";
166
+ const protectModelResponse = protectionTarget === "all" || protectionTarget === "modelResponse";
167
+ return async (req, next) => {
168
+ if (protectUserPrompt) {
169
+ await sanitizeUserPrompt(req, client, options);
170
+ }
171
+ const response = await next(req);
172
+ if (protectModelResponse) {
173
+ await sanitizeModelResponse(response, client, options);
174
+ }
175
+ return response;
176
+ };
177
+ }
178
+ export {
179
+ modelArmor
180
+ };
181
+ //# sourceMappingURL=model-armor.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/model-armor.ts"],"sourcesContent":["/**\n * Copyright 2025 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 { ModelArmorClient, protos } from '@google-cloud/modelarmor';\nimport { GenkitError } from 'genkit';\nimport {\n GenerateRequest,\n GenerateResponseData,\n MessageData,\n ModelMiddleware,\n Part,\n} from 'genkit/model';\nimport { runInNewSpan } from 'genkit/tracing';\n\nexport interface ModelArmorOptions {\n templateName: string;\n client?: ModelArmorClient;\n /**\n * Options for the Model Armor client (e.g. apiEndpoint).\n */\n clientOptions?: ConstructorParameters<typeof ModelArmorClient>[0];\n /**\n * What to sanitize. Defaults to 'all'.\n */\n protectionTarget?: 'all' | 'userPrompt' | 'modelResponse';\n /**\n * Whether to block on SDP match even if the content was successfully de-identified.\n * Defaults to false (lenient).\n */\n strictSdpEnforcement?: boolean;\n /**\n * List of filters to enforce. If not specified, all filters are enforced.\n * Possible values: 'rai', 'pi_and_jailbreak', 'malicious_uris', 'csam', 'sdp'.\n */\n filters?: (\n | 'rai'\n | 'pi_and_jailbreak'\n | 'malicious_uris'\n | 'csam'\n | 'sdp'\n | (string & {})\n )[];\n /**\n * Whether to apply the de-identification results to the content.\n * - If true, the default logic (replace text, preserve structure) is used.\n * - If false, no changes are applied.\n * - If a function, it is called with the messages and SDP result, and should return the new messages.\n *\n * Defaults to false.\n */\n applyDeidentificationResults?:\n | boolean\n | ((data: {\n messages: MessageData[];\n sdpResult: protos.google.cloud.modelarmor.v1.ISdpFilterResult;\n }) => MessageData[] | undefined);\n}\n\nfunction extractText(parts: Part[]): string {\n return parts.map((p) => p.text || '').join('');\n}\n\n/**\n * If SDP (Sensitive Data Protection) filter returns sanitized data,\n * we swap out the data with sanitized data.\n */\nfunction applySdp(\n messages: MessageData[],\n targetIndex: number,\n result: protos.google.cloud.modelarmor.v1.ISanitizationResult,\n options: ModelArmorOptions\n): { sdpApplied: boolean; messages: MessageData[] } {\n const sdpFilterResult = result.filterResults?.['sdp']?.sdpFilterResult;\n\n if (!sdpFilterResult) {\n return { sdpApplied: false, messages };\n }\n\n // If user provided applyDeidentificationResults, we use it to apply\n // the deidentification results.\n if (typeof options.applyDeidentificationResults === 'function') {\n const newMessages = options.applyDeidentificationResults({\n messages,\n sdpResult: sdpFilterResult,\n });\n if (!newMessages) {\n return { sdpApplied: false, messages };\n }\n const sdpApplied = !!sdpFilterResult.deidentifyResult?.data?.text;\n return { sdpApplied, messages: newMessages };\n }\n\n // if applyDeidentificationResults is set to true, we use the default/basic\n // approach to apply the results.\n if (options.applyDeidentificationResults === true) {\n const deidentifyResult = sdpFilterResult.deidentifyResult;\n if (deidentifyResult && deidentifyResult.data?.text) {\n const targetMessage = messages[targetIndex];\n const nonTextParts = targetMessage.content.filter((p) => !p.text);\n const newContent = [\n ...nonTextParts,\n { text: deidentifyResult.data.text },\n ];\n const newMessages = [...messages];\n newMessages[targetIndex] = { ...targetMessage, content: newContent };\n return {\n sdpApplied: true,\n messages: newMessages,\n };\n }\n }\n\n return { sdpApplied: false, messages };\n}\n\nfunction shouldBlock(\n result: protos.google.cloud.modelarmor.v1.ISanitizationResult,\n options: ModelArmorOptions,\n sdpApplied: boolean\n): boolean {\n if (result.filterMatchState !== 'MATCH_FOUND') {\n return false;\n }\n // Check if we should block.\n // If strict SDP enforcement is enabled and SDP was applied, we must block.\n if (options.strictSdpEnforcement && sdpApplied) {\n return true;\n }\n // Otherwise, check if any active filter matched.\n if (result.filterResults) {\n for (const [key, filterResult] of Object.entries(result.filterResults)) {\n if (options.filters && !options.filters.includes(key)) continue;\n if (key === 'sdp' && sdpApplied) continue;\n\n // Look for matchState in the nested object\n // e.g. filterResult.raiFilterResult.matchState\n const nestedResult = Object.values(filterResult)[0];\n if (nestedResult?.matchState === 'MATCH_FOUND') {\n return true;\n }\n }\n }\n return false;\n}\n\nasync function sanitizeUserPrompt(\n req: GenerateRequest,\n client: ModelArmorClient,\n options: ModelArmorOptions\n) {\n let targetMessageIndex = -1;\n // Find the last user message to sanitize\n for (let i = req.messages.length - 1; i >= 0; i--) {\n if (req.messages[i].role === 'user') {\n targetMessageIndex = i;\n break;\n }\n }\n\n if (targetMessageIndex !== -1) {\n const userMessage = req.messages[targetMessageIndex];\n const promptText = extractText(userMessage.content);\n\n if (promptText) {\n await runInNewSpan(\n { metadata: { name: 'sanitizeUserPrompt' } },\n async (meta) => {\n meta.input = {\n name: options.templateName,\n userPromptData: {\n text: promptText,\n },\n };\n const [response] = await client.sanitizeUserPrompt({\n name: options.templateName,\n userPromptData: {\n text: promptText,\n },\n });\n meta.output = response;\n\n if (response.sanitizationResult) {\n const result = response.sanitizationResult;\n const { sdpApplied, messages: modifiedMessages } = applySdp(\n req.messages,\n targetMessageIndex,\n result,\n options\n );\n\n if (\n sdpApplied ||\n typeof options.applyDeidentificationResults === 'function'\n ) {\n req.messages = modifiedMessages;\n }\n\n if (shouldBlock(result, options, sdpApplied)) {\n throw new GenkitError({\n status: 'PERMISSION_DENIED',\n message: 'Model Armor blocked user prompt.',\n detail: result,\n });\n }\n }\n }\n );\n }\n }\n}\n\nasync function sanitizeModelResponse(\n response: GenerateResponseData,\n client: ModelArmorClient,\n options: ModelArmorOptions\n) {\n const usingMessageProp = !!response.message;\n const candidates = response.message\n ? [{ index: 0, message: response.message, finishReason: 'stop' }]\n : response.candidates || [];\n\n for (const candidate of candidates) {\n const modelText = extractText(candidate.message.content);\n\n if (modelText) {\n await runInNewSpan(\n { metadata: { name: 'sanitizeModelResponse' } },\n async (meta) => {\n meta.input = {\n name: options.templateName,\n modelResponseData: {\n text: modelText,\n },\n };\n const [apiResponse] = await client.sanitizeModelResponse({\n name: options.templateName,\n modelResponseData: {\n text: modelText,\n },\n });\n meta.output = apiResponse;\n\n if (apiResponse.sanitizationResult) {\n const result = apiResponse.sanitizationResult;\n const { sdpApplied, messages: modifiedMessages } = applySdp(\n [candidate.message],\n 0,\n result,\n options\n );\n\n if (\n sdpApplied ||\n typeof options.applyDeidentificationResults === 'function'\n ) {\n candidate.message = modifiedMessages[0];\n }\n\n if (shouldBlock(result, options, sdpApplied)) {\n throw new GenkitError({\n status: 'PERMISSION_DENIED',\n message: 'Model Armor blocked model response.',\n detail: result,\n });\n }\n }\n }\n );\n }\n }\n\n if (usingMessageProp && candidates.length > 0) {\n response.message = candidates[0].message;\n }\n}\n\n/**\n * Model Middleware that uses Google Cloud Model Armor to sanitize user prompts and model responses.\n */\nexport function modelArmor(options: ModelArmorOptions): ModelMiddleware {\n const client = options.client || new ModelArmorClient(options.clientOptions);\n const protectionTarget = options.protectionTarget ?? 'all';\n const protectUserPrompt =\n protectionTarget === 'all' || protectionTarget === 'userPrompt';\n const protectModelResponse =\n protectionTarget === 'all' || protectionTarget === 'modelResponse';\n\n return async (req, next) => {\n // 1. Sanitize User Prompt\n if (protectUserPrompt) {\n await sanitizeUserPrompt(req, client, options);\n }\n\n // 2. Call Model\n const response = await next(req);\n\n // 3. Sanitize Model Response\n if (protectModelResponse) {\n await sanitizeModelResponse(response, client, options);\n }\n\n return response;\n };\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,27 @@
1
+ import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
2
+ import { Telemetry } from '../metrics.mjs';
3
+ import '@opentelemetry/api';
4
+
5
+ /**
6
+ * Copyright 2024 Google LLC
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ declare class ActionTelemetry implements Telemetry {
22
+ tick(span: ReadableSpan, logInputAndOutput: boolean, projectId?: string): void;
23
+ private writeLog;
24
+ }
25
+ declare const actionTelemetry: ActionTelemetry;
26
+
27
+ export { actionTelemetry };
@@ -0,0 +1,27 @@
1
+ import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
2
+ import { Telemetry } from '../metrics.js';
3
+ import '@opentelemetry/api';
4
+
5
+ /**
6
+ * Copyright 2024 Google LLC
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ declare class ActionTelemetry implements Telemetry {
22
+ tick(span: ReadableSpan, logInputAndOutput: boolean, projectId?: string): void;
23
+ private writeLog;
24
+ }
25
+ declare const actionTelemetry: ActionTelemetry;
26
+
27
+ export { actionTelemetry };
@@ -0,0 +1,92 @@
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 action_exports = {};
20
+ __export(action_exports, {
21
+ actionTelemetry: () => actionTelemetry
22
+ });
23
+ module.exports = __toCommonJS(action_exports);
24
+ var import_logging = require("genkit/logging");
25
+ var import_tracing = require("genkit/tracing");
26
+ var import_utils = require("../utils.js");
27
+ class ActionTelemetry {
28
+ tick(span, logInputAndOutput, projectId) {
29
+ if (!logInputAndOutput) {
30
+ return;
31
+ }
32
+ const attributes = span.attributes;
33
+ const actionName = attributes["genkit:name"] || "<unknown>";
34
+ const subtype = attributes["genkit:metadata:subtype"];
35
+ if (subtype === "tool" || actionName === "generate") {
36
+ const path = attributes["genkit:path"] || "<unknown>";
37
+ const input = (0, import_utils.truncate)(attributes["genkit:input"]);
38
+ const output = (0, import_utils.truncate)(attributes["genkit:output"]);
39
+ const sessionId = attributes["genkit:sessionId"];
40
+ const threadName = attributes["genkit:threadName"];
41
+ let featureName = (0, import_utils.extractOuterFeatureNameFromPath)(path);
42
+ if (!featureName || featureName === "<unknown>") {
43
+ featureName = actionName;
44
+ }
45
+ if (input) {
46
+ this.writeLog(
47
+ span,
48
+ "Input",
49
+ featureName,
50
+ path,
51
+ input,
52
+ projectId,
53
+ sessionId,
54
+ threadName
55
+ );
56
+ }
57
+ if (output) {
58
+ this.writeLog(
59
+ span,
60
+ "Output",
61
+ featureName,
62
+ path,
63
+ output,
64
+ projectId,
65
+ sessionId,
66
+ threadName
67
+ );
68
+ }
69
+ }
70
+ }
71
+ writeLog(span, tag, featureName, qualifiedPath, content, projectId, sessionId, threadName) {
72
+ const path = (0, import_utils.truncatePath)((0, import_tracing.toDisplayPath)(qualifiedPath));
73
+ const sharedMetadata = {
74
+ ...(0, import_utils.createCommonLogAttributes)(span, projectId),
75
+ path,
76
+ qualifiedPath,
77
+ featureName,
78
+ sessionId,
79
+ threadName
80
+ };
81
+ import_logging.logger.logStructured(`${tag}[${path}, ${featureName}]`, {
82
+ ...sharedMetadata,
83
+ content
84
+ });
85
+ }
86
+ }
87
+ const actionTelemetry = new ActionTelemetry();
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ actionTelemetry
91
+ });
92
+ //# sourceMappingURL=action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/telemetry/action.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 type { ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport { logger } from 'genkit/logging';\nimport { toDisplayPath } from 'genkit/tracing';\nimport { type Telemetry } from '../metrics.js';\nimport {\n createCommonLogAttributes,\n extractOuterFeatureNameFromPath,\n truncate,\n truncatePath,\n} from '../utils.js';\n\nclass ActionTelemetry implements Telemetry {\n tick(\n span: ReadableSpan,\n logInputAndOutput: boolean,\n projectId?: string\n ): void {\n if (!logInputAndOutput) {\n return;\n }\n const attributes = span.attributes;\n const actionName = (attributes['genkit:name'] as string) || '<unknown>';\n const subtype = attributes['genkit:metadata:subtype'] as string;\n\n if (subtype === 'tool' || actionName === 'generate') {\n const path = (attributes['genkit:path'] as string) || '<unknown>';\n const input = truncate(attributes['genkit:input'] as string);\n const output = truncate(attributes['genkit:output'] as string);\n const sessionId = attributes['genkit:sessionId'] as string;\n const threadName = attributes['genkit:threadName'] as string;\n let featureName = extractOuterFeatureNameFromPath(path);\n if (!featureName || featureName === '<unknown>') {\n featureName = actionName;\n }\n\n if (input) {\n this.writeLog(\n span,\n 'Input',\n featureName,\n path,\n input,\n projectId,\n sessionId,\n threadName\n );\n }\n if (output) {\n this.writeLog(\n span,\n 'Output',\n featureName,\n path,\n output,\n projectId,\n sessionId,\n threadName\n );\n }\n }\n }\n\n private writeLog(\n span: ReadableSpan,\n tag: string,\n featureName: string,\n qualifiedPath: string,\n content: string,\n projectId?: string,\n sessionId?: string,\n threadName?: string\n ) {\n const path = truncatePath(toDisplayPath(qualifiedPath));\n const sharedMetadata = {\n ...createCommonLogAttributes(span, projectId),\n path,\n qualifiedPath,\n featureName,\n sessionId,\n threadName,\n };\n logger.logStructured(`${tag}[${path}, ${featureName}]`, {\n ...sharedMetadata,\n content,\n });\n }\n}\n\nconst actionTelemetry = new ActionTelemetry();\nexport { actionTelemetry };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,qBAAuB;AACvB,qBAA8B;AAE9B,mBAKO;AAEP,MAAM,gBAAqC;AAAA,EACzC,KACE,MACA,mBACA,WACM;AACN,QAAI,CAAC,mBAAmB;AACtB;AAAA,IACF;AACA,UAAM,aAAa,KAAK;AACxB,UAAM,aAAc,WAAW,aAAa,KAAgB;AAC5D,UAAM,UAAU,WAAW,yBAAyB;AAEpD,QAAI,YAAY,UAAU,eAAe,YAAY;AACnD,YAAM,OAAQ,WAAW,aAAa,KAAgB;AACtD,YAAM,YAAQ,uBAAS,WAAW,cAAc,CAAW;AAC3D,YAAM,aAAS,uBAAS,WAAW,eAAe,CAAW;AAC7D,YAAM,YAAY,WAAW,kBAAkB;AAC/C,YAAM,aAAa,WAAW,mBAAmB;AACjD,UAAI,kBAAc,8CAAgC,IAAI;AACtD,UAAI,CAAC,eAAe,gBAAgB,aAAa;AAC/C,sBAAc;AAAA,MAChB;AAEA,UAAI,OAAO;AACT,aAAK;AAAA,UACH;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AACA,UAAI,QAAQ;AACV,aAAK;AAAA,UACH;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,SACN,MACA,KACA,aACA,eACA,SACA,WACA,WACA,YACA;AACA,UAAM,WAAO,+BAAa,8BAAc,aAAa,CAAC;AACtD,UAAM,iBAAiB;AAAA,MACrB,OAAG,wCAA0B,MAAM,SAAS;AAAA,MAC5C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,0BAAO,cAAc,GAAG,GAAG,IAAI,IAAI,KAAK,WAAW,KAAK;AAAA,MACtD,GAAG;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEA,MAAM,kBAAkB,IAAI,gBAAgB;","names":[]}
@@ -0,0 +1,73 @@
1
+ import { logger } from "genkit/logging";
2
+ import { toDisplayPath } from "genkit/tracing";
3
+ import {
4
+ createCommonLogAttributes,
5
+ extractOuterFeatureNameFromPath,
6
+ truncate,
7
+ truncatePath
8
+ } from "../utils.js";
9
+ class ActionTelemetry {
10
+ tick(span, logInputAndOutput, projectId) {
11
+ if (!logInputAndOutput) {
12
+ return;
13
+ }
14
+ const attributes = span.attributes;
15
+ const actionName = attributes["genkit:name"] || "<unknown>";
16
+ const subtype = attributes["genkit:metadata:subtype"];
17
+ if (subtype === "tool" || actionName === "generate") {
18
+ const path = attributes["genkit:path"] || "<unknown>";
19
+ const input = truncate(attributes["genkit:input"]);
20
+ const output = truncate(attributes["genkit:output"]);
21
+ const sessionId = attributes["genkit:sessionId"];
22
+ const threadName = attributes["genkit:threadName"];
23
+ let featureName = extractOuterFeatureNameFromPath(path);
24
+ if (!featureName || featureName === "<unknown>") {
25
+ featureName = actionName;
26
+ }
27
+ if (input) {
28
+ this.writeLog(
29
+ span,
30
+ "Input",
31
+ featureName,
32
+ path,
33
+ input,
34
+ projectId,
35
+ sessionId,
36
+ threadName
37
+ );
38
+ }
39
+ if (output) {
40
+ this.writeLog(
41
+ span,
42
+ "Output",
43
+ featureName,
44
+ path,
45
+ output,
46
+ projectId,
47
+ sessionId,
48
+ threadName
49
+ );
50
+ }
51
+ }
52
+ }
53
+ writeLog(span, tag, featureName, qualifiedPath, content, projectId, sessionId, threadName) {
54
+ const path = truncatePath(toDisplayPath(qualifiedPath));
55
+ const sharedMetadata = {
56
+ ...createCommonLogAttributes(span, projectId),
57
+ path,
58
+ qualifiedPath,
59
+ featureName,
60
+ sessionId,
61
+ threadName
62
+ };
63
+ logger.logStructured(`${tag}[${path}, ${featureName}]`, {
64
+ ...sharedMetadata,
65
+ content
66
+ });
67
+ }
68
+ }
69
+ const actionTelemetry = new ActionTelemetry();
70
+ export {
71
+ actionTelemetry
72
+ };
73
+ //# sourceMappingURL=action.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/telemetry/action.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 type { ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport { logger } from 'genkit/logging';\nimport { toDisplayPath } from 'genkit/tracing';\nimport { type Telemetry } from '../metrics.js';\nimport {\n createCommonLogAttributes,\n extractOuterFeatureNameFromPath,\n truncate,\n truncatePath,\n} from '../utils.js';\n\nclass ActionTelemetry implements Telemetry {\n tick(\n span: ReadableSpan,\n logInputAndOutput: boolean,\n projectId?: string\n ): void {\n if (!logInputAndOutput) {\n return;\n }\n const attributes = span.attributes;\n const actionName = (attributes['genkit:name'] as string) || '<unknown>';\n const subtype = attributes['genkit:metadata:subtype'] as string;\n\n if (subtype === 'tool' || actionName === 'generate') {\n const path = (attributes['genkit:path'] as string) || '<unknown>';\n const input = truncate(attributes['genkit:input'] as string);\n const output = truncate(attributes['genkit:output'] as string);\n const sessionId = attributes['genkit:sessionId'] as string;\n const threadName = attributes['genkit:threadName'] as string;\n let featureName = extractOuterFeatureNameFromPath(path);\n if (!featureName || featureName === '<unknown>') {\n featureName = actionName;\n }\n\n if (input) {\n this.writeLog(\n span,\n 'Input',\n featureName,\n path,\n input,\n projectId,\n sessionId,\n threadName\n );\n }\n if (output) {\n this.writeLog(\n span,\n 'Output',\n featureName,\n path,\n output,\n projectId,\n sessionId,\n threadName\n );\n }\n }\n }\n\n private writeLog(\n span: ReadableSpan,\n tag: string,\n featureName: string,\n qualifiedPath: string,\n content: string,\n projectId?: string,\n sessionId?: string,\n threadName?: string\n ) {\n const path = truncatePath(toDisplayPath(qualifiedPath));\n const sharedMetadata = {\n ...createCommonLogAttributes(span, projectId),\n path,\n qualifiedPath,\n featureName,\n sessionId,\n threadName,\n };\n logger.logStructured(`${tag}[${path}, ${featureName}]`, {\n ...sharedMetadata,\n content,\n });\n }\n}\n\nconst actionTelemetry = new ActionTelemetry();\nexport { actionTelemetry };\n"],"mappings":"AAiBA,SAAS,cAAc;AACvB,SAAS,qBAAqB;AAE9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,gBAAqC;AAAA,EACzC,KACE,MACA,mBACA,WACM;AACN,QAAI,CAAC,mBAAmB;AACtB;AAAA,IACF;AACA,UAAM,aAAa,KAAK;AACxB,UAAM,aAAc,WAAW,aAAa,KAAgB;AAC5D,UAAM,UAAU,WAAW,yBAAyB;AAEpD,QAAI,YAAY,UAAU,eAAe,YAAY;AACnD,YAAM,OAAQ,WAAW,aAAa,KAAgB;AACtD,YAAM,QAAQ,SAAS,WAAW,cAAc,CAAW;AAC3D,YAAM,SAAS,SAAS,WAAW,eAAe,CAAW;AAC7D,YAAM,YAAY,WAAW,kBAAkB;AAC/C,YAAM,aAAa,WAAW,mBAAmB;AACjD,UAAI,cAAc,gCAAgC,IAAI;AACtD,UAAI,CAAC,eAAe,gBAAgB,aAAa;AAC/C,sBAAc;AAAA,MAChB;AAEA,UAAI,OAAO;AACT,aAAK;AAAA,UACH;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AACA,UAAI,QAAQ;AACV,aAAK;AAAA,UACH;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,SACN,MACA,KACA,aACA,eACA,SACA,WACA,WACA,YACA;AACA,UAAM,OAAO,aAAa,cAAc,aAAa,CAAC;AACtD,UAAM,iBAAiB;AAAA,MACrB,GAAG,0BAA0B,MAAM,SAAS;AAAA,MAC5C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,WAAO,cAAc,GAAG,GAAG,IAAI,IAAI,KAAK,WAAW,KAAK;AAAA,MACtD,GAAG;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEA,MAAM,kBAAkB,IAAI,gBAAgB;","names":[]}
@@ -0,0 +1,30 @@
1
+ import { GcpTelemetryConfigOptions, GcpTelemetryConfig } 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
+ * Copyright 2024 Google LLC
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+
23
+ /** Consolidated defaults for telemetry configuration. */
24
+ declare const TelemetryConfigs: {
25
+ defaults: (overrides?: GcpTelemetryConfigOptions) => GcpTelemetryConfig;
26
+ developmentDefaults: (overrides?: GcpTelemetryConfigOptions) => GcpTelemetryConfig;
27
+ productionDefaults: (overrides?: GcpTelemetryConfigOptions) => GcpTelemetryConfig;
28
+ };
29
+
30
+ export { TelemetryConfigs };
@@ -0,0 +1,30 @@
1
+ import { GcpTelemetryConfigOptions, GcpTelemetryConfig } 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
+ * Copyright 2024 Google LLC
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+
23
+ /** Consolidated defaults for telemetry configuration. */
24
+ declare const TelemetryConfigs: {
25
+ defaults: (overrides?: GcpTelemetryConfigOptions) => GcpTelemetryConfig;
26
+ developmentDefaults: (overrides?: GcpTelemetryConfigOptions) => GcpTelemetryConfig;
27
+ productionDefaults: (overrides?: GcpTelemetryConfigOptions) => GcpTelemetryConfig;
28
+ };
29
+
30
+ export { TelemetryConfigs };
@@ -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 defaults_exports = {};
20
+ __export(defaults_exports, {
21
+ TelemetryConfigs: () => TelemetryConfigs
22
+ });
23
+ module.exports = __toCommonJS(defaults_exports);
24
+ var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
25
+ var import_genkit = require("genkit");
26
+ const TelemetryConfigs = {
27
+ defaults: (overrides = {}) => {
28
+ return (0, import_genkit.isDevEnv)() ? TelemetryConfigs.developmentDefaults(overrides) : TelemetryConfigs.productionDefaults(overrides);
29
+ },
30
+ developmentDefaults: (overrides = {}) => {
31
+ const defaults = {
32
+ sampler: new import_sdk_trace_base.AlwaysOnSampler(),
33
+ autoInstrumentation: true,
34
+ autoInstrumentationConfig: {
35
+ "@opentelemetry/instrumentation-dns": { enabled: false }
36
+ },
37
+ instrumentations: [],
38
+ metricExportIntervalMillis: 5e3,
39
+ metricExportTimeoutMillis: 5e3,
40
+ disableMetrics: false,
41
+ disableTraces: false,
42
+ exportInputAndOutput: !overrides.disableLoggingInputAndOutput,
43
+ export: !!overrides.forceDevExport
44
+ // false
45
+ };
46
+ return { ...defaults, ...overrides };
47
+ },
48
+ productionDefaults: (overrides = {}) => {
49
+ const defaults = {
50
+ sampler: new import_sdk_trace_base.AlwaysOnSampler(),
51
+ autoInstrumentation: true,
52
+ autoInstrumentationConfig: {
53
+ "@opentelemetry/instrumentation-dns": { enabled: false }
54
+ },
55
+ instrumentations: [],
56
+ metricExportIntervalMillis: 3e5,
57
+ metricExportTimeoutMillis: 3e5,
58
+ disableMetrics: false,
59
+ disableTraces: false,
60
+ exportInputAndOutput: !overrides.disableLoggingInputAndOutput,
61
+ export: true
62
+ };
63
+ return { ...defaults, ...overrides };
64
+ }
65
+ };
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ TelemetryConfigs
69
+ });
70
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/telemetry/defaults.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 { AlwaysOnSampler } from '@opentelemetry/sdk-trace-base';\nimport { isDevEnv } from 'genkit';\nimport type {\n GcpTelemetryConfig,\n GcpTelemetryConfigOptions,\n} from '../types.js';\n\n/** Consolidated defaults for telemetry configuration. */\n\nexport const TelemetryConfigs = {\n defaults: (overrides: GcpTelemetryConfigOptions = {}): GcpTelemetryConfig => {\n return isDevEnv()\n ? TelemetryConfigs.developmentDefaults(overrides)\n : TelemetryConfigs.productionDefaults(overrides);\n },\n\n developmentDefaults: (\n overrides: GcpTelemetryConfigOptions = {}\n ): GcpTelemetryConfig => {\n const defaults = {\n sampler: new AlwaysOnSampler(),\n autoInstrumentation: true,\n autoInstrumentationConfig: {\n '@opentelemetry/instrumentation-dns': { enabled: false },\n },\n instrumentations: [],\n metricExportIntervalMillis: 5_000,\n metricExportTimeoutMillis: 5_000,\n disableMetrics: false,\n disableTraces: false,\n exportInputAndOutput: !overrides.disableLoggingInputAndOutput,\n export: !!overrides.forceDevExport, // false\n };\n return { ...defaults, ...overrides };\n },\n\n productionDefaults: (\n overrides: GcpTelemetryConfigOptions = {}\n ): GcpTelemetryConfig => {\n const defaults = {\n sampler: new AlwaysOnSampler(),\n autoInstrumentation: true,\n autoInstrumentationConfig: {\n '@opentelemetry/instrumentation-dns': { enabled: false },\n },\n instrumentations: [],\n metricExportIntervalMillis: 300_000,\n metricExportTimeoutMillis: 300_000,\n disableMetrics: false,\n disableTraces: false,\n exportInputAndOutput: !overrides.disableLoggingInputAndOutput,\n export: true,\n };\n return { ...defaults, ...overrides };\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,4BAAgC;AAChC,oBAAyB;AAQlB,MAAM,mBAAmB;AAAA,EAC9B,UAAU,CAAC,YAAuC,CAAC,MAA0B;AAC3E,eAAO,wBAAS,IACZ,iBAAiB,oBAAoB,SAAS,IAC9C,iBAAiB,mBAAmB,SAAS;AAAA,EACnD;AAAA,EAEA,qBAAqB,CACnB,YAAuC,CAAC,MACjB;AACvB,UAAM,WAAW;AAAA,MACf,SAAS,IAAI,sCAAgB;AAAA,MAC7B,qBAAqB;AAAA,MACrB,2BAA2B;AAAA,QACzB,sCAAsC,EAAE,SAAS,MAAM;AAAA,MACzD;AAAA,MACA,kBAAkB,CAAC;AAAA,MACnB,4BAA4B;AAAA,MAC5B,2BAA2B;AAAA,MAC3B,gBAAgB;AAAA,MAChB,eAAe;AAAA,MACf,sBAAsB,CAAC,UAAU;AAAA,MACjC,QAAQ,CAAC,CAAC,UAAU;AAAA;AAAA,IACtB;AACA,WAAO,EAAE,GAAG,UAAU,GAAG,UAAU;AAAA,EACrC;AAAA,EAEA,oBAAoB,CAClB,YAAuC,CAAC,MACjB;AACvB,UAAM,WAAW;AAAA,MACf,SAAS,IAAI,sCAAgB;AAAA,MAC7B,qBAAqB;AAAA,MACrB,2BAA2B;AAAA,QACzB,sCAAsC,EAAE,SAAS,MAAM;AAAA,MACzD;AAAA,MACA,kBAAkB,CAAC;AAAA,MACnB,4BAA4B;AAAA,MAC5B,2BAA2B;AAAA,MAC3B,gBAAgB;AAAA,MAChB,eAAe;AAAA,MACf,sBAAsB,CAAC,UAAU;AAAA,MACjC,QAAQ;AAAA,IACV;AACA,WAAO,EAAE,GAAG,UAAU,GAAG,UAAU;AAAA,EACrC;AACF;","names":[]}
@@ -0,0 +1,46 @@
1
+ import { AlwaysOnSampler } from "@opentelemetry/sdk-trace-base";
2
+ import { isDevEnv } from "genkit";
3
+ const TelemetryConfigs = {
4
+ defaults: (overrides = {}) => {
5
+ return isDevEnv() ? TelemetryConfigs.developmentDefaults(overrides) : TelemetryConfigs.productionDefaults(overrides);
6
+ },
7
+ developmentDefaults: (overrides = {}) => {
8
+ const defaults = {
9
+ sampler: new AlwaysOnSampler(),
10
+ autoInstrumentation: true,
11
+ autoInstrumentationConfig: {
12
+ "@opentelemetry/instrumentation-dns": { enabled: false }
13
+ },
14
+ instrumentations: [],
15
+ metricExportIntervalMillis: 5e3,
16
+ metricExportTimeoutMillis: 5e3,
17
+ disableMetrics: false,
18
+ disableTraces: false,
19
+ exportInputAndOutput: !overrides.disableLoggingInputAndOutput,
20
+ export: !!overrides.forceDevExport
21
+ // false
22
+ };
23
+ return { ...defaults, ...overrides };
24
+ },
25
+ productionDefaults: (overrides = {}) => {
26
+ const defaults = {
27
+ sampler: new AlwaysOnSampler(),
28
+ autoInstrumentation: true,
29
+ autoInstrumentationConfig: {
30
+ "@opentelemetry/instrumentation-dns": { enabled: false }
31
+ },
32
+ instrumentations: [],
33
+ metricExportIntervalMillis: 3e5,
34
+ metricExportTimeoutMillis: 3e5,
35
+ disableMetrics: false,
36
+ disableTraces: false,
37
+ exportInputAndOutput: !overrides.disableLoggingInputAndOutput,
38
+ export: true
39
+ };
40
+ return { ...defaults, ...overrides };
41
+ }
42
+ };
43
+ export {
44
+ TelemetryConfigs
45
+ };
46
+ //# sourceMappingURL=defaults.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/telemetry/defaults.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 { AlwaysOnSampler } from '@opentelemetry/sdk-trace-base';\nimport { isDevEnv } from 'genkit';\nimport type {\n GcpTelemetryConfig,\n GcpTelemetryConfigOptions,\n} from '../types.js';\n\n/** Consolidated defaults for telemetry configuration. */\n\nexport const TelemetryConfigs = {\n defaults: (overrides: GcpTelemetryConfigOptions = {}): GcpTelemetryConfig => {\n return isDevEnv()\n ? TelemetryConfigs.developmentDefaults(overrides)\n : TelemetryConfigs.productionDefaults(overrides);\n },\n\n developmentDefaults: (\n overrides: GcpTelemetryConfigOptions = {}\n ): GcpTelemetryConfig => {\n const defaults = {\n sampler: new AlwaysOnSampler(),\n autoInstrumentation: true,\n autoInstrumentationConfig: {\n '@opentelemetry/instrumentation-dns': { enabled: false },\n },\n instrumentations: [],\n metricExportIntervalMillis: 5_000,\n metricExportTimeoutMillis: 5_000,\n disableMetrics: false,\n disableTraces: false,\n exportInputAndOutput: !overrides.disableLoggingInputAndOutput,\n export: !!overrides.forceDevExport, // false\n };\n return { ...defaults, ...overrides };\n },\n\n productionDefaults: (\n overrides: GcpTelemetryConfigOptions = {}\n ): GcpTelemetryConfig => {\n const defaults = {\n sampler: new AlwaysOnSampler(),\n autoInstrumentation: true,\n autoInstrumentationConfig: {\n '@opentelemetry/instrumentation-dns': { enabled: false },\n },\n instrumentations: [],\n metricExportIntervalMillis: 300_000,\n metricExportTimeoutMillis: 300_000,\n disableMetrics: false,\n disableTraces: false,\n exportInputAndOutput: !overrides.disableLoggingInputAndOutput,\n export: true,\n };\n return { ...defaults, ...overrides };\n },\n};\n"],"mappings":"AAgBA,SAAS,uBAAuB;AAChC,SAAS,gBAAgB;AAQlB,MAAM,mBAAmB;AAAA,EAC9B,UAAU,CAAC,YAAuC,CAAC,MAA0B;AAC3E,WAAO,SAAS,IACZ,iBAAiB,oBAAoB,SAAS,IAC9C,iBAAiB,mBAAmB,SAAS;AAAA,EACnD;AAAA,EAEA,qBAAqB,CACnB,YAAuC,CAAC,MACjB;AACvB,UAAM,WAAW;AAAA,MACf,SAAS,IAAI,gBAAgB;AAAA,MAC7B,qBAAqB;AAAA,MACrB,2BAA2B;AAAA,QACzB,sCAAsC,EAAE,SAAS,MAAM;AAAA,MACzD;AAAA,MACA,kBAAkB,CAAC;AAAA,MACnB,4BAA4B;AAAA,MAC5B,2BAA2B;AAAA,MAC3B,gBAAgB;AAAA,MAChB,eAAe;AAAA,MACf,sBAAsB,CAAC,UAAU;AAAA,MACjC,QAAQ,CAAC,CAAC,UAAU;AAAA;AAAA,IACtB;AACA,WAAO,EAAE,GAAG,UAAU,GAAG,UAAU;AAAA,EACrC;AAAA,EAEA,oBAAoB,CAClB,YAAuC,CAAC,MACjB;AACvB,UAAM,WAAW;AAAA,MACf,SAAS,IAAI,gBAAgB;AAAA,MAC7B,qBAAqB;AAAA,MACrB,2BAA2B;AAAA,QACzB,sCAAsC,EAAE,SAAS,MAAM;AAAA,MACzD;AAAA,MACA,kBAAkB,CAAC;AAAA,MACnB,4BAA4B;AAAA,MAC5B,2BAA2B;AAAA,MAC3B,gBAAgB;AAAA,MAChB,eAAe;AAAA,MACf,sBAAsB,CAAC,UAAU;AAAA,MACjC,QAAQ;AAAA,IACV;AACA,WAAO,EAAE,GAAG,UAAU,GAAG,UAAU;AAAA,EACrC;AACF;","names":[]}