本文介紹coze-studio 接入AI可觀測的流程。
操作步驟
一、下載代碼
git clone https://github.com/coze-dev/coze-studio.git
cd coze-studio
切到對應tag
git checkout xxx二、修改back/Dockerfile
增加instgo 編譯步驟,如下所示
#download instgo
RUN wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/instgo/instgo-linux-amd64" -O instgo
RUN chmod +x instgo
# Build the Go application With instgo
RUN ./instgo go build -ldflags="-s -w" -o /app/opencoze main.go整個Dockerfile如下所示:
# Stage 1: Builder for Go application
FROM golang:1.24-alpine AS builder
WORKDIR /app
# Install build dependencies for Go
RUN apk add --no-cache git gcc libc-dev
# Copy go.mod and go.sum first to leverage Docker cache
COPY backend/go.mod backend/go.sum ./
RUN go mod download
# Copy the entire backend source code
COPY backend/ ./
#download instgo
RUN wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/instgo/instgo-linux-amd64" -O instgo
RUN chmod +x instgo
# Build the Go application With instgo
RUN ./instgo go build -ldflags="-s -w" -o /app/opencoze main.go
# Stage 2: Final image
FROM alpine:3.22.0
WORKDIR /app
# Install runtime dependencies for Go app and base for Python
# pax-utils for scanelf, python3 for running Python, python3-dev for headers/shared libs
# bind-tools for nslookup etc., file for debugging file types
RUN apk add --no-cache pax-utils python3 python3-dev bind-tools file deno curl
RUN deno run -A jsr:@eyurtsev/pyodide-sandbox -c "print('Hello, World')"
# Install Python build dependencies, create venv, install packages, then remove build deps
RUN apk add --no-cache --virtual .python-build-deps build-base py3-pip git && \
python3 -m venv --copies --upgrade-deps /app/.venv && \
# Activate venv and install packages
. /app/.venv/bin/activate && \
# If you want to use other third-party libraries, you can install them here.
pip install urllib3==1.26.16 && \
pip install --no-cache-dir h11==0.16.0 httpx==0.28.1 pillow==11.2.1 pdfplumber==0.11.7 python-docx==1.2.0 numpy==2.3.1 && \
# Deactivate (optional, as RUN is a new shell)
# deactivate && \
# Remove build dependencies
apk del .python-build-deps
# Copy the built Go binary from the builder stage
COPY --from=builder /app/opencoze /app/opencoze
# Copy Python application scripts
COPY backend/infra/document/parser/impl/builtin/parse_pdf.py /app/parse_pdf.py
COPY backend/infra/document/parser/impl/builtin/parse_docx.py /app/parse_docx.py
COPY backend/infra/coderunner/impl/script/sandbox.py /app/sandbox.py
# Copy static resources
# COPY backend/static /app/resources/static/
COPY backend/conf /app/resources/conf/
COPY docker/.env.example /app/.env
# COPY docker/.env.ve /app/.env
# COPY docker/cert.pem /app/cert.pem
# COPY docker/key.pem /app/key.pem
# Set PATH to prioritize venv's binaries
ENV PATH="/app/.venv/bin:${PATH}"
# ENV LD_LIBRARY_PATH="/usr/lib:${LD_LIBRARY_PATH}" # Keep commented for now
# Ensure python scripts and venv executables are executable
RUN chmod +x /app/parse_pdf.py /app/parse_docx.py && \
find /app/.venv/bin -type f -exec chmod +x {} \;
EXPOSE 8888
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
CMD ["/app/opencoze"]在coze-studio的根目錄執行docker build即可編譯鏡像。
三、接入監控
如果通過Docker Compose部署,可以在docker/docker-compose.yml中增加Go Agent啟動環境變數,如下所示:
environment:
ARMS_ENABLE: true
ARMS_APP_NAME: coze-server
ARMS_REGION_ID: xxxxx
ARMS_LICENSE_KEY: xxxx擷取環境變數可以參考:手動安裝Golang探針,若是K8s部署,可以參考Container Service ACK 和容器計算服務 ACS 通過 ack-onepilot 組件安裝 Go 探針 安裝ack-onepilot後添加對應的label 即可。
四、查看監控
在ARMS控制台,在LLM應用監控-應用列表-coze-server查看。