Skip to content

Configuration, Logging & Actuators

Write functions: run them the way engine apps run.

At a glance

  • What — one configuration style, one log presentation, one operational surface across Java, Rust, Python and Node.js apps.
  • For developers wiring an app and operators monitoring a polyglot estate.

Configuration — the engines' conventions

Configuration lives in the resources folder (resources/application.yml, .yaml or .properties) next to the application file — the file mercury-serve is given, or the script python app.py ran — never in the working directory, so the configuration does not depend on where the app is launched from (--config names another file). Values support ${ENV_VAR:default} substitution; -Dkey=value command-line arguments are runtime overrides checked first on every read — the same syntax as the Java engine's JVM system properties and the Rust port's -D arguments:

mercury-serve app.py -Drest.server.port=8090 -Dlog.format=compact

See the worked sample examples/demo-app/resources/application.yml and the full key table in the Configuration Reference.

Logging — one aggregation, three presentations

Log lines follow the Java reference engine's pattern, so a polyglot installation reads one way in the aggregator:

2026-08-24 10:15:30.123 INFO  my_app:42 - Loaded PUBLIC hello.python, instances=10

log.format carries the engines' three presentations: text (default), json (pretty-printed) and compact (single-line JSONL for log aggregators). A JSON line carries time, level, source (the emitting logger and line, name:line, under the label the Java engine's JSON layout uses) and message, plus context inside a traced request and exception when one is attached. The level comes from the LOG_LEVEL environment variable when set, else log.level.

The level does not decide whether a trace record is written: a traced function's record on the distributed.tracing logger is written when the function ends, at WARN and ERROR too, as in the engines. The record still passes through the logger and its handler. The level DEBUG is a development setting: it is the root level, so it also turns on the DEBUG lines of every library the application uses.

What the log holds, and what the pack masks

A credential in a function's input or in the configuration is not the problem; a credential in the application log is. The pack writes its own lines by the rules of the Java and Rust engines (What the log holds, and what the engine masks). The masks are a best effort: they cover the lines of the table, and the list after it says what is written as it is.

Value Where it is written What the pack does
The trace path path in every trace record of a request that arrives at a rest.yaml entry; trace_path in a function's trace context and in the context block of the JSON formats; the path attribute of an exported span; the trace_path column of the transcript audit store Writes the method and the path. The query string and a fragment are left out, and a function reads its parameters from the request as before
The access line The aiohttp.access logger, one line for each HTTP request at INFO Writes the request target without its query string, and the Referer header by the rule for a URL
A URL The start-up line of the OpenTelemetry forwarder; the lines of ask-person that name a graph's entry and the reply page; a refusal that quotes a configured URL Writes it through mask_url(): a user id and a password become ***, and the query string and the fragment are left out
A target with a user id and a password An Event-over-HTTP endpoint of PostOffice; otel.exporter.otlp.endpoint Refuses it by a text that names the fault and does not repeat the target: the call with a 400 before anything is sent, the forwarder when the application starts
A credential header The start-up lines of the OpenTelemetry forwarder Writes the names of the headers and not their values
The trace record The distributed.tracing logger Writes it whatever the log level says. It holds a function's error text and its annotations
An error The line for a function that fails when no caller waits (Async event ... ended with status), and the line for an interceptor that fails Writes the status and the error text as they are

What is declared and not masked:

  • Where a credential travels. The pack masks what it writes. It does not change a request, an event, a function's input or the configuration.
  • A path. A path parameter is part of the path and is written, and so is a secret inside a path segment.
  • A payload. A function's own lines are the function's. Keep a request body, a response body and a model's text out of a line.
  • An error text. The text of an AppException and of an uncaught exception is written in the trace record and in the lines of the table. Keep a credential and personal data out of an error message.
  • The application's own values. What a function passes to annotate_trace() and what it logs.
  • The level. DEBUG is for development.
  • The trace record. No level turns it off. A filter that an installation adds to the handler can.
  • The libraries' own lines, and the text of a library's exception. The MCP binding writes the error text of the MCP SDK when a server cannot be reached.
  • The lines that name a person on purpose. ask-person and agent-question write who decided a question: the line is the trail of an approval.

mask_url() is public, for the application that writes a connection URL in a line of its own:

from mercury_composable import get_logger, mask_url

log = get_logger(__name__)
log.info("Cache at %s", mask_url(cache_url))  # redis://***@cache:6379/0

The rule reads a text and not a parsed URL, so it takes a redis://, a mongodb:// and a jdbc: URL as it takes an https:// one. Its limits are declared with the rule: a path is written as it is, and a password that holds an unencoded /, ? or # ends the authority early, so percent-encode such a password or keep it out of the URL. The function and its vector file (tests/vectors/mask-url-vectors.json) are the same in the four runtimes.

For the lines of your own functions there is an elective filter, the log-masking extension: it applies the rules of a log-masking.yaml file to every line before the pack's handler writes it. See Log Masking.

Distributed tracing — the OpenTelemetry forwarder (opt-in)

Every traced execution leaves one distributed-trace dataset on the distributed.tracing log stream — {"trace": {...}, "annotations": {...}}, the record the Java engine logs — so a log aggregation already stitches the span tree across all four runtimes. Who emits it follows the engines' rules, so a span lineage stays continuous from an engine into this host:

  • a function execution that is not an RPC emits its own record when it finishes, parented onto the caller's span;
  • an RPC round trip is recorded by the caller's side, never by the responder (the engines' InboxBase): the PostOffice records a local call with the responder's span, which rides the reply, the caller's span as parent, the responder's exec_time and the round_trip it measured;
  • a function that answers for itself, an interceptor that sends its answer to the request's reply address, is recorded by the same rules. The answer takes the execution's span, its annotations and the time since the execution started when it is sent, so the caller's record of a request-response call holds them; it takes the sender and the trace too, so a function that receives the answer through a reply route runs under the trace, as the child of that execution. An answer passed on from another function keeps that function's exec_time and sender, and a stream's segments are the stream writer's;
  • a traced call arriving at /api/event leaves what a Java or Rust callee leaves for it: http.request (POST /api/event, the edge's round trip, parented onto the caller's span — the envelope's span, else the traceparent header's; the backend's SERVER span), event.api.service (the ingress, parented onto the edge) and, for an RPC, the function's round-trip record parented onto the service; a drop-n-forget or streaming function emits its own record under the service. A refused call (403, 404) and a timeout (408) leave the edge record with that status. An untraced call records nothing.

The forwarder is the second sink, for backends that take spans directly: Dynatrace, Splunk, an OpenTelemetry Collector.

otel.forwarding: true
otel.exporter.otlp.endpoint: 'https://<tenant>.live.dynatrace.com/api/v2/otlp/v1/traces'
otel.exporter.otlp.headers: 'Authorization=Api-Token ${DT_TOKEN}'
otel.service.name: 'my-python-functions'

With otel.forwarding=true (the switch is the only thing that turns it on — false by default, -Dotel.forwarding=true at run time is enough, and a value that is neither true nor false stops the start by name), the host also hands each dataset to the engines' extension route distributed.trace.forwarder, where the built-in forwarder registers itself at start-up (private, two workers; an application that registers its own function on that route wins). Each dataset becomes one OpenTelemetry span carrying the host's exact W3C trace, span and parent-span ids — the same mapping as the engines' forwarders, so one trace spans the engine that called and the function here — and is exported over OTLP/HTTP as protobuf, one span per request. There is no OpenTelemetry SDK and no new dependency: the encoder is the engines' own hand-written OTLP writer, ported.

Request headers are re-read on every export, so a credential a start-up bootstrap publishes with config.set(...) after the forwarder started takes effect without a restart; header names appear in the log, never values. A transport failure or a 408/429/502/503/504 answer is retried five times on the OpenTelemetry SDK's backoff (1 s growing by 1.5×); any other rejection is logged once with the status, the backend's message and a hint (HTTP 401 ... | the backend rejected the credential itself - check otel.exporter.otlp.headers). The start-up line confirms the configuration: OpenTelemetry trace forwarder ready - service=..., OTLP endpoint=..., compression=none, credential headers=[...]. It writes the endpoint without a query string. The backend's credential belongs in otel.exporter.otlp.headers: an endpoint that holds a user id and a password stops the start, by a text that names the key and does not repeat the endpoint.

Differences from the engines: only none compression is honoured (a warning otherwise); otel.exporter.otlp.connect.timeout is honoured here (aiohttp's connect timeout); the instrumentation scope is mercury-composable-python, so a backend shows which runtime produced a span. The keys are listed in the configuration reference.

Actuators — the engines' operational surface

The host serves the engines' endpoints on the same port as /api/event:

Endpoint Purpose
GET / the static folder's index.html, else a minimal index page linking the endpoints below
GET /info app identity, runtime, origin id, start time, uptime
GET /info/routes registered routes split by visibility, with instance counts
GET /env selected environment variables and configuration parameters (opt-in lists)
GET /health dependency health checks — UP (HTTP 200) or DOWN (HTTP 400)
GET /livenessprobe OK while the last health outcome was good, else HTTP 400

JSON responses are pretty-printed (the engines' default-serializer presentation) with application/json; charset=utf-8; unknown paths answer the engines' error shape — see the HTTP Surface Reference.

Health check functions — the engines' interface contract

A health check is a normal registered function (usually private) listed in mandatory.health.dependencies / optional.health.dependencies. The actuator calls it through the event bus, first with header type=info (an advisory identity map merged into its dependency entry), then with type=health (a status text or map; a non-200 reply marks the dependency down):

@preload(route="demo.health", instances=5, private=True)
async def health_check(headers: dict[str, str], _body: Body):
    if headers.get("type") == "info":
        return {"service": "demo.service", "href": "http://127.0.0.1"}
    return "demo.service is running fine"

Optional dependencies never change the overall status; mandatory ones decide UP/DOWN, and the most recent outcome drives /livenessprobe.

Static content — the engines' public folder

The host serves the files of static.html.folder for any GET or HEAD that no host path, extension route or function claims — the Java engine's key, with the Rust engine's location as its default: resources/public next to the application file, under the resources rule above (a relative value is under the application file's folder, never the working directory; file: prefixes an absolute path as in the Java engine; an empty value turns the service off). A folder is served as its index.html, so resources/public/index.html replaces the landing page at / while /info, /health and the other host paths stay the host's. The content type follows the engines' table by extension — text/javascript, text/css, image/svg+xml, the fonts and images a bundle ships — and is application/octet-stream otherwise; every file carries an ETag and answers If-None-Match with 304, and HTML is served Cache-Control: no-cache, so a redeployed page is revalidated while hashed assets stay cached. Never found, in the engines' error shape: a hidden entry (a segment starting with ., so .. too), a symbolic link that leaves the folder, anything that is not a regular file. With REST automation on, the static-content block of rest.yaml applies to this folder — the no-cache-pages list and the filter function — as in the Java engine; its mime.types section is not ported.

Kubernetes wiring

livenessProbe:
  httpGet: { path: /livenessprobe, port: 8086 }
readinessProbe:
  httpGet: { path: /health, port: 8086 }

The pod presents exactly like an engine pod — one dashboard shape for the whole polyglot estate.