Skip to content

Telemetry

Philip Helger edited this page Nov 27, 2026 · 1 revision

Since v5.0.0 phase4 emits traces (spans) and metrics via ph-telemetry, a vendor-neutral telemetry abstraction. See GitHub issue #397 for the background.

phase4 does not register any telemetry backend. Without a backend all spans and metrics are cheap no-ops, so nothing has to be done if telemetry is not needed.

Enabling a backend

The application registers a backend via the ph-telemetry SPIs com.helger.telemetry.ITelemetryTracerSPI and com.helger.telemetry.ITelemetryMeterSPI. ph-telemetry provides bindings for OpenTelemetry (ph-telemetry-otel) and for Java Flight Recorder (ph-telemetry-jfr). See the ph-telemetry README for the details.

Example for OpenTelemetry - add com.helger.telemetry:ph-telemetry-otel to your application and create the two subclasses:

public final class MyTracerSPI extends OtelTelemetryTracerSPI
{
  public MyTracerSPI ()
  {
    super (CPhase4Telemetry.INSTRUMENTATION_SCOPE_NAME, CAS4Version.BUILD_VERSION);
  }
}

public final class MyMeterSPI extends OtelTelemetryMeterSPI
{
  public MyMeterSPI ()
  {
    super (CPhase4Telemetry.INSTRUMENTATION_SCOPE_NAME, CAS4Version.BUILD_VERSION);
  }
}

Register them in META-INF/services/com.helger.telemetry.ITelemetryTracerSPI and META-INF/services/com.helger.telemetry.ITelemetryMeterSPI and initialise the OpenTelemetry SDK at application startup. If the application already registers its own ph-telemetry backend (like phoss AP does), the phase4 spans and metrics are emitted to that backend as well.

Note: the metric instruments are created once, when the class Phase4Metrics is loaded. A meter registered via META-INF/services is always found in time. A meter installed programmatically via TelemetryMetrics.install (...) must be installed before the first message is sent or received.

Data protection

  • Participant identifiers (C1 and C4) are never recorded - neither on spans nor on metrics.
  • Values with a potentially high cardinality (AS4 message ID, signal message ID, conversation ID, RefToMessageId, PMode ID, ebMS service and action, document type and process identifier, server host name) are only used on spans, never as metric attributes.

Spans

All constants are in the class com.helger.phase4.telemetry.CPhase4Telemetry. With the OpenTelemetry binding, nested spans are linked to their parent span (e.g. the SMP lookup and the HTTP attempts are children of the user message span). The trace context is not propagated to the receiving Access Point.

Span name Kind Module Created by Attributes
phase4.incoming.request SERVER phase4-lib AS4RequestHandler.handleRequest - once per incoming AS4 request phase4.outcome, phase4.message.type, phase4.profile.id, phase4.message.id, phase4.pmode.id, phase4.service, phase4.action, phase4.conversation.id (user message), phase4.signal_message.ref_to_message.id (signal message, if present) - for a signal message phase4.message.id is its own message ID; event phase4.duplicate for a duplicate
phase4.outgoing.user_message INTERNAL phase4-lib AbstractAS4UserMessageBuilder.sendMessageAndCheckForReceipt - all profile specific senders phase4.send.result, phase4.profile.id, phase4.message.id, phase4.pmode.id, phase4.service, phase4.action, phase4.conversation.id (only if set explicitly on the builder), phase4.signal_message.id and phase4.signal_message.ref_to_message.id (of the received signal message, if present)
phase4.http.send CLIENT phase4-lib BasicHttpPoster.sendGenericMessage - once per HTTP attempt, also for every retry phase4.outcome, server.address, error.type, http.response.status_code (if the HTTP response was turned into an error)
phase4.smp.lookup CLIENT phase4-dynamic-discovery AS4EndpointDetailProviderPeppol, AS4EndpointDetailProviderBDXR and AS4EndpointDetailProviderBDXR2 - once per SMP lookup phase4.outcome, phase4.smp.provider, phase4.transport_profile.id, phase4.doctype.id, phase4.process.id, phase4.retry_feasible (on error)

Exceptions are recorded on the span, and the span status is set to error, if the operation was not successful.

Metrics

All durations are in seconds, all sizes in bytes.

Metric name Type Attributes Description
phase4.incoming.requests Counter phase4.outcome, phase4.message.type, phase4.profile.id Incoming AS4 requests handled
phase4.incoming.duration Histogram same as above Duration of handling an incoming AS4 request, including the invocation of the synchronous SPIs
phase4.incoming.size Histogram same as above Number of bytes read from an incoming AS4 request
phase4.incoming.duplicates Counter phase4.duplicate.handling, phase4.profile.id Incoming AS4 messages detected as duplicates
phase4.incoming.ebms_errors Counter phase4.ebms.error.code, phase4.profile.id ebMS errors created while handling incoming AS4 requests
phase4.outgoing.user_messages Counter phase4.send.result, phase4.profile.id AS4 user messages sent via sendMessageAndCheckForReceipt
phase4.outgoing.duration Histogram same as above Duration of sending an AS4 user message until the response is evaluated, including SMP lookup and HTTP retries
phase4.http.attempts Counter phase4.outcome, error.type, http.response.status_code Outgoing HTTP transmission attempts
phase4.http.duration Histogram same as above Duration of one outgoing HTTP transmission attempt
phase4.http.request.size Histogram same as above Size of the outgoing HTTP request body - only if the length is known in advance, which is not the case for streamed MIME messages
phase4.http.retries Counter phase4.http.retry.classification Outgoing HTTP retries scheduled (RETRY or RETRY_IF_REPLAY_SAFE)
phase4.smp.lookups Counter phase4.outcome, phase4.smp.provider, phase4.transport_profile.id, phase4.retry_feasible (on error) SMP endpoint lookups
phase4.smp.lookup.duration Histogram same as above Duration of one SMP endpoint lookup

Attribute values

Attribute Values
phase4.outcome success; ebms_error (incoming request answered with an ebMS error); error (HTTP attempt or SMP lookup failed); exception (ended by an exception)
phase4.message.type user_message, ping, receipt, error, pull_request, unknown
phase4.send.result The ID of EAS4UserMessageSendResult (e.g. success, transport-error, as4-error-msg-received) or exception
phase4.duplicate.handling The ID of EAS4IncomingDuplicateHandling (error, dismiss, process)
phase4.smp.provider peppol, bdxr1, bdxr2

Not covered

  • The availability of databases or other resources of the application - phase4 itself has no database
  • Structured logging - this is a configuration of the logging backend (e.g. a JSON encoder for Logback or Log4j)
  • The profile specific SBDH or XHE data (e.g. the document type of an incoming Peppol message) - the AS4 Service and Action values are recorded on the spans instead

Clone this wiki locally