Skip to content
Open
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
9 changes: 8 additions & 1 deletion docker/cmsmon-py/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
krb5-user \
&& rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir click pandas rucio-clients schema stomp.py==7.0.0
RUN pip install --no-cache-dir \
click \
opentelemetry-exporter-otlp~=1.39.0 \
pandas \
rucio-clients \
schema \
stomp.py==7.0.0

COPY helpers/ $WDIR/helpers/
COPY src/ ./
33 changes: 32 additions & 1 deletion docker/cmsmon-py/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CMS Monitoring Python base image

Dockerfile for generating the Base image for most non-Spark Python services in CMS Monitoring infrastructure.
Dockerfile for generating the base image for most non-Spark Python services in CMS Monitoring infrastructure.

## Characteristics

Expand All @@ -15,6 +15,7 @@ Dockerfile for generating the Base image for most non-Spark Python services in C
### Pre-installed Packages

- `click` - Command line interface creation toolkit
- `opentelemetry-exporter-otlp~=1.39.0` - OTLP export for metrics, traces, and logs
- `pandas` - Data manipulation and analysis library
- `rucio-clients` - CMS data management system client
- `schema` - Data validation library
Expand All @@ -23,3 +24,33 @@ Dockerfile for generating the Base image for most non-Spark Python services in C
## Usage

This image functions as a base image for CMS Monitoring services that require Python but are not Spark-related. It is designed to be extended rather than run directly, and should be used as a base layer in Docker images that contain the specific scripts and code for individual services.

## OpenTelemetry in child images

Child images can send metrics, traces, and logs to the in-cluster OpenTelemetry Collector via `helpers/otel_setup.py`. Instrumentation is opt-in: set `OTEL_ENABLED=true` and `OTEL_SERVICE_NAME` in the workload environment (and `OTEL_EXPORTER_OTLP_ENDPOINT` if not using the default `opentelemetry-collector.opentelemetry.svc.cluster.local:4317`).

Import `otel_setup` at startup (before `logging.getLogger()`). It configures stdout logging for `kubectl logs` and, when `OTEL_ENABLED=true`, also exports logs to the collector. Jobs should use `logging` (not `print`):

```python
import logging

import helpers.otel_setup # noqa: F401 — configures stdout + optional OTLP
from helpers.otel_setup import global_meter, shutdown_opentelemetry, trace_span

logger = logging.getLogger(__name__)

@trace_span("my_job_step")
def run_job():
logger.info("processing started")
global_meter.create_counter("jobs_processed").add(1)

if __name__ == "__main__":
try:
run_job()
finally:
shutdown_opentelemetry()
```

See `helpers/otel_setup.py` for the full list of supported environment variables.

Stomp loggers are set to `WARNING` on import (independent of `OTEL_ENABLED`). Re-call `configure_stomp_log_levels()` after `StompAMQ` init if needed.
Loading