Skip to content

Commit eb27823

Browse files
NiteshDhanpalclaude
andcommitted
chore(tracing): TEMP traceparent probes across ACP->Temporal chain
Debug-only: log the active W3C traceparent at every hop (acp.handle_jsonrpc -> before_create_task -> process_request bg-task -> svc.send_event/submit_task -> client.send_signal/start_workflow [+ live interceptor list] -> worker.activity. start_span) to pinpoint where async trace context is dropped. Grep "[TP-DEBUG]". Remove before merge (rg TP-DEBUG / delete _tp_debug.py). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 044b3f4 commit eb27823

5 files changed

Lines changed: 51 additions & 0 deletions

File tree

src/agentex/lib/core/clients/temporal/temporal_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from temporalio.converter import PayloadCodec, DataConverter
1111

1212
from agentex.lib.utils.logging import make_logger
13+
from agentex.lib.utils._tp_debug import log_tp # TEMP(obs-debug)
1314
from agentex.lib.utils.model_utils import BaseModel
1415
from agentex.lib.core.clients.temporal.types import (
1516
TaskStatus,
@@ -157,6 +158,11 @@ async def start_workflow(
157158
**kwargs: Any,
158159
) -> str:
159160
temporal_retry_policy = TemporalRetryPolicy(**retry_policy.model_dump(exclude_unset=True))
161+
try:
162+
_ics = [type(i).__name__ for i in self.client.config().get("interceptors", [])]
163+
except Exception as _e: # pragma: no cover - debug only
164+
_ics = [f"<err:{_e}>"]
165+
log_tp("client.start_workflow(before start)", interceptors=_ics) # TEMP(obs-debug)
160166
workflow_handle = await self.client.start_workflow(
161167
*args,
162168
retry_policy=temporal_retry_policy,
@@ -174,6 +180,12 @@ async def send_signal(
174180
payload: dict[str, Any] | list[Any] | str | int | float | bool | BaseModel,
175181
) -> None:
176182
handle = self.client.get_workflow_handle(workflow_id=workflow_id)
183+
# TEMP(obs-debug): also report how many interceptors the live client has
184+
try:
185+
_ics = [type(i).__name__ for i in self.client.config().get("interceptors", [])]
186+
except Exception as _e: # pragma: no cover - debug only
187+
_ics = [f"<err:{_e}>"]
188+
log_tp("client.send_signal(before handle.signal)", wf=workflow_id, interceptors=_ics) # TEMP(obs-debug)
177189
await handle.signal(signal, payload) # type: ignore[misc]
178190

179191
async def query_workflow(

src/agentex/lib/core/temporal/services/temporal_task_service.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from agentex.types.agent import Agent
99
from agentex.types.event import Event
1010
from agentex.protocol.acp import SendEventParams, CreateTaskParams, InterruptTaskParams
11+
from agentex.lib.utils._tp_debug import log_tp # TEMP(obs-debug)
1112
from agentex.lib.environment_variables import EnvironmentVariables
1213
from agentex.lib.core.clients.temporal.types import WorkflowState
1314
from agentex.lib.core.temporal.types.workflow import SignalName
@@ -67,6 +68,7 @@ async def submit_task(self, agent: Agent, task: Task, params: dict[str, Any] | N
6768
timeout_seconds = self._env_vars.WORKFLOW_EXECUTION_TIMEOUT_SECONDS
6869
execution_timeout = timedelta(seconds=timeout_seconds) if timeout_seconds and timeout_seconds > 0 else None
6970
with _acp_dispatch_span(f"acp.task_create:{task.id}"):
71+
log_tp("svc.submit_task(before start_workflow)", task=task.id) # TEMP(obs-debug)
7072
return await self._temporal_client.start_workflow(
7173
workflow=self._env_vars.WORKFLOW_NAME,
7274
arg=CreateTaskParams(
@@ -89,6 +91,7 @@ async def get_state(self, task_id: str) -> WorkflowState:
8991

9092
async def send_event(self, agent: Agent, task: Task, event: Event, request: dict | None = None) -> None:
9193
with _acp_dispatch_span(f"acp.event_send:{task.id}"):
94+
log_tp("svc.send_event(before send_signal)", task=task.id) # TEMP(obs-debug)
9295
return await self._temporal_client.send_signal(
9396
workflow_id=task.id,
9497
signal=SignalName.RECEIVE_EVENT.value,

src/agentex/lib/core/tracing/trace.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from agentex import Agentex, AsyncAgentex
1111
from agentex.types.span import Span
1212
from agentex.lib.utils.logging import make_logger
13+
from agentex.lib.utils._tp_debug import log_tp # TEMP(obs-debug)
1314
from agentex.lib.utils.model_utils import recursive_model_dump
1415
from agentex.lib.core.tracing.obs_ids import obs_correlation
1516
from agentex.lib.core.tracing.obs_span import (
@@ -151,6 +152,7 @@ def start_span(
151152
# _in_temporal_activity().
152153
id = str(uuid.uuid4())
153154
if _in_temporal_activity():
155+
log_tp("worker.activity.start_span", span=name, biz_trace=self.trace_id) # TEMP(obs-debug)
154156
tag_ambient_obs_span(business_span_id=id, business_trace_id=self.trace_id)
155157
obs_handle = None
156158
obs = obs_correlation()
@@ -331,6 +333,7 @@ async def start_span(
331333
# _in_temporal_activity().
332334
id = str(uuid.uuid4())
333335
if _in_temporal_activity():
336+
log_tp("worker.activity.start_span", span=name, biz_trace=self.trace_id) # TEMP(obs-debug)
334337
tag_ambient_obs_span(business_span_id=id, business_trace_id=self.trace_id)
335338
obs_handle = None
336339
obs = obs_correlation()

src/agentex/lib/sdk/fastacp/base/base_acp_server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
)
2727
from agentex.lib.utils.logging import make_logger, ctx_var_request_id
2828
from agentex.protocol.json_rpc import JSONRPCError, JSONRPCRequest, JSONRPCResponse
29+
from agentex.lib.utils._tp_debug import log_tp # TEMP(obs-debug)
2930
from agentex.lib.utils.model_utils import BaseModel
3031
from agentex.lib.utils.registration import register_agent
3132

@@ -197,6 +198,8 @@ async def _handle_jsonrpc(self, request: Request):
197198
params_data["request"] = {"headers": custom_headers}
198199
params = params_model.model_validate(params_data)
199200

201+
log_tp("acp.handle_jsonrpc", method=method, inbound=request.headers.get("traceparent")) # TEMP(obs-debug)
202+
200203
if method in RPC_SYNC_METHODS:
201204
handler = self._handlers[method]
202205
result = await handler(params)
@@ -223,6 +226,7 @@ async def _handle_jsonrpc(self, request: Request):
223226
return JSONRPCResponse(id=None)
224227

225228
# For regular requests, start processing in background but return immediately
229+
log_tp("acp.before_create_task", method=method) # TEMP(obs-debug)
226230
asyncio.create_task(
227231
self._process_request(rpc_request.id, method, params)
228232
)
@@ -304,6 +308,7 @@ async def _process_request(
304308
):
305309
"""Process a request in the background"""
306310
try:
311+
log_tp("acp.process_request(bg-task)", method=method) # TEMP(obs-debug)
307312
handler = self._handlers[method]
308313
await handler(params)
309314
# Note: In a real implementation, you might want to store the result somewhere

src/agentex/lib/utils/_tp_debug.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# TEMP(obs-debug): remove after diagnosing async-trace propagation.
2+
# Logs the W3C traceparent derived from the CURRENT active OpenTelemetry context
3+
# at each hop of the ACP ingress -> Temporal start/signal -> workflow -> activity
4+
# chain, so we can see exactly where the trace context is dropped. Grep the agent
5+
# logs for "[TP-DEBUG]".
6+
from __future__ import annotations
7+
8+
from agentex.lib.utils.logging import make_logger
9+
10+
logger = make_logger("tp_debug")
11+
12+
13+
def active_traceparent() -> str:
14+
"""W3C traceparent for the current active OTel context, or a marker string."""
15+
try:
16+
from opentelemetry.propagate import inject
17+
18+
carrier: dict[str, str] = {}
19+
inject(carrier)
20+
return carrier.get("traceparent", "<none>")
21+
except Exception as exc: # pragma: no cover - debug only
22+
return f"<err:{exc}>"
23+
24+
25+
def log_tp(where: str, **extra: object) -> None:
26+
"""Emit a one-line [TP-DEBUG] log: where + current traceparent + any extras."""
27+
kv = " ".join(f"{k}={v}" for k, v in extra.items())
28+
logger.info("[TP-DEBUG] %s traceparent=%s %s", where, active_traceparent(), kv)

0 commit comments

Comments
 (0)