Blog

    Instrumenting Mirth Connect With OpenTelemetry: Message Traces Across Channels, PHI-Free Attributes, Queue Metrics and Linked Logs

    By GauravNovember 28, 20269 mins read
    On this page

    Most hospital interface teams learn about a stuck Mirth channel from a phone call. The Administrator dashboard shows counts per channel, but it does not show how one message moved through four channels, why it slowed down, or how that lines up with the API and database errors the rest of the platform already reports.

    This post is for integration engineers who want Mirth Connect in the same monitoring stack as their other services. It covers the instrumentation options, a trace per message across channels, span attributes that carry no PHI, metrics for queues and errors, and log correlation.

    What does OpenTelemetry instrumentation for Mirth Connect involve?

    Need eyes on your interfaces?

    Our interface monitoring and support page covers how we watch, alert on and support hospital interface engines.

    OpenTelemetry instrumentation for Mirth Connect means emitting traces, metrics and correlated logs from the interface engine in a vendor-neutral format, so each message becomes a trace across its channels and queue depth and errors appear beside other services. Agnotic Technologies adds this instrumentation without putting PHI into the telemetry.

    Nothing about the channels' logic changes. The work is a small library, a few calls in scripts, a Java agent on the server and a collector that decides what leaves the network.

    Why Mirth needs more than its dashboard

    Mirth's own dashboard answers whether a channel is running and how many messages it received, filtered, sent or errored. It does not answer where a single message spent its time across several channels, or which downstream API slowed it.

    Those questions come up in every incident. When results reach a clinic an hour late, the team needs the path of one message, with timings, next to the receiving system's own telemetry, not five screens of separate counters.

    Which instrumentation options does Mirth allow?

    Mirth allows two complementary options: attaching a Java agent to the server process, and calling a custom Java library from channel scripts. The agent captures generic runtime behavior; the library adds message-level spans that only the channel logic can describe.

    OpenTelemetry's zero-code instrumentation for Java uses a Java agent JAR that can be attached to any Java 8 or later application and dynamically injects bytecode to capture telemetry from many popular libraries and frameworks.

    NextGen Healthcare's Mirth Connect wiki says custom Java code packaged as a JAR can be invoked from any JavaScript context, including global and channel scripts, filters, transformers and JavaScript connectors, once the JAR is loaded through a directory resource such as custom-lib.

    • Java agent: added to the server's JVM options, giving JVM metrics and spans for supported libraries without code changes.
    • Custom library: a thin wrapper over the OpenTelemetry API with calls such as start message span and end message span.
    • Script hooks: the library is called from the preprocessor, transformers and postprocessor of the channels that matter.

    Check what the agent actually captures on your Mirth version before relying on it. Treat anything beyond JVM metrics as a bonus, and put the spans you depend on into the library.

    How do you trace one message across channels?

    Trace one message across channels by starting a span when the source accepts it and passing the trace context along with the message to every channel it reaches. Each channel then adds child spans under the same trace.

    OpenTelemetry for Mirth Connect: channels on the Mirth server emit message spans through a custom library and JVM metrics through the Java agent, an OpenTelemetry Collector drops PHI attributes and batches data, and the existing monitoring stack stores traces, metrics and logs, with a lane for PHI rules and retention
    • Root span: created at the inbound channel's source, named by channel and event type.
    • Child spans: one per destination, including the call to the receiving system, with its result status.
    • Context hand-off: the trace context written into a map variable that travels with the message to the next channel.
    • Close out: spans ended in the response or postprocessor stage, so queued time is measured too.

    HL7 v2 messages have no standard header for trace context, so do not add one to the message itself. Keep the context in Mirth's own maps and only send a traceparent header when the destination is an HTTP service that understands it.

    Which span attributes are safe without PHI?

    Safe span attributes describe the processing, not the patient. Channel names, Mirth message ids, event types, destination names, status and timing tell an engineer what happened without revealing who it happened to.

    • Safe: channel id, connector name, message type and trigger event, Mirth's internal message id, status and error class.
    • Hashed only: a sender's message control ID, hashed with a secret so it can be matched during an incident.
    • Never: names, medical record numbers, dates of birth, raw segments, error text that quotes message content.

    Error messages are the usual leak. A parser error often echoes the offending field, so record the error class and position instead of the text.

    Which metrics should Mirth export?

    Mirth should export queue depth per destination, error counts per channel and the age of the oldest queued message. Those three show trouble before a ward does.

    • Queue depth: messages waiting per destination, so a slow consumer stands out.
    • Oldest queued age: the clearest signal that a destination has stopped draining.
    • Errors and filtered counts: per channel, compared with the usual rate for that hour.
    • JVM health: heap, garbage collection and threads from the Java agent.

    Queue figures come from Mirth's channel statistics rather than from spans. A small scheduled job can read them and publish them as OpenTelemetry metrics with channel and destination names as attributes.

    How do logs connect to traces?

    Logs connect to traces when each log line written while handling a message carries that message's trace id. Search the trace id in the log tool and every relevant line appears, from every channel.

    Write channel logs through the same library, which adds the trace and span ids automatically. Keep logged content to processing facts for the same reason as span attributes: logs travel to the same monitoring stack.

    The collector as the control point

    Send all telemetry through an OpenTelemetry Collector inside your network before anything reaches a monitoring vendor. The collector is where a second PHI check, sampling and routing happen.

    • Attribute filter: drop any attribute not on an allowed list, as a safety net for library mistakes.
    • Sampling: keep every error trace and a share of successful ones for busy feeds.
    • Routing: send traces, metrics and logs to the tools your team already uses.

    Check the monitoring vendor's terms before routing anything there. If the vendor could ever receive PHI by mistake, the hospital will want a business associate agreement in place, even with the attribute filter running.

    What goes wrong when instrumenting Mirth?

    Most problems come from instrumenting too much or in the wrong place. The engine is busy, and telemetry should not slow it.

    • PHI in telemetry: a raw message or error text attached to a span for convenience.
    • Broken traces: context not passed through channel writers, so each channel starts a new trace.
    • Spans never ended: a filtered or errored path skips the end call, and spans pile up in memory.
    • Blocking exports: telemetry sent synchronously from scripts, so a slow collector slows the feed.

    Each failure has a simple guard. Use batched, asynchronous exports, end spans in a finally block, test the hand-off through every channel writer, and let the collector reject any attribute that is not on the list.

    A worked example: tracing a lab result feed

    A hospital routes lab results through three channels: an inbound HL7 v2 listener, a routing channel and an outbound channel that posts to a clinic portal API. Results sometimes reach the portal late, and nobody can say where the time goes.

    The team adds the custom library to all three channels, passes trace context between them and starts the Java agent on the server. Within a day, traces show results waiting in the outbound queue while the portal API returns slow responses during a nightly job.

    The portal team moves its job, and an alert on oldest queued age now pages the interface team before clinics notice. No span in the investigation carried a patient name or record number, only channel, event type and timing.

    Who owns what?

    Observability for Mirth spans the interface team, platform engineering and the privacy officer. Each owns a different part.

    • Interface team: the library calls in channels, span names and the allowed attribute list.
    • Platform engineering: the Java agent, the collector, sampling and the monitoring stack.
    • Privacy officer: sign-off on the attribute list and log retention.
    • Receiving system teams: their own telemetry, so traces line up across the boundary.

    How do you check the instrumentation works?

    Check the instrumentation by sending test messages through every path, including filtered, errored and queued ones, and confirming one complete trace per message. Then inspect attributes for anything that looks like patient data.

    • Path test: each route produces one trace with the expected child spans.
    • Outage test: stop a destination and confirm queue metrics and alerts react.
    • PHI scan: search exported attributes and logs for names, identifiers and dates.
    • Load test: compare throughput with and without instrumentation on the busiest channel.

    What are Mirth observability best practices?

    Put message spans in a small custom library, use the Java agent for runtime data, pass trace context between channels and end spans on every path. Keep attributes to an allowed list with no PHI.

    Route telemetry through a collector you control, export queue depth and oldest queued age as metrics, and alert on those before users notice delays.

    How Agnotic can help

    Agnotic instruments Mirth Connect estates with OpenTelemetry: the custom library, channel changes, Java agent setup, collector rules and alerts in your existing monitoring tools. We keep PHI out of telemetry and test the overhead on your busiest feeds.

    Bring your interfaces into one view

    We add tracing, metrics and alerts to Mirth Connect channels.

    Sources

    Frequently Asked Questions

    Mirth runs on Java, so the OpenTelemetry Java agent can attach to the server, and a custom Java library called from channel scripts can add message-level spans.

    Talk to an engineer about your project

    Tell us which feeds cause the most incidents. We will outline spans, metrics and alerts for those channels.