Sticky wire-exchange trace id derived from message content - #771
Merged
Merged
Conversation
ISOMsg.getTraceId() returns an id derived from the MTI class and fields 3, 7, 11, 12, 41 and 42 (configurable system-wide), so a request and its response share one id with no wire carrier and regardless of protocol version. An explicitly asserted id (setTraceId) is kept as a transient claim, copied by clone and never packed; a message without key fields gets a random id minted once. Channel send and receive events carry the message's id as trace-id, the socket UUID moves to a session tag, and trace-claimed records a claim that differs from the effective id. IncomingListener puts the id in the Context under ContextConstants.TRACE_ID, the TransactionManager uses it for the transaction event, and SendResponse claims it on the response. Closes #769
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #769.
What
One trace id per wire exchange, derived from message content so request and response share it with no carrier on the wire and regardless of protocol version.
ISOMsg
naturalTraceId(): first two MTI digits plus the trace-id fields present (default 3, 7, 11, 12, 41, 42, trimmed; 37 and 32 are excluded because a server often mints them, 7 and 12 keep a wrapped STAN from linking to old exchanges), hashed to a 32-hex UUID.nullwhen none of the key fields is present.setTraceIdFields(int...)tunes the field list system-wide.setTraceId(String)/getClaimedTraceId(): an explicitly asserted id. Transient, copied byclone, never packed.getTraceId(): the effective id. Natural when computable, else the claim, else a random id minted once and kept as the claim.BaseChannel send and receive events:
trace-id= the message's effective id; newsessiontag = socket UUID (which used to be the trace id);trace-claimed= the claimed id, only when it differs from the effective one.IncomingListener puts
ContextConstants.TRACE_ID(new) into the Context.TransactionManager uses the Context trace id for the transaction event, falling back to the per-transaction id when absent.
SendResponse claims the Context trace id on the response when it has no claim of its own, so a response whose key fields changed still links back through
trace-claimed.Not changed
No wire field. No thread-locals. LogEvent trace-id format stays 32 hex. Session events in ISOServer are unchanged.
Behaviour notes
QueryHost).Tests
ISOMsgTest: request/response share the natural id, a different STAN differs, claim copied bycloneand never overrides the natural id, a message without key fields gets a stable minted id.IncomingListenerTest(new): the queued Context carries the message's id.ISOServerTest.testChannelEventsCarryTheExchangeTraceIdAndSessionTag(new): a real client-to-server exchange; the client's send event and the server's receive event carry the sametrace-id, both carrysession, neither carriestrace-claimed.:jpos:testand:jpos:javadocpass.Release note
Channel
send/receiveevents:trace-idnow identifies the wire exchange rather than the connection; the connection id moved to thesessiontag. Consumers that joined channel events ontrace-idper connection should usesession.