-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·82 lines (73 loc) · 2.55 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·82 lines (73 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PLUGIN_SPEC="@devtheops/opencode-plugin-otel"
OPENCODE_CONFIG="$HOME/.config/opencode/opencode.json"
log() { printf '[%s] [INFO] %s\n' "$(date '+%H:%M:%S')" "$*"; }
warn() { printf '[%s] [WARN] %s\n' "$(date '+%H:%M:%S')" "$*" >&2; }
err() { printf '[%s] [ERROR] %s\n' "$(date '+%H:%M:%S')" "$*" >&2; }
trap 'err "Setup failed (line $LINENO). See output above for details."' ERR
log "Starting opencode-otel-observability setup"
# 0. Check prerequisites
log "Checking prerequisites (docker, docker compose, uv)..."
if ! command -v docker >/dev/null 2>&1; then
err "'docker' is not installed."
exit 1
fi
log " found docker: $(command -v docker)"
if ! docker compose version >/dev/null 2>&1; then
err "'docker compose' (v2) is not available."
exit 1
fi
log " found docker compose: $(docker compose version --short 2>/dev/null || echo unknown)"
if ! command -v uv >/dev/null 2>&1; then
err "'uv' is not installed. See https://docs.astral.sh/uv/"
exit 1
fi
log " found uv: $(command -v uv)"
log "Prerequisites OK"
# 1. Configure opencode.json (idempotent). opencode installs the plugin from npm at startup.
log "Configuring $OPENCODE_CONFIG..."
if [ -f "$OPENCODE_CONFIG" ]; then
uv run python - "$OPENCODE_CONFIG" "$PLUGIN_SPEC" <<'EOF'
import json, sys
path, spec = sys.argv[1], sys.argv[2]
with open(path) as f:
c = json.load(f)
c.setdefault("plugin", [])
if spec not in c["plugin"]:
c["plugin"].append(spec)
with open(path, "w") as f:
json.dump(c, f, indent=2)
f.write("\n")
print(f">>> Added {spec} to opencode.json")
else:
print(f">>> Plugin already in opencode.json")
EOF
else
log " $OPENCODE_CONFIG not found, creating with plugin entry..."
mkdir -p "$(dirname "$OPENCODE_CONFIG")"
printf '{"plugin":["%s"]}\n' "$PLUGIN_SPEC" > "$OPENCODE_CONFIG"
fi
log "opencode.json configured"
log "Currently installed plugins:"
uv run python -c "
import json
with open('$OPENCODE_CONFIG') as f:
c = json.load(f)
for p in c.get('plugin', []):
print(f' - {p}')
"
# 2. Start the stack
log "Starting observability stack (docker compose up -d)..."
docker compose -f "$SCRIPT_DIR/../docker-compose.yml" up -d
log "Observability stack is up"
log "Setup complete."
echo ""
echo "Run opencode with telemetry:"
echo " just run-opencode"
echo ""
echo "Or export env vars and run opencode directly:"
echo " export OPENCODE_ENABLE_TELEMETRY=1"
echo " export OPENCODE_OTLP_ENDPOINT=http://localhost:4317"
echo " export OPENCODE_OTLP_PROTOCOL=grpc"