dify icon indicating copy to clipboard operation
dify copied to clipboard

feat: add GraphEngine layer node execution hooks

Open hieheihei opened this issue 1 month ago • 5 comments

[!IMPORTANT]

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

part of https://github.com/langgenius/dify/issues/28446

Extend the graph layer to inject OTel context

Screenshots

image image

Checklist

  • [ ] This change requires a documentation update, included: Dify Document
  • [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [x] I've updated the documentation accordingly.
  • [x] I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

hieheihei avatar Nov 24 '25 07:11 hieheihei

python style check failed, you can

class Node:
      @property
      def execution_id(self) -> str:
          return self._node_execution_id

      def ensure_execution_id(self) -> str:
          if not self._node_execution_id:
              self._node_execution_id = str(uuid4())
          return self._node_execution_id

fatelei avatar Dec 10 '25 14:12 fatelei

add unittest:

Hook/event order: on_node_run_start -> NodeRunStartedEvent -> … -> NodeRunSucceeded/Failed -> on_node_run_end.

fatelei avatar Dec 11 '25 00:12 fatelei

hi @fatelei This PR is ready for review, fixed Python style issues and adds unit tests for the Observability layer.

the "hook/event order" you mentioned: events appear to be handled asynchronously.But hooks are executed synchronously in the sequence on_node_run_start → node_execute → on_node_run_end. I believe this ordering is sufficient for the Observability layer.

hieheihei avatar Dec 11 '25 08:12 hieheihei

hi @fatelei This PR is ready for review, fixed Python style issues and adds unit tests for the Observability layer.

the "hook/event order" you mentioned: events appear to be handled asynchronously.But hooks are executed synchronously in the sequence on_node_run_start → node_execute → on_node_run_end. I believe this ordering is sufficient for the Observability layer.

ok

fatelei avatar Dec 11 '25 08:12 fatelei

git commit squash

fatelei avatar Dec 11 '25 13:12 fatelei