Auto-instrument sanctions with OpenTelemetry zero-code

Add opentelemetry-distro/exporter-otlp (pinned pair) and run
opentelemetry-bootstrap at build time; wrap the sanctions command with
opentelemetry-instrument and configure the SDK via OTEL_* env (traces
only, OTLP/HTTP to otlp.vione.cloud). create-secrets.sh now writes the
base64 OTLP auth header into .env.observability.

The G10 guard test (no observability libraries in requirements) is
expected to fail from here until the guard suite is retired in Phase 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Movses Aslanyan
2026-10-12 20:09:38 +03:30
co-authored by Claude Opus 5.5
parent 995c93982a
commit f721df3063
4 changed files with 21 additions and 3 deletions
+1
View File
@@ -12,6 +12,7 @@ WORKDIR /app
COPY requirements.txt . COPY requirements.txt .
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
RUN opentelemetry-bootstrap -a install
COPY common ./common COPY common ./common
COPY services ./services COPY services ./services
+10 -1
View File
@@ -139,7 +139,16 @@ services:
environment: environment:
<<: *app-env <<: *app-env
SERVICE_NAME: sanctions SERVICE_NAME: sanctions
command: uvicorn services.sanctions.app:app --host 0.0.0.0 --port 8003 --reload --no-access-log OTEL_SERVICE_NAME: sanctions
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=prod
OTEL_EXPORTER_OTLP_ENDPOINT: https://otlp.vione.cloud
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
OTEL_TRACES_EXPORTER: otlp
OTEL_METRICS_EXPORTER: none
OTEL_LOGS_EXPORTER: none
env_file:
- .env.observability
command: opentelemetry-instrument uvicorn services.sanctions.app:app --host 0.0.0.0 --port 8003 --reload --no-access-log
ports: ports:
- "8003:8003" - "8003:8003"
healthcheck: healthcheck:
+8 -2
View File
@@ -10,7 +10,8 @@
# (Prometheus, Alertmanager, Loki, Tempo, Alloy UI, OTLP) # (Prometheus, Alertmanager, Loki, Tempo, Alloy UI, OTLP)
# grafana-admin Grafana admin user/password # grafana-admin Grafana admin user/password
# and writes .env.observability at the repo root (gitignored) for the czy-side # and writes .env.observability at the repo root (gitignored) for the czy-side
# Alloy log agent; copy it to the server once (see k8s/README.md). # Alloy log agent and the OTLP auth header of instrumented services; copy it to
# the server after every regeneration (see k8s/README.md).
# #
# KUBECTL defaults to `kubectl`; e.g. KUBECTL="ssh falken kubectl" to run it on # KUBECTL defaults to `kubectl`; e.g. KUBECTL="ssh falken kubectl" to run it on
# the node when the API server isn't reachable from here. # the node when the API server isn't reachable from here.
@@ -47,14 +48,19 @@ kubectl create secret generic grafana-admin -n "$NS" \
--from-literal=admin-password="$GRAFANA_ADMIN_PASSWORD" \ --from-literal=admin-password="$GRAFANA_ADMIN_PASSWORD" \
--dry-run=client -o yaml | $KUBECTL apply -f - --dry-run=client -o yaml | $KUBECTL apply -f -
# OTLP header for instrumented services: URL-encoded (space -> %20), and
# newlines stripped because GNU base64 wraps at 76 chars and this is ~80.
OTLP_BASIC=$(printf '%s:%s' "$OBS_USER" "$OBS_PASSWORD" | base64 | tr -d '\n')
( (
umask 077 umask 077
cat > ../.env.observability <<EOF cat > ../.env.observability <<EOF
# Credentials for the Alloy log agent on czy (docker-compose.traefik.yml). # Credentials for the Alloy log agent and instrumented services on czy.
# Generated by k8s/create-secrets.sh -- do not commit. # Generated by k8s/create-secrets.sh -- do not commit.
LOKI_PUSH_URL=https://loki.vione.cloud/loki/api/v1/push LOKI_PUSH_URL=https://loki.vione.cloud/loki/api/v1/push
LOKI_PUSH_USER=$OBS_USER LOKI_PUSH_USER=$OBS_USER
LOKI_PUSH_PASSWORD=$OBS_PASSWORD LOKI_PUSH_PASSWORD=$OBS_PASSWORD
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Basic%20$OTLP_BASIC
EOF EOF
) )
echo "wrote $(cd .. && pwd)/.env.observability" echo "wrote $(cd .. && pwd)/.env.observability"
+2
View File
@@ -8,3 +8,5 @@ redis==5.2.1
pydantic==2.10.4 pydantic==2.10.4
pydantic-settings==2.7.1 pydantic-settings==2.7.1
python-multipart==0.0.20 python-multipart==0.0.20
opentelemetry-distro==0.66b1
opentelemetry-exporter-otlp==1.45.1