Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions veadk/configs/tracing_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ class CozeloopConfig(BaseSettings):
default="", alias="OBSERVABILITY_OPENTELEMETRY_COZELOOP_SERVICE_NAME"
)

# TODO: auto fetching via AK/SK pair
# @cached_property
# def otel_exporter_api_key(self) -> str:
# pass

# TODO: auto fetching workspace id
# @cached_property
# def otel_exporter_space_id(self) -> str:
# workspace_id = os.getenv("OBSERVABILITY_OPENTELEMETRY_COZELOOP_SERVICE_NAME", "")

# if not workspace_id:
# # create a default one
# workspace_id = VeCozeloop(self.otel_exporter_api_key).create_workspace(
# workspace_name=DEFAULT_COZELOOP_SPACE_NAME
# )

# return workspace_id


class TLSConfig(BaseSettings):
otel_exporter_endpoint: str = Field(
Expand Down
2 changes: 1 addition & 1 deletion veadk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@

DEFAULT_TOS_BUCKET_NAME = "veadk-default-bucket"

DEFAULT_COZELOOP_SPACE_NAME = "veadk-space"
DEFAULT_COZELOOP_SPACE_NAME = "VeADK Space"
13 changes: 13 additions & 0 deletions veadk/integrations/ve_cozeloop/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
90 changes: 90 additions & 0 deletions veadk/integrations/ve_cozeloop/ve_cozeloop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import requests

from veadk.consts import DEFAULT_COZELOOP_SPACE_NAME
from veadk.utils.logger import get_logger

logger = get_logger(__name__)


class VeCozeloop:
def __init__(self, api_key: str) -> None:
self.api_key = api_key

def create_workspace(
self, workspace_name: str = DEFAULT_COZELOOP_SPACE_NAME
) -> str:
logger.info(
f"Automatically create Cozeloop workspace with name {workspace_name}"
)

URL = "https://api.coze.cn/v1/workspaces"

headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}

data = {
"name": workspace_name,
"description": "Created by Volcengine Agent Development Kit (VeADK)",
}

response = requests.post(URL, headers=headers, json=data)

if response.json().get("code") == 0:
workspace_id = response.json().get("data").get("id")
logger.info(f"Cozeloop workspace ID: {workspace_id}")
return workspace_id
else:
raise Exception(
f"Failed to automatically create workspace: {response.json()}"
)

def get_workspace_id(
self, workspace_name: str = DEFAULT_COZELOOP_SPACE_NAME
) -> str:
logger.info(
f"Automatically fetching Cozeloop workspace ID with name {workspace_name}"
)

URL = "https://api.coze.cn/v1/workspaces"

headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}

data = {
"page_num": 1,
"page_size": 50,
}

response = requests.post(URL, headers=headers, json=data)

if response.json().get("code") == 0:
workspaces = response.json().get("data").get("workspaces", [])

workspace_id = ""
for workspace in workspaces:
if workspace.get("name") == workspace_name:
workspace_id = workspace.get("id")
logger.info(f"Get Cozeloop workspace ID: {workspace_id}")
return workspace_id

raise Exception(f"Workspace with name {workspace_name} not found.")
else:
raise Exception(f"Failed to get workspace ID: {response.json()}")
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ TIMEOUT=${_FAAS_FUNC_TIMEOUT}
export SERVER_HOST=$HOST
export SERVER_PORT=$PORT

export PYTHONPATH=$PYTHONPATH:./site-packages
# use cached veadk-python and corresponding deps in VeFaaS
# `./preinstalled-site-packages` stores veadk-python and its dependencies
export PYTHONPATH=$PYTHONPATH:./site-packages:./preinstalled-site-packages

# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
Expand Down