This is an automated email from the ASF dual-hosted git repository.

zqr10159 pushed a commit to branch 2.0.0
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git


The following commit(s) were added to refs/heads/2.0.0 by this push:
     new a306dfc748 Carry entity context in response handoffs
a306dfc748 is described below

commit a306dfc748a1c2af6ffee5336ab3eabe5186b2e7
Author: Logic <[email protected]>
AuthorDate: Tue Jun 9 20:07:46 2026 +0800

    Carry entity context in response handoffs
---
 .../dto/handoff/EntityResponseHandoffInfo.java     |  6 ++++
 .../dto/EvidenceDtoMigrationTest.java              | 11 +++++--
 .../impl/EntityObservabilityGatewayImpl.java       | 34 +++++++++++++++++++++-
 .../impl/EntityObservabilityGatewayImplTest.java   | 13 +++++++++
 4 files changed, 60 insertions(+), 4 deletions(-)

diff --git 
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/observability/dto/handoff/EntityResponseHandoffInfo.java
 
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/observability/dto/handoff/EntityResponseHandoffInfo.java
index 2c16ceb080..ff7c4b6ad6 100644
--- 
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/observability/dto/handoff/EntityResponseHandoffInfo.java
+++ 
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/observability/dto/handoff/EntityResponseHandoffInfo.java
@@ -40,6 +40,12 @@ public class EntityResponseHandoffInfo {
 
     private String content;
 
+    private Long entityId;
+
+    private String entityType;
+
+    private String entityName;
+
     private String traceId;
 
     private String spanId;
diff --git 
a/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/observability/dto/EvidenceDtoMigrationTest.java
 
b/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/observability/dto/EvidenceDtoMigrationTest.java
index 9c8f57194c..79c4a476d9 100644
--- 
a/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/observability/dto/EvidenceDtoMigrationTest.java
+++ 
b/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/observability/dto/EvidenceDtoMigrationTest.java
@@ -69,9 +69,11 @@ class EvidenceDtoMigrationTest {
         );
 
         EntityResponseHandoffInfo traceHandoff = new EntityResponseHandoffInfo(
-                "trace-1", "open", "critical", "checkout", "trace content", 
"trace-1", "span-1",
-                "checkout", "commerce", "ERROR", "trace_id='trace-1'", 
"platform", "checkout-system",
-                "prod", 1000L, 2000L, "otlp", "trace", codeNavigationHint, 
"/entities/1", "Back to entity"
+                "trace-1", "open", "critical", "checkout", "trace content",
+                1L, "service", "Checkout API", "trace-1", "span-1", 
"checkout", "commerce",
+                "ERROR", "trace_id='trace-1'",
+                "platform", "checkout-system", "prod", 1000L, 2000L, "otlp", 
"trace",
+                codeNavigationHint, "/entities/1", "Back to entity"
         );
         EntityResponseHandoffsInfo handoffsInfo = new 
EntityResponseHandoffsInfo(
                 null, null, null, traceHandoff, null, null
@@ -81,5 +83,8 @@ class EvidenceDtoMigrationTest {
         assertEquals("trace-1", logEvidence.getTraceId());
         assertEquals("checkout", traceEvidence.getServiceName());
         assertEquals("trace-1", handoffsInfo.getTraces().getTraceId());
+        assertEquals(1L, handoffsInfo.getTraces().getEntityId());
+        assertEquals("service", handoffsInfo.getTraces().getEntityType());
+        assertEquals("Checkout API", handoffsInfo.getTraces().getEntityName());
     }
 }
diff --git 
a/hertzbeat-observability/src/main/java/org/apache/hertzbeat/observability/shared/service/impl/EntityObservabilityGatewayImpl.java
 
b/hertzbeat-observability/src/main/java/org/apache/hertzbeat/observability/shared/service/impl/EntityObservabilityGatewayImpl.java
index b21b6d109e..5ac0bdc5f4 100644
--- 
a/hertzbeat-observability/src/main/java/org/apache/hertzbeat/observability/shared/service/impl/EntityObservabilityGatewayImpl.java
+++ 
b/hertzbeat-observability/src/main/java/org/apache/hertzbeat/observability/shared/service/impl/EntityObservabilityGatewayImpl.java
@@ -606,7 +606,7 @@ public class EntityObservabilityGatewayImpl implements 
EntityObservabilityGatewa
                 CollectionUtils.isEmpty(logEvidence) ? null : 
logEvidence.getFirst();
         TraceEvidence preferredTraceEvidence =
                 CollectionUtils.isEmpty(traceEvidence) ? null : 
traceEvidence.getFirst();
-        return new EntityResponseHandoffsInfo(
+        EntityResponseHandoffsInfo handoffs = new EntityResponseHandoffsInfo(
                 buildEntityAlertHandoff(request.getReturnTo(), 
request.getReturnLabel(),
                         request.getEntityContext(), request.getActiveAlerts()),
                 buildEntityMonitorHandoff(request.getReturnTo(), 
request.getReturnLabel(),
@@ -624,6 +624,38 @@ public class EntityObservabilityGatewayImpl implements 
EntityObservabilityGatewa
                         request.isOwnerReady(), request.isRunbookReady(),
                         request.isRelationReady(), request.isTelemetryReady())
         );
+        applyEntityContextToResponseHandoffs(handoffs, 
request.getEntityContext());
+        return handoffs;
+    }
+
+    private void 
applyEntityContextToResponseHandoffs(EntityResponseHandoffsInfo handoffs,
+                                                      ObservedEntityContext 
entityContext) {
+        if (handoffs == null || entityContext == null || 
entityContext.getEntity() == null) {
+            return;
+        }
+        applyEntityContextToResponseHandoff(handoffs.getAlerts(), 
entityContext);
+        applyEntityContextToResponseHandoff(handoffs.getMonitors(), 
entityContext);
+        applyEntityContextToResponseHandoff(handoffs.getLogs(), entityContext);
+        applyEntityContextToResponseHandoff(handoffs.getTraces(), 
entityContext);
+        applyEntityContextToResponseHandoff(handoffs.getDiscovery(), 
entityContext);
+        applyEntityContextToResponseHandoff(handoffs.getEditor(), 
entityContext);
+    }
+
+    private void applyEntityContextToResponseHandoff(EntityResponseHandoffInfo 
handoff,
+                                                    ObservedEntityContext 
entityContext) {
+        if (handoff == null || entityContext == null || 
entityContext.getEntity() == null) {
+            return;
+        }
+        ObserveEntity entity = entityContext.getEntity();
+        if (handoff.getEntityId() == null) {
+            handoff.setEntityId(entity.getId());
+        }
+        if (!StringUtils.hasText(handoff.getEntityType())) {
+            handoff.setEntityType(trimToNull(entity.getType()));
+        }
+        if (!StringUtils.hasText(handoff.getEntityName())) {
+            handoff.setEntityName(firstNonBlank(entity.getDisplayName(), 
entity.getName()));
+        }
     }
 
     @Override
diff --git 
a/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/shared/service/impl/EntityObservabilityGatewayImplTest.java
 
b/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/shared/service/impl/EntityObservabilityGatewayImplTest.java
index e2fcb981ff..875abc8fe6 100644
--- 
a/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/shared/service/impl/EntityObservabilityGatewayImplTest.java
+++ 
b/hertzbeat-observability/src/test/java/org/apache/hertzbeat/observability/shared/service/impl/EntityObservabilityGatewayImplTest.java
@@ -727,6 +727,8 @@ class EntityObservabilityGatewayImplTest {
     @Test
     void buildEntityResponseHandoffsShouldAssembleAllTargetsFromRequest() {
         ObserveEntity entity = new ObserveEntity();
+        entity.setId(1L);
+        entity.setType("service");
         entity.setName("checkout");
         entity.setDisplayName("Checkout service");
         EntityIdentity identity = EntityIdentity.builder()
@@ -766,6 +768,17 @@ class EntityObservabilityGatewayImplTest {
         assertEquals("trace-1", handoffs.getTraces().getSearch());
         assertEquals("checkout-system", handoffs.getDiscovery().getSystem());
         assertEquals("ownership", handoffs.getEditor().getFocus());
+        for (EntityResponseHandoffInfo handoff : List.of(
+                handoffs.getAlerts(),
+                handoffs.getMonitors(),
+                handoffs.getLogs(),
+                handoffs.getTraces(),
+                handoffs.getDiscovery(),
+                handoffs.getEditor())) {
+            assertEquals(1L, handoff.getEntityId());
+            assertEquals("service", handoff.getEntityType());
+            assertEquals("Checkout service", handoff.getEntityName());
+        }
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to