#!/bin/sh
# OpenTelemetry zero-code bootstrap: wraps the service command with opentelemetry-instrument
# only when the platform injects an OTLP endpoint (the Cortex deploy overlay sets
# OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES); otherwise the
# command runs untouched and emits nothing. Never hard-code endpoints or ingestion keys.
set -e
if [ -n "${OTEL_EXPORTER_OTLP_ENDPOINT:-}${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT:-}" ]; then
  export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="${OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED:-true}"
  exec opentelemetry-instrument "$@"
fi
exec "$@"
