Correlation Capabilities
MATLAB does not provide a built-in, automated mechanism to embed a unique deployment identifier that propagates from the compiler.build process directly into the MATLAB Runtime (MCR) logs. Correlation between these two streams must be implemented manually by the developer.
Implementation Strategy
To establish a trace between a specific build and its runtime failures, you must inject a unique identifier (such as a UUID or build timestamp) at the time of compilation and ensure the application emits this ID upon startup.
- Build Phase: Generate a unique Build ID during your CI/CD process. Pass this ID into your MATLAB code as a constant or a configuration file included in the build artifacts.
- Runtime Phase: Program the compiled application to print this Build ID to
stdout or stderr as the first action in the main entry function.
- Aggregation: Use your log aggregator to index the runtime logs by this printed ID, allowing you to map the failure back to the corresponding
compiler.build log.
MCR Versioning and Parseability
The MCR does not natively emit machine-parseable JSON events for versioning. It primarily outputs unstructured text to stderr. While you can adjust verbosity using the MCR_LOG_LEVEL environment variable to get more detail without a reinstall, this output remains text-based. To achieve machine-parseable versioning, you must wrap the application execution in a script that captures the MCR banner and converts it to JSON before forwarding it to your logging stack.
Preserving Docker Environment Variables
The MCR does not automatically log environment variables during a crash. If your entrypoint script redirects stdout and stderr but fails to capture the environment, license-checkout or path-resolution failures will remain invisible. To preserve this data, modify your Docker entrypoint to dump critical variables to the log stream before executing the binary:
# Example entrypoint snippet
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH" > /proc/1/fd/1
echo "LICENSE_HOST: $LICENSE_HOST" > /proc/1/fd/1
exec "./your_compiled_app" "$@"
Verification and Assumptions
These recommendations assume a standard Linux-based Docker deployment using a recent version of the MATLAB Compiler. To verify the setup, run your container with MCR_LOG_LEVEL=debug and confirm that your manually injected Build ID appears in the logs before any runtime errors occur.
Missing Detail: Are you using a standalone executable or a shared library (CTF)? If using a shared library, the correlation ID must be passed via the host application's API calls rather than command-line arguments.