genkit-plugin-google-cloud 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
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.
- genkit/plugins/google_cloud/__init__.py +127 -2
- genkit/plugins/google_cloud/telemetry/__init__.py +74 -0
- genkit/plugins/google_cloud/telemetry/action.py +124 -0
- genkit/plugins/google_cloud/telemetry/engagement.py +170 -0
- genkit/plugins/google_cloud/telemetry/feature.py +186 -0
- genkit/plugins/google_cloud/telemetry/generate.py +605 -0
- genkit/plugins/google_cloud/telemetry/metrics.py +246 -0
- genkit/plugins/google_cloud/telemetry/path.py +157 -0
- genkit/plugins/google_cloud/telemetry/tracing.py +880 -29
- genkit/plugins/google_cloud/telemetry/utils.py +217 -0
- {genkit_plugin_google_cloud-0.4.0.dist-info → genkit_plugin_google_cloud-0.5.0.dist-info}/METADATA +10 -2
- genkit_plugin_google_cloud-0.5.0.dist-info/RECORD +15 -0
- {genkit_plugin_google_cloud-0.4.0.dist-info → genkit_plugin_google_cloud-0.5.0.dist-info}/WHEEL +1 -1
- genkit_plugin_google_cloud-0.4.0.dist-info/RECORD +0 -9
- /genkit/{py.typed → plugins/google_cloud/py.typed} +0 -0
- {genkit_plugin_google_cloud-0.4.0.dist-info → genkit_plugin_google_cloud-0.5.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
#
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
"""Utility functions for GCP telemetry.
|
|
18
|
+
|
|
19
|
+
This module provides utility functions used by the telemetry handlers,
|
|
20
|
+
matching the JavaScript implementation in js/plugins/google-cloud/src/utils.ts.
|
|
21
|
+
|
|
22
|
+
Functions:
|
|
23
|
+
- truncate(): Limit string length for log content
|
|
24
|
+
- truncate_path(): Limit Genkit path string length
|
|
25
|
+
- to_display_path(): Convert internal path to display format
|
|
26
|
+
- extract_outer_feature_name_from_path(): Get root feature from path
|
|
27
|
+
- create_common_log_attributes(): Build log attributes dict
|
|
28
|
+
- extract_error_*(): Error info extraction helpers
|
|
29
|
+
|
|
30
|
+
See Also:
|
|
31
|
+
- Cloud Logging Limits: https://cloud.google.com/logging/quotas
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import annotations
|
|
35
|
+
|
|
36
|
+
import re
|
|
37
|
+
from typing import Any
|
|
38
|
+
|
|
39
|
+
from opentelemetry.sdk.trace import ReadableSpan
|
|
40
|
+
from opentelemetry.trace import TraceFlags
|
|
41
|
+
|
|
42
|
+
# Constants matching JS implementation
|
|
43
|
+
MAX_LOG_CONTENT_CHARS = 128_000
|
|
44
|
+
MAX_PATH_CHARS = 4096
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def truncate(text: str | None, limit: int = MAX_LOG_CONTENT_CHARS) -> str:
|
|
48
|
+
"""Truncate text to a maximum length.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
text: The text to truncate.
|
|
52
|
+
limit: Maximum length (default: 128,000 chars).
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
The truncated text or empty string if None.
|
|
56
|
+
"""
|
|
57
|
+
if not text:
|
|
58
|
+
return ''
|
|
59
|
+
return text[:limit]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def truncate_path(path: str) -> str:
|
|
63
|
+
"""Truncate a path to the maximum path length.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
path: The path to truncate.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
The truncated path.
|
|
70
|
+
"""
|
|
71
|
+
return truncate(path, MAX_PATH_CHARS)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def extract_outer_flow_name_from_path(path: str) -> str:
|
|
75
|
+
"""Extract the outer flow name from a Genkit path.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
path: The Genkit path (e.g., '/{myFlow,t:flow}').
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
The flow name or '<unknown>'.
|
|
82
|
+
"""
|
|
83
|
+
if not path or path == '<unknown>':
|
|
84
|
+
return '<unknown>'
|
|
85
|
+
|
|
86
|
+
match = re.search(r'/{(.+),t:flow}', path)
|
|
87
|
+
return match.group(1) if match else '<unknown>'
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def extract_outer_feature_name_from_path(path: str) -> str:
|
|
91
|
+
"""Extract the outer feature name from a Genkit path.
|
|
92
|
+
|
|
93
|
+
Extracts the first feature name from paths like:
|
|
94
|
+
'/{myFlow,t:flow}/{myStep,t:flowStep}/{googleai/gemini-pro,t:action,s:model}'
|
|
95
|
+
Returns 'myFlow'.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
path: The Genkit path.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
The feature name or '<unknown>'.
|
|
102
|
+
"""
|
|
103
|
+
if not path or path == '<unknown>':
|
|
104
|
+
return '<unknown>'
|
|
105
|
+
|
|
106
|
+
parts = path.split('/')
|
|
107
|
+
if len(parts) < 2:
|
|
108
|
+
return '<unknown>'
|
|
109
|
+
|
|
110
|
+
first = parts[1]
|
|
111
|
+
match = re.match(r'\{(.+),t:(flow|action|prompt|dotprompt|helper)', first)
|
|
112
|
+
return match.group(1) if match else '<unknown>'
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def extract_error_name(events: list[Any]) -> str | None:
|
|
116
|
+
"""Extract the error name from span events.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
events: List of span events.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
The error type name or None.
|
|
123
|
+
"""
|
|
124
|
+
for event in events:
|
|
125
|
+
if event.name == 'exception':
|
|
126
|
+
attrs = event.attributes or {}
|
|
127
|
+
error_type = attrs.get('exception.type')
|
|
128
|
+
if error_type:
|
|
129
|
+
return truncate(str(error_type), 1024)
|
|
130
|
+
return None
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def extract_error_message(events: list[Any]) -> str | None:
|
|
134
|
+
"""Extract the error message from span events.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
events: List of span events.
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
The error message or None.
|
|
141
|
+
"""
|
|
142
|
+
for event in events:
|
|
143
|
+
if event.name == 'exception':
|
|
144
|
+
attrs = event.attributes or {}
|
|
145
|
+
error_msg = attrs.get('exception.message')
|
|
146
|
+
if error_msg:
|
|
147
|
+
return truncate(str(error_msg), 4096)
|
|
148
|
+
return None
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def extract_error_stack(events: list[Any]) -> str | None:
|
|
152
|
+
"""Extract the error stack trace from span events.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
events: List of span events.
|
|
156
|
+
|
|
157
|
+
Returns:
|
|
158
|
+
The stack trace or None.
|
|
159
|
+
"""
|
|
160
|
+
for event in events:
|
|
161
|
+
if event.name == 'exception':
|
|
162
|
+
attrs = event.attributes or {}
|
|
163
|
+
stack = attrs.get('exception.stacktrace')
|
|
164
|
+
if stack:
|
|
165
|
+
return truncate(str(stack), 32_768)
|
|
166
|
+
return None
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def create_common_log_attributes(span: ReadableSpan, project_id: str | None = None) -> dict[str, Any]:
|
|
170
|
+
"""Create common log attributes for GCP structured logging.
|
|
171
|
+
|
|
172
|
+
These attributes link logs to traces in Google Cloud.
|
|
173
|
+
|
|
174
|
+
Args:
|
|
175
|
+
span: The span to extract context from.
|
|
176
|
+
project_id: Optional GCP project ID.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
Dictionary with logging.googleapis.com attributes.
|
|
180
|
+
"""
|
|
181
|
+
span_context = span.context
|
|
182
|
+
if span_context is None:
|
|
183
|
+
return {}
|
|
184
|
+
is_sampled = bool(span_context.trace_flags & TraceFlags.SAMPLED)
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
'logging.googleapis.com/spanId': format(span_context.span_id, '016x'),
|
|
188
|
+
'logging.googleapis.com/trace': f'projects/{project_id}/traces/{format(span_context.trace_id, "032x")}',
|
|
189
|
+
'logging.googleapis.com/trace_sampled': '1' if is_sampled else '0',
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def to_display_path(qualified_path: str) -> str:
|
|
194
|
+
"""Convert a qualified Genkit path to a display path.
|
|
195
|
+
|
|
196
|
+
Simplifies paths like '/{myFlow,t:flow}/{step,t:flowStep}' to 'myFlow/step'.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
qualified_path: The full Genkit path.
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
A simplified display path.
|
|
203
|
+
"""
|
|
204
|
+
if not qualified_path:
|
|
205
|
+
return ''
|
|
206
|
+
|
|
207
|
+
# Extract names from path segments like '{name,t:type}'
|
|
208
|
+
parts = []
|
|
209
|
+
for segment in qualified_path.split('/'):
|
|
210
|
+
if segment.startswith('{'):
|
|
211
|
+
match = re.match(r'\{([^,}]+)', segment)
|
|
212
|
+
if match:
|
|
213
|
+
parts.append(match.group(1))
|
|
214
|
+
elif segment:
|
|
215
|
+
parts.append(segment)
|
|
216
|
+
|
|
217
|
+
return '/'.join(parts)
|
{genkit_plugin_google_cloud-0.4.0.dist-info → genkit_plugin_google_cloud-0.5.0.dist-info}/METADATA
RENAMED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: genkit-plugin-google-cloud
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Genkit Google Cloud Plugin
|
|
5
|
+
Project-URL: Bug Tracker, https://github.com/firebase/genkit/issues
|
|
6
|
+
Project-URL: Documentation, https://firebase.google.com/docs/genkit
|
|
7
|
+
Project-URL: Homepage, https://github.com/firebase/genkit
|
|
8
|
+
Project-URL: Repository, https://github.com/firebase/genkit/tree/main/py
|
|
5
9
|
Author: Google
|
|
6
|
-
License: Apache-2.0
|
|
10
|
+
License-Expression: Apache-2.0
|
|
7
11
|
License-File: LICENSE
|
|
12
|
+
Keywords: ai,artificial-intelligence,cloud-trace,gcp,generative-ai,genkit,google-cloud,llm,machine-learning,telemetry
|
|
8
13
|
Classifier: Development Status :: 3 - Alpha
|
|
9
14
|
Classifier: Environment :: Console
|
|
10
15
|
Classifier: Environment :: Web Environment
|
|
@@ -17,10 +22,13 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
17
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
19
24
|
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
26
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
27
|
Classifier: Topic :: Software Development :: Libraries
|
|
28
|
+
Classifier: Typing :: Typed
|
|
22
29
|
Requires-Python: >=3.10
|
|
23
30
|
Requires-Dist: genkit
|
|
31
|
+
Requires-Dist: opentelemetry-exporter-gcp-monitoring>=1.9.0
|
|
24
32
|
Requires-Dist: opentelemetry-exporter-gcp-trace>=1.9.0
|
|
25
33
|
Requires-Dist: strenum>=0.4.15; python_version < '3.11'
|
|
26
34
|
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
genkit/plugins/google_cloud/__init__.py,sha256=xGtaLGbJN3h3_M7j-puTVhBBt5tKwQNa_TzuZ35gYbU,13097
|
|
2
|
+
genkit/plugins/google_cloud/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
genkit/plugins/google_cloud/telemetry/__init__.py,sha256=fHABRo0Wttj-1SxJyT0dESw7xo-42lop45OZQZsgrIA,3478
|
|
4
|
+
genkit/plugins/google_cloud/telemetry/action.py,sha256=CTkw2wNPPHZ3Yx1IHqMbC5J1kHINqx3J3hKgI7XqAeM,4033
|
|
5
|
+
genkit/plugins/google_cloud/telemetry/engagement.py,sha256=XUj3px7mpEWTYuaGP6LW63KbFVBVFiyIsFf6aG7BIoQ,5626
|
|
6
|
+
genkit/plugins/google_cloud/telemetry/feature.py,sha256=M-ChpbFXaVrqj1NhpY8JrtPoJ3WtY2LxBVQv1RoDhTA,6126
|
|
7
|
+
genkit/plugins/google_cloud/telemetry/generate.py,sha256=2Jihlip8zI2cTjJPvg02ddguQREYHjiYWSazSeEL7aQ,22800
|
|
8
|
+
genkit/plugins/google_cloud/telemetry/metrics.py,sha256=b-WLbSDJ5kVpklcUVjmaA4roLui7FYn-jYViNpn144w,7554
|
|
9
|
+
genkit/plugins/google_cloud/telemetry/path.py,sha256=pqR_imoFVqYa7d_l1kWCLrZkSXa8hDk5lmqUdDahwmE,5017
|
|
10
|
+
genkit/plugins/google_cloud/telemetry/tracing.py,sha256=8fR1HB_qrbdLGNlDHTgGbzs6v6nV5pJfRcjwWDiTeJ0,44002
|
|
11
|
+
genkit/plugins/google_cloud/telemetry/utils.py,sha256=z3q2czj_q4-la57KNAJG6PsoHpHwKEfcRrU_zay_hdw,6176
|
|
12
|
+
genkit_plugin_google_cloud-0.5.0.dist-info/METADATA,sha256=_9pJFm5TMXOoWE5WDVTxNoWr_0VZd1-8q_OWhMUsvW0,1712
|
|
13
|
+
genkit_plugin_google_cloud-0.5.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
14
|
+
genkit_plugin_google_cloud-0.5.0.dist-info/licenses/LICENSE,sha256=bsvE5_qSn_2LH2G-haMvT_AoIeINhX6fvzZTlyq2xJY,11340
|
|
15
|
+
genkit_plugin_google_cloud-0.5.0.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
genkit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
genkit/plugins/google_cloud/__init__.py,sha256=hslI9NDSXVZ2VpUblsGa1QBYPTQd0hVXF2sPfpSIpdk,886
|
|
3
|
-
genkit/plugins/google_cloud/telemetry/tracing.py,sha256=we3m0a7mVK58swN6hE_JNNjLPZdh5ykPBp_Dynr7fMU,4046
|
|
4
|
-
genkit/plugins/google_cloud/__init__.py,sha256=hslI9NDSXVZ2VpUblsGa1QBYPTQd0hVXF2sPfpSIpdk,886
|
|
5
|
-
genkit/plugins/google_cloud/telemetry/tracing.py,sha256=we3m0a7mVK58swN6hE_JNNjLPZdh5ykPBp_Dynr7fMU,4046
|
|
6
|
-
genkit_plugin_google_cloud-0.4.0.dist-info/METADATA,sha256=vPPyeS175AFtU2KliCwTf9GsQKWONLFklboNv-AEhCk,1177
|
|
7
|
-
genkit_plugin_google_cloud-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
-
genkit_plugin_google_cloud-0.4.0.dist-info/licenses/LICENSE,sha256=bsvE5_qSn_2LH2G-haMvT_AoIeINhX6fvzZTlyq2xJY,11340
|
|
9
|
-
genkit_plugin_google_cloud-0.4.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|