Skip to content

feat(governance): add track_event for custom telemetry to /runtime/log#1745

Open
viswa-uipath wants to merge 1 commit into
mainfrom
feat/traces-api
Open

feat(governance): add track_event for custom telemetry to /runtime/log#1745
viswa-uipath wants to merge 1 commit into
mainfrom
feat/traces-api

Conversation

@viswa-uipath

@viswa-uipath viswa-uipath commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds track_event to GovernanceService and UiPathPlatformGovernanceProvider for posting custom telemetry events to POST /agenticgovernance_/api/v1/runtime/log. The server forwards each event to App Insights as a customEvents row.

  • GovernanceService.track_event(*, event_name, data=None, operation_id=None) + async — POSTs { eventName, data? } to /runtime/log. eventName must be non-empty; data is included only when provided.
  • x-uipath-operation-id header — caller can supply operation_id to correlate events from one logical request (becomes App Insights operation_Id). When omitted, falls back to resolve_trace_id() so events from the same agent trace correlate automatically. When no source resolves, the header is omitted and App Insights generates its own id per event.
  • UiPathPlatformGovernanceProvider.track_event(*, ...) + async — thin delegate so runtime consumers can emit events through the protocol-adapter surface without importing the platform service directly.

Bumps: uipath-platform 0.1.73 → 0.1.74.

Design choices

  • Public ergonomic signature, matching compensate(*, ...)track_event(*, event_name, data=None, operation_id=None) follows the same kwarg-only pattern already established on the service; no request-object wrapper.
  • operation_id fallback to resolve_trace_id(), not required — events emitted from inside an OTel-traced agent flow automatically get the canonical trace id as their operation_Id. Callers in background pools (where OTel context is thread-local and lost) pass operation_id explicitly; callers with neither leave App Insights to assign one per event.
  • Reuses _build_org_scoped_requestUIPATH_SERVICE_URL_AGENTICGOVERNANCE override + routing-header injection work for /runtime/log without extra plumbing. Override redirects to {override}/api/v1/runtime/log and replaces the platform router's tenant/account headers.
  • No new core protocoltrack_event is platform-specific telemetry, not a runtime contract. Adding a protocol can be done later if uipath-runtime consumers need to swap in fakes.
  • @traced(name="governance_track_event", ...) on both sync/async — matches the trace span names already used for retrieve_policy and compensate.

Out of scope (follow-ups)

  • A core protocol for track_event if/when a runtime consumer needs constructor-injected fakes.

Test plan

  • ruff check . / ruff format --check . — clean
  • mypy src testsSuccess: no issues found in 201 source files
  • 1301 passed, 7 skipped (LLM creds), 4 deselected — full uipath-platform suite
  • 12 new tests specifically for track_event:
    • TestTrackEvent (8): name-only payload; data included when provided; caller operation_id header; trace-id fallback via resolve_trace_id(); caller value wins over fallback; header omitted when no source resolves; UIPATH_ORGANIZATION_ID missing raises ValueError; HTTP error raises EnrichedException.
    • TestTrackEventAsync (1): async variant — payload shape + trace-id fallback.
    • TestServiceUrlOverride (+1): UIPATH_SERVICE_URL_AGENTICGOVERNANCE redirects /runtime/log and preserves x-uipath-operation-id.
    • TestDelegation (+2): provider delegation for sync + async.

🤖 Generated with Claude Code

Development Packages

uipath

[project]
dependencies = [
  # Exact version (copy-paste ready):
  "uipath==2.11.10.dev1017456915",

  # Any version from this PR (uncomment to use a range instead):
  # "uipath>=2.11.10.dev1017450000,<2.11.10.dev1017460000",
]

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
publish-url = "https://test.pypi.org/legacy/"
explicit = true

[tool.uv.sources]
uipath = { index = "testpypi" }
uipath-platform = { index = "testpypi" }

[tool.uv]
override-dependencies = ["uipath-platform==0.1.74.dev1017456915"]

Copilot AI review requested due to automatic review settings June 24, 2026 06:57
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-integrations labels Jun 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a platform-specific telemetry hook to the uipath-platform governance surface so runtime consumers can emit custom events to the agentic governance ingress (POST .../api/v1/runtime/log), with optional correlation via x-uipath-operation-id.

Changes:

  • Add GovernanceService.track_event() / track_event_async() to POST {eventName, data?} to /runtime/log, with operation_id falling back to resolve_trace_id().
  • Add UiPathPlatformGovernanceProvider.track_event() / track_event_async() delegation methods.
  • Bump uipath-platform version 0.1.73 → 0.1.74 (and lockfile).

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/uipath-platform/src/uipath/platform/governance/_governance_service.py Adds the new /runtime/log client methods and operation-id header behavior.
packages/uipath-platform/src/uipath/platform/governance/_governance_provider.py Exposes track_event through the provider adapter via thin delegation.
packages/uipath-platform/tests/services/test_governance_service.py Adds sync/async tests covering payload shape, operation-id behavior, override routing, and error paths.
packages/uipath-platform/tests/services/test_governance_provider.py Adds delegation tests for the provider’s sync/async track_event methods.
packages/uipath-platform/pyproject.toml Version bump to 0.1.74.
packages/uipath-platform/uv.lock Lockfile update reflecting the version bump.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

viswa-uipath added a commit that referenced this pull request Jun 24, 2026
…ockfile

track_event / track_event_async now reject empty or whitespace-only
event_name with a ValueError at call time instead of round-tripping
the platform's own 4xx (per Copilot review on #1745). Documented in
the Raises section and covered by parametrized tests on both the sync
and async variants.

Also regenerates packages/uipath/uv.lock so it tracks the bumped
uipath-platform 0.1.74 — the prior CI run failed `uv sync --locked`
because the lockfile still referenced 0.1.73.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
GovernanceService.track_event(*, event_name, data=None, operation_id=None)
posts to /runtime/log, which the server forwards to App Insights as a
customEvents row. Both sync and async variants are provided.

event_name is validated client-side — empty or whitespace-only values
raise ValueError before any URL/header work, so callers fail fast
with a clear error instead of round-tripping the platform's 4xx.

The optional operation_id becomes the x-uipath-operation-id header
that the server stamps as App Insights operation_Id on every emitted
event — events sharing an id are queryable together in KQL. When the
caller omits operation_id, it falls back to resolve_trace_id() so
events from the same agent trace correlate automatically; when no
source resolves, the header is omitted and App Insights generates its
own id per event.

UiPathPlatformGovernanceProvider exposes thin track_event /
track_event_async delegates so runtime consumers can emit events
through the protocol-adapter surface without importing the platform
service directly.

Bumps uipath-platform 0.1.73 → 0.1.74.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@viswa-uipath viswa-uipath added the build:dev Create a dev build from the pr label Jun 24, 2026
@github-actions

Copy link
Copy Markdown

🚨 Heads up: uipath-langchain cross-tests are FAILING 🚨

Your changes may break the uipath-langchain-python integration.

⚠️ These checks are NOT enforced by branch protection rules. Please review the failures before merging.

🔍 Inspect the failed run →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build:dev Create a dev build from the pr test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants