FROM node:22-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci --omit=dev

FROM node:22-alpine AS production
WORKDIR /app
# OpenTelemetry bootstrap: src/telemetry.mjs registers the ESM loader hook and loads the
# auto-instrumentation only when the platform injects an OTLP endpoint
# (OTEL_EXPORTER_OTLP_ENDPOINT); otherwise it is silent. Cloud metadata detectors
# (GCP/AWS/Azure) are skipped: they only probe and warn on a Cortex host.
ENV NODE_OPTIONS="--import /app/src/telemetry.mjs" \
    OTEL_NODE_RESOURCE_DETECTORS="env,host,os,process"
COPY --from=deps /app/node_modules ./node_modules
COPY . .
EXPOSE 8000
CMD ["node", "src/index.js"]
