How OpenTelemetry tracing for HAPI FHIR finds slow requests
When FHIR searches or clinical reads slow down, the first question is where the time goes. A trace shows each step of one request, from the HTTP call into the HAPI FHIR server, through the database queries it runs, to any outbound calls, so the team can see whether the delay sits in the server, the database or the network. Metrics can show that latency rose, but they usually cannot show which search, which SQL statement or which downstream call caused it. That is why tracing is often needed before metrics alone are enough, especially when a single slow search type or a few heavy clients are suspected.
OpenTelemetry is an open framework and toolkit for generating, exporting and collecting telemetry: traces, metrics and logs. It is vendor- and tool-agnostic, and it is not a backend. Storage and visualization are handled by separate tools, so the team must choose where traces go. A Collector is usually placed between the server and those tools. It receives telemetry, applies processing such as filtering or batching, and exports it to one or more backends. Running it as a separate component keeps credentials for the backend out of the application and lets the team change backends without redeploying the FHIR server.
Before enabling anything, confirm with the HAPI FHIR documentation which Java agent version, property names and configuration keys match the release you run. Agent names, property keys and supported JDK versions can change between HAPI FHIR releases, so this page does not define them. Check the documentation for your exact version, and check the JDK requirement for that release as well, since the versions page lists JDK requirements per release. Test the setting in a non-production environment first, and record which trace attributes the server emits, because the names used for database and HTTP spans determine how you filter later.
OpenTelemetry Collector documentation describes the agent and gateway roles. Use a gateway if many services send telemetry, and confirm the stability level of each Collector component in its README before you depend on it in production. Decide early who may read traces, because span attributes can include request paths and query parameters, and FHIR search parameters can carry identifiers that are sensitive in a clinical setting.
How telemetry moves from HAPI FHIR to your backend
Telemetry starts in the HAPI FHIR JVM, where the attached OpenTelemetry Java agent instruments requests and database calls and creates spans. The agent exports traces and metrics to an OpenTelemetry Collector, which can run beside the server as an agent or as a shared gateway. The Collector then forwards data to a separate observability backend, which stores and visualizes it. Check where each hand-off crosses the hospital network boundary, and whether the authenticator extensions on the receiver and exporter sides are configured.
Telemetry flows from the server through the Collector to a separate backend.
Configuration options and when each fits
This table compares the main choices for enabling the OpenTelemetry Java agent with HAPI FHIR, from how the agent is attached to where traces go and how the exporter authenticates. Read each row against your environment: a single test server can take the simplest path, while a shared production estate usually needs a Collector and enforced exporter authentication. Property names differ between releases, so confirm every key against the HAPI FHIR documentation for the version you run before you copy it into a configuration.
| Decision | Option | Trade-off | When it fits |
|---|---|---|---|
| How the agent is attached | JVM start parameters with the Java agent jar | Works with any HAPI FHIR deployment that starts a Java process, and changes stay in the start command; each restart needs the same flags | A single test server or a proof of concept where you want to see traces quickly |
| How the agent is attached | Packaged deployment that sets properties through container or Helm values | Settings live in versioned manifests and are reviewed like other infrastructure changes, but the agent file must be present in the image or volume | Shared production estates on Kubernetes where configuration must be reviewed and repeated across environments |
| Where exported data goes | Direct export from the server to a tracing backend | Fewer moving parts, but every server needs backend endpoints and credentials, and changing backends means reconfiguring each server | One server with one backend and a small team that owns both sides |
| Where exported data goes | Through a Collector running as an agent next to the server | Adds a process to run and patch, but lets each node forward to a central point and apply local processing | Several servers on the same hosts or nodes where you want a local buffer and consistent export settings |
| Where exported data goes | Through a Collector running as a gateway that receives from many sources | Centralizes routing, redaction and credentials in one place, so the gateway becomes a critical service to size and monitor | Shared estates with several services, backends or teams that need one policy point for telemetry |
| Exporter authentication | oauth2client extension on the Collector exporter | Adds credentials to outgoing requests from the Collector, so the server does not hold backend secrets; token issuance and rotation must be configured and tested | Production gateways where the backend requires tokens and the credential lifecycle belongs to the platform team |
| Exporter authentication | Network controls alone, such as private addressing and restricted egress | Simple to set up, but any workload that can reach the endpoint can send data, and it does not prove who sent it | A single test server inside a segment that only the server can reach, with a plan to add authentication before wider use |
Setting up the agent and Collector step by step
This sequence takes a HAPI FHIR JPA server from an untraced build to a Collector that receives spans for each search, with metrics arriving on the same path. Each step ends with a check your team can run in its own environment before moving on.
Confirm the HAPI FHIR release and JDK
Your platform team records the HAPI FHIR version and the JDK in use. For HAPI FHIR 8.2.0 and later, the documented requirement is JDK 17, so verify the runtime before changing anything. If you run a later release, confirm its Java requirement in the HAPI FHIR versions documentation. Check:
java -versionon the host or inside the container reports a JDK 17 build, and the server starts cleanly on its current configuration before any agent work begins.Choose the deployment method
Pick the pattern your server already uses: the hapiproject/hapi Docker image, Docker Compose, Spring Boot, a WAR on Tomcat, Jetty or Wildfly, or Kubernetes with the Helm chart. This choice decides where JVM arguments and environment variables are set. The agent must attach to the same JVM that serves FHIR requests, so confirm the exact setting with the team that owns the deployment. Check: write down the single file, values key or environment variable that will carry the agent settings, and confirm it appears in the running process arguments after a restart.
Enable the bundled OpenTelemetry agent
Attach the bundled OpenTelemetry Java agent to the server JVM with a
-javaagentargument, then set the service name and environment attributes so traces can be filtered later. Take the flag path and property names from the HAPI FHIR documentation for your exact version and check them against the release you run. Check: the startup log or process listing shows the agent loaded, and the server's capability statement endpoint still responds, which shows the agent did not break request handling.Point the agent at a Collector endpoint
Set the exporter endpoint to the address of a Collector reachable from the server network, using the protocol and port that the bundled agent documentation specifies. Decide early whether the Collector runs beside the server as an agent or as a shared gateway that receives from several services. Network rules must allow the server to reach the Collector port. Check: the server starts without export errors in its log, and the Collector shows connections from the server host instead of refused or timed-out attempts.
Deploy a Collector pinned to a tested release
Deploy the OpenTelemetry Collector at a fixed release, such as v0.163.0, which was released on October 16, 2026, and record that version in your deployment manifests. Verify the signed artifact, SHA256 checksum and SBOM published with the release before you deploy it, using the OpenTelemetry Collector releases page. Start with one OTLP receiver, a batch processor and one exporter to your backend, and check each component's stability level in its README. Check: the Collector logs show every pipeline started with no configuration validation errors.
Send a test search and find its trace
Run one FHIR search against a known resource type in a non-production environment, using synthetic test data only. Open your tracing backend and locate the trace for that request. A healthy result includes a server span for the HTTP request and a child span for the database query that the search issued. Check: the single search produces one trace containing a database child span, and its duration is consistent with the response time in your access log.
Confirm metrics arrive on the same pipeline
Verify that server and JVM metrics reach your backend through a metrics pipeline in the same Collector, using the receiver and exporter pattern you already validated for traces. Confirm the metric names against what the agent documentation describes for your version, because names vary between releases and backends. Send a few test searches while you watch the series. Check: a server metric series is queryable in the backend, and its latest timestamp advances as test requests arrive.
Lock down the Collector before wider use
Before other teams send telemetry, add authentication to the receiver with an authenticator extension, such as OIDC, and attach credentials to exporter requests with the oauth2client extension where your backend requires them. Follow the Collector configuration best practices for network exposure and secrets handling. Restrict network paths so only known senders reach the receiver. Check: a request without credentials is rejected by the receiver, and the test trace still arrives once the configured credentials are in place.
Finding slow searches and database calls in traces
Once the agent emits spans, five analysis patterns cover most slow-request questions. Each one narrows the cause, from a single request to the database, the JVM, or the search design itself. Confirm the span names and attributes your agent release emits in a test environment before you build queries or dashboards on them.
Isolate slow searches by resource and parameter
Group server spans for FHIR requests by resource type and search parameter set, then sort by duration and count. A few combinations, such as a broad date range on Observation or an unindexed parameter on a large table, often account for most of the latency. Check whether the request URL or operation attributes carry enough detail to separate these cases, and whether query strings with patient identifiers are recorded in traces, since that creates a PHI exposure you must control before export.
JPA server docsSplit request time from SQL time
Compare each slow server span with its child database spans. If most of the duration sits in SQL, the next step is the query plan and index design on the relational database. If the database spans are short but the request is long, look at serialization, interceptors, authorization checks, or time spent waiting for a pooled connection. The gap between parent and child durations is the fastest way to decide which team should look next.
Trace chained and included searches
Chained parameters, _include and _revinclude can fan a single client request into many queries across related resources. Count the child database spans under one request and note how that count changes with the size of the result set. A request that issues dozens of queries for a small page of results points to a search design problem, not a slow database. Confirm how your agent version names and groups these child calls before you rely on the count.
Correlate traces with JVM and pool metrics
Match the time windows of slow traces against JVM garbage collection, heap usage, thread counts and connection pool wait metrics exported alongside the traces. Long pool waits during slow requests suggest the server is short of database connections, while steady heap growth points to a memory problem. Metrics and traces only agree if both use the same service name and resource attributes, so verify that label set in your collector before building the correlation.
Build a baseline before changing indexes
Record request duration percentiles per resource type and search pattern over a representative period before changing any search parameter or index. Repeat the same measurement after each change, so you can see whether latency moved and whether other requests slowed down. Without a baseline, a fix can look successful because traffic dropped, or hide a regression in a search pattern nobody re-ran. Agree the baseline window and load profile with the team that owns the workload.
Why a Collector sits between HAPI FHIR and your backend
The OpenTelemetry Collector is the component that receives telemetry from the HAPI FHIR server's Java agent, processes it, and exports it to the backend you choose. OpenTelemetry itself is not an observability backend, so storage and visualization are separate decisions, and the Collector is the vendor-agnostic seam that lets you change those tools later without re-instrumenting the server. The Collector is licensed under Apache-2.0, and you can run it beside the FHIR server as an agent or centrally as a gateway that accepts data from several sources.
The placement choice is the main trade-off. An agent next to the HAPI FHIR pods keeps the export path short and limits how much telemetry sits in a queue if a central service is slow. A gateway centralizes sampling, filtering, redaction and credential handling, so the rules live in one configuration rather than in every server. For a FHIR workload, that matters because span attributes can carry request details, so decide early which fields are dropped before data leaves your network. Ask your team which of these controls must be enforced centrally for your audit and security reviews.
Collector components do not share one maturity level. Stability is documented in each component's README, and the OpenTelemetry status page gives the overall picture. Before you rely on a processor or exporter in production, check its stated stability in the README, confirm that your chosen distribution includes it, and pin the Collector version you tested. Authenticator extensions, such as OIDC for incoming connections or the oauth2client extension for outgoing exporter requests, are also configured per component, so verify each one against the documentation for your release.
How tracing differs across deployment environments
On a single host, the HAPI FHIR JPA server starter usually runs as a container from the hapiproject/hapi image, with the Collector as another service in the same Compose file or on the same machine. The agent is typically attached through the JVM startup options that the image passes to Java, so the agent jar must be present inside the container or mounted into it. Traces reach the Collector over the local network of the host, which keeps the setup simple but means the host is a single point of failure for telemetry as well as for the server.
- Agent attachment: Usually set through environment variables or the image's Java options, with the agent jar mounted or baked into the image.
- Collector location: Commonly a sibling container on the same Compose network, reached by service name.
- Configuration path: Environment variables in the Compose file or an env file, which the JVM reads at container start.
- Upgrades: Pulling a new image can change the bundled agent version and the exporter defaults, so the agent and environment settings must be rechecked after each pull.
- Restart behavior: Telemetry resumes only when both containers are healthy, so a Collector outage can drop spans unless the exporter queue is sized for it.
Confirm the exact agent path and Java options in the image version you run, and check the Collector configuration before and after every image change.
On Kubernetes, the Helm chart for the JPA server starter deploys the server as pods, and the Collector is usually deployed separately, either as a per-node agent or as a central gateway that many workloads send to. Configuration reaches the JVM through the chart values and the resulting pod environment, so exporter endpoints and service names are best managed as values that are versioned with the chart. Network policies and service discovery decide whether the server pods can reach the Collector at all.
- Agent attachment: Configured through chart values or the container's Java options, with the agent jar supplied by the image or an init container.
- Collector location: A DaemonSet agent on each node or a Deployment gateway, chosen by how much processing you want before export.
- Configuration path: Helm values rendered into a ConfigMap or Secret and then into pod environment variables.
- Upgrades: A chart or image upgrade rolls the pods, so confirm the agent version and exporter endpoint survive the rollout and that old and new pods do not double-count spans.
- Scaling: Each replica emits its own traces and metrics, so resource attributes such as pod name must be set so slow requests can be traced to a specific replica.
Confirm the chart version's agent and exporter settings against the chart's documentation, and check network policy rules between the server namespace and the Collector.
When the server runs as a WAR on Tomcat, Jetty or Wildfly, the agent is attached to the application server's JVM rather than to a container entry point, and each server has its own place for JVM options and environment settings. The Collector is often a separate host or a local process that the application server reaches over the network. Because the operator controls the application server directly, configuration tends to live in server files and service definitions, which must be kept under change control with the WAR.
- Agent attachment: Added through the JVM options of the specific application server, and the exact mechanism differs between Tomcat, Jetty and Wildfly.
- Collector location: Often a dedicated host or a local agent process, reached by the server's configured address.
- Configuration path: Server startup scripts, service unit files or
setenvstyle files, read when the JVM starts. - Upgrades: Replacing the WAR does not change the agent or its settings, but upgrading the application server or Java can change how options are read.
- Drift risk: Settings edited on one node but not others produce partial telemetry, so compare JVM arguments across nodes after every change.
Confirm the exact attachment mechanism for your application server version with its own documentation and verify the agent loads by checking the startup log before relying on traces.
Security and privacy risks in HAPI FHIR tracing
Traces are copies of request data, so every span, attribute and exporter path can expose the same clinical information the FHIR server protects. The risks below connect the instrumentation, the Collector and the trace backend, and each one needs an owner and a check before traces leave the server. HAPI FHIR provides building blocks for access control, but it does not secure the telemetry pipeline around it.
Patient identifiers in span attributes
Java agent instrumentation records HTTP request details, and search URLs can carry patient identifiers, names, dates of birth or clinical values such as diagnosis codes. A span that stores a full query string makes the trace backend a copy of the FHIR data. Before enabling the agent in production, sample real traffic, list the attributes it emits, and decide which fields to drop or redact in the Collector. Confirm the exact attribute set for your agent version with the OpenTelemetry Java documentation.
Unauthenticated Collector receivers
A Collector receiver that accepts OTLP without authentication lets any reachable host write data into your pipeline or flood it. Bind receivers to a private network interface, restrict them with network policy, and place the Collector behind your trust boundary. Where clients span networks, consider an authenticator extension such as OIDC on the receiver to check callers. Confirm which authenticator extensions your Collector distribution includes before you depend on them.
Collector security practicesExporter credentials in plain configuration
Backend tokens or client secrets written directly into the Collector YAML end up in version control, container images and support bundles. Load credentials from environment variables or a secrets manager, and limit who can read the Collector configuration. For exporters that need token-based access, review the oauth2client extension as an option so the Collector obtains and refreshes tokens without storing a static secret in the file. Confirm how your deployment platform injects these values.
Retention and access on the trace backend
Trace stores often keep data longer than teams expect and show full span attributes to anyone with dashboard access. Set a retention period that matches your privacy policy, restrict query access by role, and audit who views raw spans. Ask the backend vendor or project how it handles deletion requests and whether it supports attribute-level redaction. Treat the backend as a system holding protected health information when it receives unredacted spans.
Endpoint hardening from the Collector guidance
The Collector project publishes configuration best practices for securing receivers, exporters and extensions, including limits on exposed ports and avoiding insecure defaults in production. Review your configuration against that guidance on each Collector upgrade, because defaults and component stability differ across releases. Record the review as a change record so auditors can see when endpoints were checked. Document which receivers are enabled and why, so unused receivers do not stay open.
Config best practicesQuestions teams ask before setting up HAPI FHIR tracing
What does OpenTelemetry tracing for HAPI FHIR cost and what drives it?
The cost depends on how much of the platform you want traced and how many places the telemetry must reach. The main components are the scoping and design work, configuring the Java agent in each environment, building the Collector pipeline, connecting a backend, and a review of what the traces contain. The biggest drivers are the number of environments (development, test, staging and production usually each need configuration), the number of trace sources beyond the FHIR server such as gateways or databases, the backend choice, and the authentication and privacy review of exported data. One-time work is the initial build. Recurring costs are the backend hosting and any retainer for upgrades. Ask for a written scope that lists each environment, each source, the backend, and the review steps as separate line items.
How long does a first HAPI FHIR tracing setup take?
No duration has been fixed for this work, so the honest answer depends on your environment. Timing is set by how quickly you can confirm the HAPI FHIR version and JDK in use, whether the server runs in Docker, Kubernetes or an application server, whether a Collector already exists, and how fast your security team approves the fields that will leave the server. Change windows also matter, because enabling the agent means restarting the server. A simple case with one non-production environment and an existing Collector takes less time than a multi-environment rollout with a new backend. Ask the partner to break the schedule into discovery, a non-production rollout, review of trace content, and production cutover.
What must our team provide before tracing work starts?
Gather the inputs that determine how the agent is attached and where data goes. You will need:
- The HAPI FHIR version and the JDK version running in each environment. HAPI FHIR 8.2.0 requires JDK 17, and the HAPI FHIR versions page lists the requirements for each release.
- The deployment method, such as the hapiproject/hapi Docker image, Spring Boot, a WAR on Tomcat, Jetty or Wildfly, or Kubernetes with the Helm chart.
- The tracing backend, the Collector location and the access model for who may view traces.
- Change windows for restarts in each environment.
- Names of the people who approve data fields, since trace attributes can carry request details.
Can our internal team set up HAPI FHIR tracing without a partner?
Yes, many teams can, provided they have engineers who already run the HAPI FHIR server and understand Java services and the OpenTelemetry Collector. The Collector is a vendor-agnostic component that receives, processes and exports telemetry, and it can run as an agent beside services or as a gateway, so the design choice needs experience. Your team should understand how the agent is attached at startup, how exporter settings are configured, which attributes are recorded, and how to verify that a slow search produces a trace you can act on. If that knowledge is spread thin, a partner can shorten the learning curve and leave behind a documented configuration and runbook.
Do we need a retainer for ongoing agent and Collector upgrades?
Not always, but ongoing upkeep is a real recurring task. The OpenTelemetry Collector publishes frequent releases, for example v0.161.0 on September 16, 2026, v0.162.0 on September 29, 2026 and v0.163.0 on October 16, 2026, and its components have mixed stability levels documented in each component's README. Agent versions also need checking against your HAPI FHIR and JDK versions. A retainer covers testing new versions, moving configuration changes through environments and watching for deprecated components. Without one, assign an owner and a monthly review. Ask any partner to state in the scope which upgrades are included, how many environments they cover, and how breaking changes are handled.
What privacy and security checks apply to exported traces?
Traces can carry request paths, query parameters, status codes, database statement text and other attributes, so they need review before they leave the server. Confirm that no patient identifiers or clinical content are captured in span attributes, and that the backend has access controls matching your policy. On the Collector side, the Collector configuration best practices describe how to secure receivers and exporters. Collector authenticator extensions can authenticate incoming connections, for example with OIDC, and add credentials to outgoing requests. HAPI FHIR itself does not provide one security layer, so tracing should sit within your wider access and audit design. Ask for the review to be a named deliverable with written sign-off.
Limits to confirm in your environment
Tracing a HAPI FHIR server touches the agent, the Collector, the backend and the production workload at once. The items below are the points where a plan that looks complete on paper can fail once real traffic arrives, so confirm each one before you roll tracing out beyond a test environment.
Agent version and property names
Confirm which OpenTelemetry Java agent version your HAPI FHIR release expects, and check the exact system property or environment variable names in that version's documentation before writing them into a deployment. Property names change between agent releases, and a misspelled key fails quietly, leaving you with no spans and no error. Record the agent version next to your HAPI FHIR version so an upgrade on either side triggers a recheck. Also confirm the JDK requirement of your HAPI FHIR release, since the agent must run on the same JVM you deploy.
HAPI FHIR versionsDefault spans and sampling
Determine whether the agent's default instrumentation produces the spans you need, such as inbound HTTP requests and JDBC calls, and whether it captures enough detail to tell a slow FHIR search from a slow database statement. Then decide the sampling rate. Low sampling keeps cost down but can drop the very slow requests you are trying to find, while full sampling multiplies storage and overhead. Test with a realistic set of search types, including chained and include searches, before settling on a configuration.
Collector component stability
Each Collector component you plan to use, such as a receiver, processor or exporter, has its own stability level documented in its README. Review those levels for every component in your pipeline, not just the Collector core, and decide which components you can accept at their current maturity. A component marked as beta or alpha may change configuration keys between releases. Pin the Collector distribution version and track release notes so a planned upgrade does not silently change your trace path.
OpenTelemetry statusBackend licence and data residency
Trace data for a FHIR server can carry identifiers, resource types, query parameters and database statements that your compliance team may treat as sensitive. Confirm where the backend stores traces, who can read them, and whether its licence and hosting model fit your data residency rules. A backend that runs inside your own infrastructure keeps the telemetry under your control, but it adds storage, retention and access work that someone must own. Ask the compliance team to review the data fields before traces leave the application host.
Overhead on a busy production server
Instrumentation adds work to every request and every database call, and the cost grows with load and with the span volume the Collector must export. Measure request latency, heap use, CPU and thread counts under a production-like load with tracing on and off, and compare the results against your existing service objectives. Watch the export path too, since a slow or unreachable Collector can build up memory in the application. Set a rollback plan that disables the agent without a redeploy of the application image.
How DeployOpen scopes and supports HAPI FHIR tracing
DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside the client's own infrastructure, including OpenTelemetry tracing for a HAPI FHIR JPA server. The work starts with a written scope that names the environment, the trace backend and the questions the traces must answer.
How we scope
- Written scope lists the HAPI FHIR version, JDK, application server and database the agent must instrument.
- Scope names the collector topology, export destinations and who operates the trace backend.
- Scope defines which slow-search and database-call questions the traces must answer before go-live.
How we build
- Agent is attached to the JPA server, with sampling and exporter settings set in your own configuration.
- Collector pipelines are built with receivers, processors and exporters, with authentication configured on incoming and outgoing connections.
- Test runs confirm that request, search and database spans appear and that no sensitive request data leaves the environment unreviewed.
How we hand over
- Handover includes configuration files, collector settings, a runbook for upgrading the agent and collector, and a record of decisions made.
- Operators receive a list of the dashboards and trace queries used to find slow searches and database calls.
- Your team walks through the setup and the open items agreed in the written scope before the engagement closes.
How we support
- Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
- Ongoing support, agent and collector upgrades and continuous testing are available as a retainer.
- Retainer scope and any changes to the agreed scope are confirmed in writing, so your team knows what is covered.

