Skip to content

feat(008): Plugin observability — test run ID correlation and FFI log sink#537

Merged
rholshausen merged 3 commits into
masterfrom
feat/008-plugin-observability-and-logging
Jun 24, 2026
Merged

feat(008): Plugin observability — test run ID correlation and FFI log sink#537
rholshausen merged 3 commits into
masterfrom
feat/008-plugin-observability-and-logging

Conversation

@rholshausen

Copy link
Copy Markdown
Contributor

Summary

Implements the pact-reference side of proposal 008 — Plugin observability and logging. Requires pact-plugin-driver ≥ 1.0.0-beta.5 (released via pact-plugins PRs #100 and #101).

pact_consumer

  • Added uuid (v4) as an optional dependency under the plugins feature.
  • Generates a UUID and sets it as the thread-local test run ID via pact_plugin_driver::test_context::set_test_run_id immediately before every configure_interaction call in RequestBuilder, ResponseBuilder, MessageInteractionBuilder, and SyncMessageInteractionBuilder. The driver then forwards testContext.testRunId to V2-capable plugins so their log entries can be correlated with a specific test.

pact_ffi

  • log/plugin_sink.rs (new): FfiPluginLogSink implementing PluginLogSink. Buffers every plugin log entry keyed by plugin instance ID. Optionally forwards entries to a registered C callback (PluginLogCallback) for live streaming.
  • Registers FfiPluginLogSink with the driver in pactffi_init and pactffi_init_with_log_level via an OnceLock guard (set up exactly once).
  • Three new exported functions:
    • pactffi_set_test_run_id(test_run_id: *const c_char) — set the thread-local test run UUID forwarded in plugin request testContext
    • pactffi_register_plugin_log_callback(callback) — register a C function pointer called for each plugin log entry as it arrives
    • pactffi_get_plugin_logs(plugin_instance_id: *const c_char) -> *const c_char — retrieve all buffered log entries for a plugin instance as newline-delimited JSON; caller frees with pactffi_string_delete

Test plan

  • cargo check / cargo build passes across the workspace
  • cargo test --package pact_ffi all pass
  • Verify a V2-capable plugin receives testContext.testRunId during configure_interaction when called from pact_consumer
  • Verify pactffi_get_plugin_logs returns structured entries after an FFI-driven test that uses a plugin

🤖 Generated with Claude Code

rholshausen and others added 3 commits June 23, 2026 16:23
… sink

Implements the pact-reference side of proposal 008 (Plugin observability
and logging), depending on pact-plugin-driver 1.0.0-beta.5.

pact_consumer:
- Add uuid (v4, optional) under the plugins feature
- Generate a UUID and set it as the thread-local test run ID immediately
  before each configure_interaction call in RequestBuilder, ResponseBuilder,
  MessageInteractionBuilder, and SyncMessageInteractionBuilder so that the
  driver forwards testContext.testRunId to V2 plugins for log correlation

pact_ffi:
- Add log/plugin_sink.rs: FfiPluginLogSink implementing PluginLogSink;
  buffers every plugin log entry by plugin instance ID and optionally
  forwards to a registered C callback (PluginLogCallback)
- Register FfiPluginLogSink in pactffi_init and pactffi_init_with_log_level
  via an OnceLock guard so it is set up exactly once on FFI initialisation
- New exported functions:
    pactffi_set_test_run_id        — set thread-local test run UUID
    pactffi_register_plugin_log_callback — register C callback for live log forwarding
    pactffi_get_plugin_logs        — retrieve buffered log entries as newline-delimited JSON

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…t_matching

Generate a UUID and set it as the thread-local test run ID immediately
before calling match_contents in the plugin body comparison path, so that
the driver forwards testContext.testRunId to V2 plugins during verification.

Also bumps pact-plugin-driver to ~1.0.0-beta.5 in pact_matching.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… only in pact_matching

In pact_verifier, generate a UUID at the start of verify_interaction so
that all plugin calls for a single interaction (prepare_validation,
verify_interaction, and body comparison via pact_matching) share the same
test run ID for log correlation.

Update pact_matching to only generate a fallback UUID when no test run ID
is already set on the thread, so it does not override the one set by the
verifier.

Also bumps pact-plugin-driver to ~1.0.0-beta.5 in pact_verifier.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rholshausen rholshausen merged commit 40318b1 into master Jun 24, 2026
29 of 30 checks passed
@rholshausen rholshausen deleted the feat/008-plugin-observability-and-logging branch June 24, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant