Skip to content
Merged
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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ Changes to Deployyy, newest first. Each feature works in the console at
[deployyy.com](https://deployyy.com), the API and the MCP tools. Exceptions
are noted per entry.

## 2026-12-02

### Traces

- **Each request of a Next.js or GraphCommerce server is one span, named by
its route, in the trace of the gateway.** Its `fetch` calls to a Magento
backend carry the `traceparent`, so the PHP request continues the same
trace. A GraphQL call is named by its operation, such as
`GET graphql CategoryPage`. The Requests page of the environment lists the
requests.
- **The platform sets `OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_TRACES_SAMPLER`
and `OTEL_SERVICE_NAME` on each process.** `OTEL_SERVICE_NAME` is the name
of the process, such as `magento-web`. A stored value of these variables
has no effect.

## 2026-11-30

### Profiles
Expand Down
38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,14 @@ Laravel writes to stderr with `LOG_CHANNEL=stderr`, a value of the recipe.

Each PHP-FPM request of a Magento, Mage-OS or Laravel image on PHP 8.2 or later
is one span, a child of the `traceparent` of the request. The SDK sends the
spans to `OTEL_EXPORTER_OTLP_ENDPOINT`, a value of the recipe that names the
collector of the platform. Set the variable to your own OTLP/HTTP endpoint, or
leave it empty to send no spans.
spans to the collector of the platform. The platform sets these variables on
each process:

| Variable | Value |
|---|---|
| `OTEL_EXPORTER_OTLP_ENDPOINT` | the OTLP/HTTP endpoint of the collector |
| `OTEL_TRACES_SAMPLER` | `parentbased_always_off`: a process records a request with a sampled `traceparent`, such as each request through the gateway. A health check of the kubelet has none. |
| `OTEL_SERVICE_NAME` | the name of the process, such as `magento-web` |

The spans of a request:

Expand Down Expand Up @@ -356,8 +361,6 @@ no bundle and configures OpenTelemetry itself.

| Variable | Image value |
|---|---|
| `OTEL_SERVICE_NAME` | `magento` or `laravel` |
| `OTEL_TRACES_SAMPLER` | `parentbased_always_off`: PHP-FPM records a request with a sampled `traceparent`, such as each request through the gateway. A health check of the kubelet has none. |
| `OTEL_EXPORTER_OTLP_TIMEOUT` | `1000` (milliseconds) |
| `OTEL_PHP_DISABLED_INSTRUMENTATIONS` | none; `pdo,guzzle` turns those off |

Expand Down Expand Up @@ -411,6 +414,31 @@ Every variable and secret is available to `next build` and, at runtime, to
the server in `process.env`. As on Vercel, only `NEXT_PUBLIC_*` values end up
in the browser bundle.

### Traces

Each request of the Next.js server is one span of the instrumentation
`next.js`, named by its method and its route, such as `GET /products/[slug]`,
a child of the `traceparent` of the request. Each `fetch` and each `http`
call of the server is a child span. A call to an address inside the platform,
a host name without a dot or under `.svc`, carries the `traceparent`, so the
PHP request of a Magento backend continues the trace. A call to another host
carries no `traceparent`. A GraphQL call is named as the PHP request that
answers it, such as `GET graphql CategoryPage`, with
`graphql.operation.name` and `graphql.operation.type`. The variables of the
platform are in [Traces](#traces).

The build bundles [`otel.mjs`](recipes/nextjs/platform/otel.mjs), which
calls `registerOTel` of [`@vercel/otel`](https://github.com/vercel/otel),
with the packages of
[`otel-package.json`](recipes/nextjs/platform/otel-package.json) into one file
of the image. [`inject-instrumentation.mjs`](recipes/nextjs/platform/inject-instrumentation.mjs)
writes the instrumentation file of Next.js, which loads that file. Your own
`instrumentation.ts` or `.js` stays: the build renames it to
`instrumentation.project.ts`, and its `register()` and its other exports run
as before. A project that depends on `@vercel/otel` or an
`@opentelemetry/sdk-*` package gets no instrumentation file and configures
OpenTelemetry itself.

### Magento backend for a storefront

A GraphCommerce storefront paired with a Magento project builds against one
Expand Down
6 changes: 3 additions & 3 deletions recipes/laravel/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ ENV PHP_EXTENSION_GD=1 PHP_EXTENSION_INTL=1 PHP_EXTENSION_BCMATH=1 \
PHP_EXTENSION_OPCACHE=1 PHP_INI_OPCACHE__ENABLE=1 \
PHP_INI_MEMORY_LIMIT=512M PHP_INI_DATE__TIMEZONE=Europe/Amsterdam \
TEMPLATE_PHP_INI=production
# The settings of the OpenTelemetry SDK. OTEL_EXPORTER_OTLP_ENDPOINT, a value of the
# recipe, starts the traces of PHP-FPM (.platform/otel-bootstrap.php).
ENV PHP_EXTENSION_OPENTELEMETRY=1 PHP_EXTENSION_EXCIMER=1 OTEL_PHP_AUTOLOAD_ENABLED=true OTEL_TRACES_SAMPLER=parentbased_always_off OTEL_SERVICE_NAME=laravel \
# The settings of the OpenTelemetry SDK. OTEL_EXPORTER_OTLP_ENDPOINT, a platform variable,
# starts the traces of PHP-FPM (.platform/otel-bootstrap.php).
ENV PHP_EXTENSION_OPENTELEMETRY=1 PHP_EXTENSION_EXCIMER=1 OTEL_PHP_AUTOLOAD_ENABLED=true \
OTEL_PHP_PSR3_MODE=inject OTEL_METRICS_EXPORTER=none OTEL_LOGS_EXPORTER=none \
OTEL_EXPORTER_OTLP_TIMEOUT=1000
# `php artisan migrate` loads a schema dump (database/schema/) with the client
Expand Down
6 changes: 3 additions & 3 deletions recipes/magento/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ ENV PHP_EXTENSION_GD=1 PHP_EXTENSION_INTL=1 PHP_EXTENSION_OPCACHE=1 \
PHP_INI_OPCACHE__MEMORY_CONSUMPTION=512 PHP_INI_OPCACHE__INTERNED_STRINGS_BUFFER=64 \
PHP_INI_OPCACHE__MAX_ACCELERATED_FILES=130000 PHP_INI_OPCACHE__VALIDATE_TIMESTAMPS=0 \
TEMPLATE_PHP_INI=production
# The settings of the OpenTelemetry SDK. OTEL_EXPORTER_OTLP_ENDPOINT, a value of the
# recipe, starts the traces of PHP-FPM (.platform/otel-bootstrap.php).
ENV PHP_EXTENSION_OPENTELEMETRY=1 PHP_EXTENSION_EXCIMER=1 OTEL_PHP_AUTOLOAD_ENABLED=true OTEL_TRACES_SAMPLER=parentbased_always_off OTEL_SERVICE_NAME=magento \
# The settings of the OpenTelemetry SDK. OTEL_EXPORTER_OTLP_ENDPOINT, a platform variable,
# starts the traces of PHP-FPM (.platform/otel-bootstrap.php).
ENV PHP_EXTENSION_OPENTELEMETRY=1 PHP_EXTENSION_EXCIMER=1 OTEL_PHP_AUTOLOAD_ENABLED=true \
OTEL_PHP_PSR3_MODE=inject OTEL_METRICS_EXPORTER=none OTEL_LOGS_EXPORTER=none \
OTEL_EXPORTER_OTLP_TIMEOUT=1000
USER root
Expand Down
19 changes: 17 additions & 2 deletions recipes/nextjs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
# build and never stored in a layer.
ARG NODE_VERSION=22

# The OpenTelemetry SDK of the Next.js server (README, "Traces"): .platform/otel.mjs with the
# packages of .platform/otel-package.json, bundled into one file. A fixed Node.js version keeps
# the cache of this stage independent of the project.
FROM node:22-bookworm-slim AS otel
WORKDIR /otel
COPY .platform/otel-package.json package.json
COPY .platform/otel-package-lock.json package-lock.json
COPY .platform/otel.mjs otel.mjs
RUN npm ci --ignore-scripts --no-audit --no-fund \
&& node_modules/.bin/esbuild otel.mjs --bundle --platform=node --format=esm --target=node18 \
--main-fields=module,main --outfile=deployyy-otel.mjs \
--banner:js="import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);"

FROM node:${NODE_VERSION}-bookworm-slim AS builder
ENV NEXT_TELEMETRY_DISABLED=1 COREPACK_ENABLE_DOWNLOAD_PROMPT=0 CI=1
WORKDIR /app
Expand All @@ -32,9 +45,10 @@ RUN corepack enable
# and postinstall code generation (GraphCommerce) all need more than the
# lockfile, and a partial copy fails in ways that are hard to see.
COPY . .
# The platform cache handler and the Next config wrapper (docs in each file).
# The platform cache handler, the Next config wrapper and the instrumentation file (docs in each file).
RUN cp .platform/cache-handler.mjs deployyy-cache-handler.mjs \
&& node .platform/inject-next-config.mjs
&& node .platform/inject-next-config.mjs \
&& node .platform/inject-instrumentation.mjs
# The commit sha as the Next build id (inject-next-config.mjs).
ARG DEPLOYYY_BUILD_ID=""
RUN --mount=type=secret,id=build-env,required=false \
Expand Down Expand Up @@ -84,6 +98,7 @@ RUN groupadd --system --gid 1001 nextjs \
COPY --from=builder --chown=1001:1001 /app/.next/standalone ./
COPY --from=builder --chown=1001:1001 /app/.next/static ./.next/static
COPY --from=builder --chown=1001:1001 /app/public ./public
COPY --from=otel /otel/deployyy-otel.mjs /usr/local/lib/deployyy/deployyy-otel.mjs
# Numeric, so the kubelet can verify runAsNonRoot without a securityContext.
LABEL app.deployyy.pod-security="restricted"
USER 1001:1001
Expand Down
59 changes: 59 additions & 0 deletions recipes/nextjs/platform/inject-instrumentation.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Platform build step for Next.js and GraphCommerce projects: load the OpenTelemetry SDK of the
* platform (otel.mjs, bundled into deployyy-otel.mjs) in the Next.js server, so a project carries
* no tracing package and no tracing code of its own.
*
* Runs in the Dockerfile builder stage, in the project root, before `next build`. It writes the
* instrumentation file of Next.js (`instrumentation.js`, in `src/` when the pages or the app
* directory is in `src/`). Its `register()` imports deployyy-otel.mjs in the Node.js runtime while
* OTEL_EXPORTER_OTLP_ENDPOINT is set. The import names an absolute path in the runtime image, and
* Next.js does not bundle it.
*
* A project with its own instrumentation file keeps it: the file is renamed to
* `instrumentation.project.<ext>`, the generated file under the original name exports each export
* of it, and its `register()` runs after the SDK of the platform.
*
* A project that depends on @vercel/otel or an OpenTelemetry SDK configures OpenTelemetry itself
* and gets no generated file.
*/
import fs from 'node:fs'
import path from 'node:path'

const root = process.cwd()
// The runtime stage of the Dockerfile copies the bundle to this path.
const BUNDLE = '/usr/local/lib/deployyy/deployyy-otel.mjs'

const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
const dependencies = { ...pkg.dependencies, ...pkg.devDependencies }
const sdk = Object.keys(dependencies).find((name) => name === '@vercel/otel' || name.startsWith('@opentelemetry/sdk-'))
if (sdk) {
console.log(`Traces: the project depends on ${sdk}. The build adds no instrumentation file.`)
process.exit(0)
}

const exists = (...parts) => fs.existsSync(path.join(root, ...parts))
// Next.js reads the instrumentation file from src/ when the pages or the app directory is there.
const dir = !exists('pages') && !exists('app') && (exists('src', 'pages') || exists('src', 'app')) ? 'src' : '.'
// The default page extensions of Next.js.
const own = ['ts', 'tsx', 'js', 'jsx'].map((ext) => `instrumentation.${ext}`).find((f) => exists(dir, f))
const ext = own ? path.extname(own) : '.js'
const projectFile = own ? `instrumentation.project${ext}` : null
if (own) fs.renameSync(path.join(root, dir, own), path.join(root, dir, projectFile))

const projectModule = projectFile ? `./${path.basename(projectFile, ext)}` : null
const body = `/* eslint-disable */
${ext.startsWith('.ts') ? '// @ts-nocheck\n' : ''}// GENERATED AT BUILD TIME by the deployyy platform build (inject-instrumentation.mjs).
${projectModule ? `// Your own instrumentation is in ${projectFile}; edit that file, not this one.
import * as project from '${projectModule}'
export * from '${projectModule}'
` : ''}
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs' && process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {
await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ '${BUNDLE}')
}
${projectModule ? ' await project.register?.()\n' : ''}}
`

const generated = path.join(dir, `instrumentation${ext}`)
fs.writeFileSync(path.join(root, generated), body)
console.log(`Traces: ${generated} loads the OpenTelemetry SDK of the platform${own ? `, then ${path.join(dir, projectFile)}` : ''}.`)
8 changes: 7 additions & 1 deletion recipes/nextjs/platform/inject-next-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Runs in the Dockerfile builder stage, in the project root, before
* `next build`. It renames the project's config file to
* `next.config.project.<ext>` and writes a wrapper under the original config
* name that imports it and adds three settings:
* name that imports it and adds these settings:
*
* cacheHandler -> <root>/deployyy-cache-handler.mjs (the platform
* handler, copied next to the config by the
Expand All @@ -18,6 +18,9 @@
* the operator repo).
* output -> 'standalone' when the project sets no output. The
* runtime image runs `node server.js`.
* experimental.instrumentationHook -> true on Next.js 13 and 14, which
* load the instrumentation file of
* inject-instrumentation.mjs only with this flag.
* generateBuildId -> the commit sha (DEPLOYYY_BUILD_ID), when the
* project sets none. The cache seed and the runtime
* image are two build targets; a fixed build id
Expand Down Expand Up @@ -85,8 +88,10 @@ const body = `${isTs ? '// @ts-nocheck\n' : ''}// GENERATED AT BUILD TIME by the
// Your own config is in ${projectFile ?? '(none)'}; edit that file, not this one.
${importLine}
import path from 'node:path'
import { createRequire } from 'node:module'
import { fileURLToPath } from 'node:url'

const nextMajor = Number(createRequire(import.meta.url)('next/package.json').version.split('.')[0])
const handler = path.join(path.dirname(fileURLToPath(import.meta.url)), '${HANDLER}')
const loaded${isTs ? ': any' : ''} = (project${isTs ? ' as any' : ''}).default ?? project

Expand All @@ -97,6 +102,7 @@ export default async function deployyyConfig(phase${isTs ? ': string' : ''}, ctx
throw new Error("deployyy: output: 'export' produces static files without a server. Remove output: 'export' from your next.config.")
}
if (!config.output) config.output = 'standalone'
if (nextMajor < 15) config.experimental = { ...config.experimental, instrumentationHook: true }
if (!config.generateBuildId && process.env.DEPLOYYY_BUILD_ID) {
const buildId = process.env.DEPLOYYY_BUILD_ID
config.generateBuildId = () => buildId
Expand Down
Loading
Loading