Visitar URL original
feat(extensibility): migrate n8n hook execution to per-workflow MCP tool invocation by rishikunnath2747 · Pull Request #324 · SAP/cloud-sdk-python · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
temp:add span info
  • Loading branch information
rishikunnath2747 committed Sep 18, 2026
commit 1e4ae801818db577d34eeb3832c155e6e50b2534
4 changes: 4 additions & 0 deletions src/sap_cloud_sdk/core/telemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
ATTR_SUMMARY_HOOK_CALL_COUNT,
ATTR_SUMMARY_HAS_INSTRUCTION,
ATTR_SUMMARY_JOULE_STUDIO_GSID,
ATTR_SUMMARY_IS_EXTENSION,
ATTR_SUMMARY_SOLUTION_ID,
resolve_source_info,
build_extension_span_attributes,
reset_tool_call_metrics,
Expand Down Expand Up @@ -98,6 +100,8 @@
"ATTR_SUMMARY_HOOK_CALL_COUNT",
"ATTR_SUMMARY_HAS_INSTRUCTION",
"ATTR_SUMMARY_JOULE_STUDIO_GSID",
"ATTR_SUMMARY_IS_EXTENSION",
"ATTR_SUMMARY_SOLUTION_ID",
"resolve_source_info",
"build_extension_span_attributes",
"reset_tool_call_metrics",
Expand Down
8 changes: 8 additions & 0 deletions src/sap_cloud_sdk/core/telemetry/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def get_extension_context() -> dict[str, Any] | None:
ATTR_SUMMARY_HOOK_CALL_COUNT = "sap.extension.summary.hookCallCount"
ATTR_SUMMARY_HAS_INSTRUCTION = "sap.extension.summary.hasInstruction"
ATTR_SUMMARY_JOULE_STUDIO_GSID = "sap.extension.joule_studio_gsid"
ATTR_SUMMARY_IS_EXTENSION = "sap.extension.isExtension"
ATTR_SUMMARY_SOLUTION_ID = "sap.extension.solutionId"

# ---------------------------------------------------------------------------
# Private state
Expand Down Expand Up @@ -614,6 +616,7 @@ def emit_extensions_summary_span(
has_instruction: bool,
total_duration_ms: float,
joule_studio_gsid: str = "",
solution_id: str = "",
) -> None:
"""Emit a sibling summary span with aggregate extension metrics.

Expand All @@ -637,6 +640,8 @@ def emit_extensions_summary_span(
operations.
joule_studio_gsid: Global solution ID of Joule Studio (empty string
if not available).
solution_id: Solution ID of the contributing extension (empty string
if not available).
"""
total = tool_call_count + hook_call_count + (1 if has_instruction else 0)
attrs = {
Expand All @@ -645,9 +650,12 @@ def emit_extensions_summary_span(
ATTR_SUMMARY_TOOL_CALL_COUNT: tool_call_count,
ATTR_SUMMARY_HOOK_CALL_COUNT: hook_call_count,
ATTR_SUMMARY_HAS_INSTRUCTION: has_instruction,
ATTR_SUMMARY_IS_EXTENSION: True,
}
if joule_studio_gsid:
attrs[ATTR_SUMMARY_JOULE_STUDIO_GSID] = joule_studio_gsid
if solution_id:
attrs[ATTR_SUMMARY_SOLUTION_ID] = solution_id
span = _tracer.start_span("agent_extensions_summary", attributes=attrs)
span.end()

Expand Down
36 changes: 36 additions & 0 deletions src/sap_cloud_sdk/extensibility/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,16 +515,19 @@ class ExtensionSourceMapping:
(e.g., ``"create_ticket"``).
Hook keys are hook IDs (UUIDs) (e.g.,
``"3f5c8c8a-7b4d-4f9c-a4c0-7d5cb1a39f7e"``).
Instruction keys are extension instance IDs (e.g., ``"ext-instance-1"``).
Values are :class:`ExtensionSourceInfo` objects containing the extension's
name, version, and unique identifier.

Attributes:
tools: Mapping of tool name to extension source info.
hooks: Mapping of hook ID to extension source info.
instructions: Mapping of extension instance ID to extension source info.
"""

tools: Dict[str, ExtensionSourceInfo] = field(default_factory=dict)
hooks: Dict[str, ExtensionSourceInfo] = field(default_factory=dict)
instructions: Dict[str, ExtensionSourceInfo] = field(default_factory=dict)

@classmethod
def from_dict(cls, obj: Dict[str, Any]) -> ExtensionSourceMapping:
Expand All @@ -546,6 +549,13 @@ def from_dict(cls, obj: Dict[str, Any]) -> ExtensionSourceMapping:
"extensionVersion": "1",
"extensionId": "a1b2c3d4-..."
}
},
"instructions": {
"ext-instance-1": {
"extensionName": "ServiceNow Extension",
"extensionVersion": "1.0.0",
"extensionId": "ext-instance-1"
}
}
}

Expand All @@ -560,9 +570,14 @@ def from_dict(cls, obj: Dict[str, Any]) -> ExtensionSourceMapping:
"""
raw_tools = obj.get("tools", {})
raw_hooks = obj.get("hooks", {})
raw_instructions = obj.get("instructions", {})
return cls(
tools={k: ExtensionSourceInfo.from_value(v) for k, v in raw_tools.items()},
hooks={k: ExtensionSourceInfo.from_value(v) for k, v in raw_hooks.items()},
instructions={
k: ExtensionSourceInfo.from_value(v)
for k, v in raw_instructions.items()
},
)


Expand Down Expand Up @@ -794,6 +809,27 @@ def get_extension_for_hook(self, hook_id: str) -> Optional[str]:
if self.source and hook_id in self.source.hooks:
return self.source.hooks[hook_id].extension_name
return None

def get_source_info_for_instruction(
self, extension_id: str
) -> Optional[ExtensionSourceInfo]:
"""Look up the full source info for a specific instruction contributor.

Returns the :class:`ExtensionSourceInfo` containing extension name,
version, and ID for the extension that contributed an instruction
fragment. Returns ``None`` when source mapping is not available or
the extension ID is not found.

Args:
extension_id: The extension instance ID used as the key in
``source.instructions`` (e.g., ``"ext-instance-1"``).

Returns:
:class:`ExtensionSourceInfo` for the instruction contributor, or ``None``.
"""
if self.source and extension_id in self.source.instructions:
return self.source.instructions[extension_id]
return None

def get_source_info_for_tool(self, tool_name: str) -> Optional[ExtensionSourceInfo]:
"""Look up the full source info for a specific tool.
Expand Down
7 changes: 4 additions & 3 deletions src/sap_cloud_sdk/extensibility/_ums_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,15 @@ def _build_source_mapping(
mcp_servers: List[McpServer],
hooks: List[Hook],
) -> ExtensionSourceMapping:
"""Build a source mapping from per-node title to contributed tools/hooks.
"""Build a source mapping from per-node title to contributed tools/hooks/instructions.

Each node has a ``title`` (the extension name) and a list of
``capabilityImplementations`` whose tools and hooks were contributed
by that extension.
``capabilityImplementations`` whose tools, hooks, and instructions were
contributed by that extension.
"""
tool_map: Dict[str, ExtensionSourceInfo] = {}
hook_map: Dict[str, ExtensionSourceInfo] = {}
instruction_map: Dict[str, ExtensionSourceInfo] = {}

for node in nodes:
title = node.get("title", "")
Expand Down
Loading