agent-starter-pack 0.18.2__py3-none-any.whl → 0.21.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.
- agent_starter_pack/agents/{langgraph_base_react → adk_a2a_base}/.template/templateconfig.yaml +5 -12
- agent_starter_pack/agents/adk_a2a_base/README.md +37 -0
- agent_starter_pack/{frontends/streamlit/frontend/style/app_markdown.py → agents/adk_a2a_base/app/__init__.py} +3 -23
- agent_starter_pack/agents/adk_a2a_base/app/agent.py +70 -0
- agent_starter_pack/agents/adk_a2a_base/notebooks/adk_a2a_app_testing.ipynb +583 -0
- agent_starter_pack/agents/{crewai_coding_crew/notebooks/evaluating_crewai_agent.ipynb → adk_a2a_base/notebooks/evaluating_adk_agent.ipynb} +163 -199
- agent_starter_pack/agents/adk_a2a_base/tests/integration/test_agent.py +58 -0
- agent_starter_pack/agents/adk_base/app/__init__.py +2 -2
- agent_starter_pack/agents/adk_base/app/agent.py +3 -0
- agent_starter_pack/agents/adk_base/notebooks/adk_app_testing.ipynb +13 -28
- agent_starter_pack/agents/adk_live/app/__init__.py +17 -0
- agent_starter_pack/agents/adk_live/app/agent.py +3 -0
- agent_starter_pack/agents/agentic_rag/app/__init__.py +2 -2
- agent_starter_pack/agents/agentic_rag/app/agent.py +3 -0
- agent_starter_pack/agents/agentic_rag/notebooks/adk_app_testing.ipynb +13 -28
- agent_starter_pack/agents/{crewai_coding_crew → langgraph_base}/.template/templateconfig.yaml +12 -9
- agent_starter_pack/agents/langgraph_base/README.md +30 -0
- agent_starter_pack/agents/langgraph_base/app/__init__.py +17 -0
- agent_starter_pack/agents/{langgraph_base_react → langgraph_base}/app/agent.py +4 -4
- agent_starter_pack/agents/{langgraph_base_react → langgraph_base}/tests/integration/test_agent.py +1 -1
- agent_starter_pack/base_template/.gitignore +4 -2
- agent_starter_pack/base_template/Makefile +110 -16
- agent_starter_pack/base_template/README.md +97 -12
- agent_starter_pack/base_template/deployment/terraform/dev/apis.tf +4 -6
- agent_starter_pack/base_template/deployment/terraform/dev/providers.tf +5 -1
- agent_starter_pack/base_template/deployment/terraform/dev/variables.tf +5 -3
- agent_starter_pack/base_template/deployment/terraform/dev/{% if cookiecutter.is_adk %}telemetry.tf{% else %}unused_telemetry.tf{% endif %} +193 -0
- agent_starter_pack/base_template/deployment/terraform/github.tf +16 -9
- agent_starter_pack/base_template/deployment/terraform/locals.tf +7 -7
- agent_starter_pack/base_template/deployment/terraform/providers.tf +5 -1
- agent_starter_pack/base_template/deployment/terraform/sql/completions.sql +138 -0
- agent_starter_pack/base_template/deployment/terraform/storage.tf +0 -9
- agent_starter_pack/base_template/deployment/terraform/variables.tf +15 -19
- agent_starter_pack/base_template/deployment/terraform/{% if cookiecutter.cicd_runner == 'google_cloud_build' %}build_triggers.tf{% else %}unused_build_triggers.tf{% endif %} +20 -22
- agent_starter_pack/base_template/deployment/terraform/{% if cookiecutter.is_adk %}telemetry.tf{% else %}unused_telemetry.tf{% endif %} +206 -0
- agent_starter_pack/base_template/pyproject.toml +5 -17
- agent_starter_pack/base_template/{% if cookiecutter.cicd_runner == 'github_actions' %}.github{% else %}unused_github{% endif %}/workflows/deploy-to-prod.yaml +19 -4
- agent_starter_pack/base_template/{% if cookiecutter.cicd_runner == 'github_actions' %}.github{% else %}unused_github{% endif %}/workflows/staging.yaml +36 -11
- agent_starter_pack/base_template/{% if cookiecutter.cicd_runner == 'google_cloud_build' %}.cloudbuild{% else %}unused_.cloudbuild{% endif %}/deploy-to-prod.yaml +24 -5
- agent_starter_pack/base_template/{% if cookiecutter.cicd_runner == 'google_cloud_build' %}.cloudbuild{% else %}unused_.cloudbuild{% endif %}/staging.yaml +44 -9
- agent_starter_pack/base_template/{{cookiecutter.agent_directory}}/app_utils/telemetry.py +96 -0
- agent_starter_pack/base_template/{{cookiecutter.agent_directory}}/{utils → app_utils}/typing.py +4 -6
- agent_starter_pack/{agents/crewai_coding_crew/app/crew/config/agents.yaml → base_template/{{cookiecutter.agent_directory}}/app_utils/{% if cookiecutter.is_a2a and cookiecutter.agent_name == 'langgraph_base' %}converters{% else %}unused_converters{% endif %}/__init__.py } +9 -23
- agent_starter_pack/base_template/{{cookiecutter.agent_directory}}/app_utils/{% if cookiecutter.is_a2a and cookiecutter.agent_name == 'langgraph_base' %}converters{% else %}unused_converters{% endif %}/part_converter.py +138 -0
- agent_starter_pack/base_template/{{cookiecutter.agent_directory}}/app_utils/{% if cookiecutter.is_a2a and cookiecutter.agent_name == 'langgraph_base' %}executor{% else %}unused_executor{% endif %}/__init__.py +13 -0
- agent_starter_pack/base_template/{{cookiecutter.agent_directory}}/app_utils/{% if cookiecutter.is_a2a and cookiecutter.agent_name == 'langgraph_base' %}executor{% else %}unused_executor{% endif %}/a2a_agent_executor.py +265 -0
- agent_starter_pack/base_template/{{cookiecutter.agent_directory}}/app_utils/{% if cookiecutter.is_a2a and cookiecutter.agent_name == 'langgraph_base' %}executor{% else %}unused_executor{% endif %}/task_result_aggregator.py +152 -0
- agent_starter_pack/cli/commands/create.py +40 -4
- agent_starter_pack/cli/commands/enhance.py +1 -1
- agent_starter_pack/cli/commands/register_gemini_enterprise.py +1070 -0
- agent_starter_pack/cli/main.py +2 -0
- agent_starter_pack/cli/utils/cicd.py +20 -4
- agent_starter_pack/cli/utils/template.py +257 -25
- agent_starter_pack/deployment_targets/agent_engine/tests/integration/test_agent_engine_app.py +113 -16
- agent_starter_pack/deployment_targets/agent_engine/tests/load_test/README.md +2 -2
- agent_starter_pack/deployment_targets/agent_engine/tests/load_test/load_test.py +178 -9
- agent_starter_pack/deployment_targets/agent_engine/tests/{% if cookiecutter.is_a2a %}helpers.py{% else %}unused_helpers.py{% endif %} +138 -0
- agent_starter_pack/deployment_targets/agent_engine/{{cookiecutter.agent_directory}}/agent_engine_app.py +193 -307
- agent_starter_pack/deployment_targets/agent_engine/{{cookiecutter.agent_directory}}/app_utils/deploy.py +414 -0
- agent_starter_pack/deployment_targets/agent_engine/{{cookiecutter.agent_directory}}/{utils → app_utils}/{% if cookiecutter.is_adk_live %}expose_app.py{% else %}unused_expose_app.py{% endif %} +13 -14
- agent_starter_pack/deployment_targets/cloud_run/Dockerfile +4 -1
- agent_starter_pack/deployment_targets/cloud_run/deployment/terraform/dev/service.tf +85 -86
- agent_starter_pack/deployment_targets/cloud_run/deployment/terraform/service.tf +139 -107
- agent_starter_pack/deployment_targets/cloud_run/tests/integration/test_server_e2e.py +228 -12
- agent_starter_pack/deployment_targets/cloud_run/tests/load_test/README.md +4 -4
- agent_starter_pack/deployment_targets/cloud_run/tests/load_test/load_test.py +92 -12
- agent_starter_pack/deployment_targets/cloud_run/{{cookiecutter.agent_directory}}/{server.py → fast_api_app.py} +194 -121
- agent_starter_pack/frontends/adk_live_react/frontend/package-lock.json +18 -18
- agent_starter_pack/frontends/adk_live_react/frontend/src/multimodal-live-types.ts +5 -3
- agent_starter_pack/resources/docs/adk-cheatsheet.md +198 -41
- agent_starter_pack/resources/locks/uv-adk_a2a_base-agent_engine.lock +4966 -0
- agent_starter_pack/resources/locks/uv-adk_a2a_base-cloud_run.lock +5011 -0
- agent_starter_pack/resources/locks/uv-adk_base-agent_engine.lock +1443 -709
- agent_starter_pack/resources/locks/uv-adk_base-cloud_run.lock +1058 -874
- agent_starter_pack/resources/locks/uv-adk_live-agent_engine.lock +1443 -709
- agent_starter_pack/resources/locks/uv-adk_live-cloud_run.lock +1058 -874
- agent_starter_pack/resources/locks/uv-agentic_rag-agent_engine.lock +1568 -749
- agent_starter_pack/resources/locks/uv-agentic_rag-cloud_run.lock +1123 -929
- agent_starter_pack/resources/locks/{uv-langgraph_base_react-agent_engine.lock → uv-langgraph_base-agent_engine.lock} +1714 -1689
- agent_starter_pack/resources/locks/{uv-langgraph_base_react-cloud_run.lock → uv-langgraph_base-cloud_run.lock} +1285 -2374
- agent_starter_pack/utils/watch_and_rebuild.py +1 -1
- {agent_starter_pack-0.18.2.dist-info → agent_starter_pack-0.21.0.dist-info}/METADATA +3 -6
- {agent_starter_pack-0.18.2.dist-info → agent_starter_pack-0.21.0.dist-info}/RECORD +89 -93
- agent_starter_pack-0.21.0.dist-info/entry_points.txt +2 -0
- llm.txt +4 -5
- agent_starter_pack/agents/crewai_coding_crew/README.md +0 -34
- agent_starter_pack/agents/crewai_coding_crew/app/agent.py +0 -47
- agent_starter_pack/agents/crewai_coding_crew/app/crew/config/tasks.yaml +0 -37
- agent_starter_pack/agents/crewai_coding_crew/app/crew/crew.py +0 -71
- agent_starter_pack/agents/crewai_coding_crew/tests/integration/test_agent.py +0 -47
- agent_starter_pack/agents/langgraph_base_react/README.md +0 -9
- agent_starter_pack/agents/langgraph_base_react/notebooks/evaluating_langgraph_agent.ipynb +0 -1574
- agent_starter_pack/base_template/deployment/terraform/dev/log_sinks.tf +0 -69
- agent_starter_pack/base_template/deployment/terraform/log_sinks.tf +0 -79
- agent_starter_pack/base_template/{{cookiecutter.agent_directory}}/utils/tracing.py +0 -155
- agent_starter_pack/cli/utils/register_gemini_enterprise.py +0 -406
- agent_starter_pack/deployment_targets/agent_engine/deployment/terraform/{% if not cookiecutter.is_adk_live %}service.tf{% else %}unused_service.tf{% endif %} +0 -82
- agent_starter_pack/deployment_targets/agent_engine/notebooks/intro_agent_engine.ipynb +0 -1025
- agent_starter_pack/deployment_targets/agent_engine/{{cookiecutter.agent_directory}}/utils/deployment.py +0 -99
- agent_starter_pack/frontends/streamlit/frontend/side_bar.py +0 -214
- agent_starter_pack/frontends/streamlit/frontend/streamlit_app.py +0 -265
- agent_starter_pack/frontends/streamlit/frontend/utils/chat_utils.py +0 -67
- agent_starter_pack/frontends/streamlit/frontend/utils/local_chat_history.py +0 -127
- agent_starter_pack/frontends/streamlit/frontend/utils/message_editing.py +0 -59
- agent_starter_pack/frontends/streamlit/frontend/utils/multimodal_utils.py +0 -217
- agent_starter_pack/frontends/streamlit/frontend/utils/stream_handler.py +0 -310
- agent_starter_pack/frontends/streamlit/frontend/utils/title_summary.py +0 -94
- agent_starter_pack/resources/locks/uv-crewai_coding_crew-agent_engine.lock +0 -6650
- agent_starter_pack/resources/locks/uv-crewai_coding_crew-cloud_run.lock +0 -7825
- agent_starter_pack-0.18.2.dist-info/entry_points.txt +0 -3
- /agent_starter_pack/agents/{crewai_coding_crew → langgraph_base}/notebooks/evaluating_langgraph_agent.ipynb +0 -0
- /agent_starter_pack/base_template/{{cookiecutter.agent_directory}}/{utils → app_utils}/gcs.py +0 -0
- {agent_starter_pack-0.18.2.dist-info → agent_starter_pack-0.21.0.dist-info}/WHEEL +0 -0
- {agent_starter_pack-0.18.2.dist-info → agent_starter_pack-0.21.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,69 +0,0 @@
|
|
|
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
|
-
resource "google_bigquery_dataset" "feedback_dataset" {
|
|
16
|
-
project = var.dev_project_id
|
|
17
|
-
dataset_id = replace("${var.project_name}_feedback", "-", "_")
|
|
18
|
-
friendly_name = "${var.project_name}_feedback"
|
|
19
|
-
location = var.region
|
|
20
|
-
depends_on = [resource.google_project_service.services]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
resource "google_bigquery_dataset" "telemetry_logs_dataset" {
|
|
24
|
-
project = var.dev_project_id
|
|
25
|
-
dataset_id = replace("${var.project_name}_telemetry", "-", "_")
|
|
26
|
-
friendly_name = "${var.project_name}_telemetry"
|
|
27
|
-
location = var.region
|
|
28
|
-
depends_on = [resource.google_project_service.services]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
resource "google_logging_project_sink" "feedback_export_to_bigquery" {
|
|
32
|
-
name = "${var.project_name}_feedback"
|
|
33
|
-
project = var.dev_project_id
|
|
34
|
-
destination = "bigquery.googleapis.com/projects/${var.dev_project_id}/datasets/${google_bigquery_dataset.feedback_dataset.dataset_id}"
|
|
35
|
-
filter = var.feedback_logs_filter
|
|
36
|
-
|
|
37
|
-
bigquery_options {
|
|
38
|
-
use_partitioned_tables = true
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
unique_writer_identity = true
|
|
42
|
-
depends_on = [google_bigquery_dataset.feedback_dataset]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
resource "google_logging_project_sink" "log_export_to_bigquery" {
|
|
46
|
-
name = "${var.project_name}_telemetry"
|
|
47
|
-
project = var.dev_project_id
|
|
48
|
-
destination = "bigquery.googleapis.com/projects/${var.dev_project_id}/datasets/${google_bigquery_dataset.telemetry_logs_dataset.dataset_id}"
|
|
49
|
-
filter = var.telemetry_logs_filter
|
|
50
|
-
|
|
51
|
-
bigquery_options {
|
|
52
|
-
use_partitioned_tables = true
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
unique_writer_identity = true
|
|
56
|
-
depends_on = [google_bigquery_dataset.telemetry_logs_dataset]
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
resource "google_project_iam_member" "bigquery_data_editor" {
|
|
60
|
-
project = var.dev_project_id
|
|
61
|
-
role = "roles/bigquery.dataEditor"
|
|
62
|
-
member = google_logging_project_sink.log_export_to_bigquery.writer_identity
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
resource "google_project_iam_member" "feedback_bigquery_data_editor" {
|
|
66
|
-
project = var.dev_project_id
|
|
67
|
-
role = "roles/bigquery.dataEditor"
|
|
68
|
-
member = google_logging_project_sink.feedback_export_to_bigquery.writer_identity
|
|
69
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
resource "google_bigquery_dataset" "feedback_dataset" {
|
|
16
|
-
for_each = local.deploy_project_ids
|
|
17
|
-
project = each.value
|
|
18
|
-
dataset_id = replace("${var.project_name}_feedback", "-", "_")
|
|
19
|
-
friendly_name = "${var.project_name}_feedback"
|
|
20
|
-
location = var.region
|
|
21
|
-
depends_on = [resource.google_project_service.cicd_services, resource.google_project_service.deploy_project_services]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
resource "google_bigquery_dataset" "telemetry_logs_dataset" {
|
|
25
|
-
for_each = local.deploy_project_ids
|
|
26
|
-
project = each.value
|
|
27
|
-
dataset_id = replace("${var.project_name}_telemetry", "-", "_")
|
|
28
|
-
friendly_name = "${var.project_name}_telemetry"
|
|
29
|
-
location = var.region
|
|
30
|
-
depends_on = [resource.google_project_service.cicd_services, resource.google_project_service.deploy_project_services]
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
resource "google_logging_project_sink" "feedback_export_to_bigquery" {
|
|
34
|
-
for_each = local.deploy_project_ids
|
|
35
|
-
|
|
36
|
-
name = "${var.project_name}_feedback"
|
|
37
|
-
project = each.value
|
|
38
|
-
destination = "bigquery.googleapis.com/projects/${each.value}/datasets/${google_bigquery_dataset.feedback_dataset[each.key].dataset_id}"
|
|
39
|
-
filter = var.feedback_logs_filter
|
|
40
|
-
|
|
41
|
-
bigquery_options {
|
|
42
|
-
use_partitioned_tables = true
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
unique_writer_identity = true
|
|
46
|
-
depends_on = [google_bigquery_dataset.feedback_dataset]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
resource "google_logging_project_sink" "log_export_to_bigquery" {
|
|
50
|
-
for_each = local.deploy_project_ids
|
|
51
|
-
|
|
52
|
-
name = "${var.project_name}_telemetry"
|
|
53
|
-
project = each.value
|
|
54
|
-
destination = "bigquery.googleapis.com/projects/${each.value}/datasets/${google_bigquery_dataset.telemetry_logs_dataset[each.key].dataset_id}"
|
|
55
|
-
filter = var.telemetry_logs_filter
|
|
56
|
-
|
|
57
|
-
bigquery_options {
|
|
58
|
-
use_partitioned_tables = true
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
unique_writer_identity = true
|
|
62
|
-
depends_on = [google_bigquery_dataset.telemetry_logs_dataset]
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
resource "google_project_iam_member" "bigquery_data_editor" {
|
|
66
|
-
for_each = local.deploy_project_ids
|
|
67
|
-
|
|
68
|
-
project = each.value
|
|
69
|
-
role = "roles/bigquery.dataEditor"
|
|
70
|
-
member = google_logging_project_sink.log_export_to_bigquery[each.key].writer_identity
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
resource "google_project_iam_member" "feedback_bigquery_data_editor" {
|
|
74
|
-
for_each = local.deploy_project_ids
|
|
75
|
-
|
|
76
|
-
project = each.value
|
|
77
|
-
role = "roles/bigquery.dataEditor"
|
|
78
|
-
member = google_logging_project_sink.feedback_export_to_bigquery[each.key].writer_identity
|
|
79
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
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
|
-
import json
|
|
16
|
-
import logging
|
|
17
|
-
from collections.abc import Sequence
|
|
18
|
-
from typing import Any
|
|
19
|
-
|
|
20
|
-
import google.cloud.storage as storage
|
|
21
|
-
from google.cloud import logging as google_cloud_logging
|
|
22
|
-
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter
|
|
23
|
-
from opentelemetry.sdk.trace import ReadableSpan
|
|
24
|
-
from opentelemetry.sdk.trace.export import SpanExportResult
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class CloudTraceLoggingSpanExporter(CloudTraceSpanExporter):
|
|
28
|
-
"""
|
|
29
|
-
An extended version of CloudTraceSpanExporter that logs span data to Google Cloud Logging
|
|
30
|
-
and handles large attribute values by storing them in Google Cloud Storage.
|
|
31
|
-
|
|
32
|
-
This class helps bypass the 256 character limit of Cloud Trace for attribute values
|
|
33
|
-
by leveraging Cloud Logging (which has a 256KB limit) and Cloud Storage for larger payloads.
|
|
34
|
-
"""
|
|
35
|
-
|
|
36
|
-
def __init__(
|
|
37
|
-
self,
|
|
38
|
-
logging_client: google_cloud_logging.Client | None = None,
|
|
39
|
-
storage_client: storage.Client | None = None,
|
|
40
|
-
bucket_name: str | None = None,
|
|
41
|
-
debug: bool = False,
|
|
42
|
-
**kwargs: Any,
|
|
43
|
-
) -> None:
|
|
44
|
-
"""
|
|
45
|
-
Initialize the exporter with Google Cloud clients and configuration.
|
|
46
|
-
|
|
47
|
-
:param logging_client: Google Cloud Logging client
|
|
48
|
-
:param storage_client: Google Cloud Storage client
|
|
49
|
-
:param bucket_name: Name of the GCS bucket to store large payloads
|
|
50
|
-
:param debug: Enable debug mode for additional logging
|
|
51
|
-
:param kwargs: Additional arguments to pass to the parent class
|
|
52
|
-
"""
|
|
53
|
-
super().__init__(**kwargs)
|
|
54
|
-
self.debug = debug
|
|
55
|
-
self.logging_client = logging_client or google_cloud_logging.Client(
|
|
56
|
-
project=self.project_id
|
|
57
|
-
)
|
|
58
|
-
self.logger = self.logging_client.logger(__name__)
|
|
59
|
-
self.storage_client = storage_client or storage.Client(project=self.project_id)
|
|
60
|
-
self.bucket_name = (
|
|
61
|
-
bucket_name or f"{self.project_id}-{{cookiecutter.project_name}}-logs"
|
|
62
|
-
)
|
|
63
|
-
self.bucket = self.storage_client.bucket(self.bucket_name)
|
|
64
|
-
|
|
65
|
-
def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
|
|
66
|
-
"""
|
|
67
|
-
Export the spans to Google Cloud Logging and Cloud Trace.
|
|
68
|
-
|
|
69
|
-
:param spans: A sequence of spans to export
|
|
70
|
-
:return: The result of the export operation
|
|
71
|
-
"""
|
|
72
|
-
for span in spans:
|
|
73
|
-
span_context = span.get_span_context()
|
|
74
|
-
trace_id = format(span_context.trace_id, "x")
|
|
75
|
-
span_id = format(span_context.span_id, "x")
|
|
76
|
-
span_dict = json.loads(span.to_json())
|
|
77
|
-
|
|
78
|
-
span_dict["trace"] = f"projects/{self.project_id}/traces/{trace_id}"
|
|
79
|
-
span_dict["span_id"] = span_id
|
|
80
|
-
|
|
81
|
-
span_dict = self._process_large_attributes(
|
|
82
|
-
span_dict=span_dict, span_id=span_id
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
if self.debug:
|
|
86
|
-
print(span_dict)
|
|
87
|
-
|
|
88
|
-
# Log the span data to Google Cloud Logging
|
|
89
|
-
{%- if cookiecutter.is_adk %}
|
|
90
|
-
self.logger.log_struct(
|
|
91
|
-
span_dict,
|
|
92
|
-
labels={
|
|
93
|
-
"type": "agent_telemetry",
|
|
94
|
-
"service_name": "{{cookiecutter.project_name}}",
|
|
95
|
-
},
|
|
96
|
-
severity="INFO",
|
|
97
|
-
)
|
|
98
|
-
{%- else %}
|
|
99
|
-
self.logger.log_struct(span_dict, severity="INFO")
|
|
100
|
-
{%- endif %}
|
|
101
|
-
# Export spans to Google Cloud Trace using the parent class method
|
|
102
|
-
return super().export(spans)
|
|
103
|
-
|
|
104
|
-
def store_in_gcs(self, content: str, span_id: str) -> str:
|
|
105
|
-
"""
|
|
106
|
-
Initiate storing large content in Google Cloud Storage/
|
|
107
|
-
|
|
108
|
-
:param content: The content to store
|
|
109
|
-
:param span_id: The ID of the span
|
|
110
|
-
:return: The GCS URI of the stored content
|
|
111
|
-
"""
|
|
112
|
-
if not self.storage_client.bucket(self.bucket_name).exists():
|
|
113
|
-
logging.warning(
|
|
114
|
-
f"Bucket {self.bucket_name} not found. "
|
|
115
|
-
"Unable to store span attributes in GCS."
|
|
116
|
-
)
|
|
117
|
-
return "GCS bucket not found"
|
|
118
|
-
|
|
119
|
-
blob_name = f"spans/{span_id}.json"
|
|
120
|
-
blob = self.bucket.blob(blob_name)
|
|
121
|
-
|
|
122
|
-
blob.upload_from_string(content, "application/json")
|
|
123
|
-
return f"gs://{self.bucket_name}/{blob_name}"
|
|
124
|
-
|
|
125
|
-
def _process_large_attributes(self, span_dict: dict, span_id: str) -> dict:
|
|
126
|
-
"""
|
|
127
|
-
Process large attribute values by storing them in GCS if they exceed the size
|
|
128
|
-
limit of Google Cloud Logging.
|
|
129
|
-
|
|
130
|
-
:param span_dict: The span data dictionary
|
|
131
|
-
:param trace_id: The trace ID
|
|
132
|
-
:param span_id: The span ID
|
|
133
|
-
:return: The updated span dictionary
|
|
134
|
-
"""
|
|
135
|
-
attributes = span_dict["attributes"]
|
|
136
|
-
if len(json.dumps(attributes).encode()) > 255 * 1024: # 250 KB
|
|
137
|
-
# Separate large payload from other attributes
|
|
138
|
-
attributes_payload = dict(attributes.items())
|
|
139
|
-
attributes_retain = dict(attributes.items())
|
|
140
|
-
|
|
141
|
-
# Store large payload in GCS
|
|
142
|
-
gcs_uri = self.store_in_gcs(json.dumps(attributes_payload), span_id)
|
|
143
|
-
attributes_retain["uri_payload"] = gcs_uri
|
|
144
|
-
attributes_retain["url_payload"] = (
|
|
145
|
-
f"https://storage.mtls.cloud.google.com/"
|
|
146
|
-
f"{self.bucket_name}/spans/{span_id}.json"
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
span_dict["attributes"] = attributes_retain
|
|
150
|
-
logging.info(
|
|
151
|
-
"Length of payload span above 250 KB, storing attributes in GCS "
|
|
152
|
-
"to avoid large log entry errors"
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
return span_dict
|