Skip to content

Commit c808703

Browse files
[Fusion] Add SubgraphRequestError diagnostic event (#8237)
1 parent a0475e3 commit c808703

File tree

7 files changed

+36
-2
lines changed

7 files changed

+36
-2
lines changed

src/HotChocolate/Fusion/src/Core/Execution/Diagnostic/AggregateFusionDiagnosticEvents.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public void ResolveByKeyBatchError(Exception exception)
4141
}
4242
}
4343

44+
public void SubgraphRequestError(string subgraphName, Exception exception)
45+
{
46+
for (var i = 0; i < listeners.Length; i++)
47+
{
48+
listeners[i].SubgraphRequestError(subgraphName, exception);
49+
}
50+
}
51+
4452
private sealed class AggregateActivityScope(IDisposable[] scopes) : IDisposable
4553
{
4654
private bool _disposed;

src/HotChocolate/Fusion/src/Core/Execution/Diagnostic/FusionDiagnosticEventListener.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public virtual void ResolveByKeyBatchError(Exception exception)
3434
{
3535
}
3636

37+
/// <inheritdoc />
38+
public virtual void SubgraphRequestError(string subgraphName, Exception exception)
39+
{
40+
}
41+
3742
private sealed class EmptyActivityScope : IDisposable
3843
{
3944
public void Dispose()

src/HotChocolate/Fusion/src/Core/Execution/Diagnostic/IFusionDiagnosticEvents.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@ public interface IFusionDiagnosticEvents
3939
/// The exception that occurred while executing a ResolveByKeyBatch QueryPlan node.
4040
/// </param>
4141
void ResolveByKeyBatchError(Exception exception);
42+
43+
/// <summary>
44+
/// Called when an exception occurred during the request to a subgraph service.
45+
/// </summary>
46+
/// <param name="subgraphName">
47+
/// The name of the subgraph the request was sent to.
48+
/// </param>
49+
/// <param name="exception">
50+
/// The exception that occurred during the request to a subgraph service.
51+
/// </param>
52+
void SubgraphRequestError(string subgraphName, Exception exception);
4253
}

src/HotChocolate/Fusion/src/Core/Execution/Diagnostic/NoopFusionDiagnosticEvents.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public void ResolveByKeyBatchError(Exception exception)
1919
{
2020
}
2121

22+
public void SubgraphRequestError(string subgraphName, Exception exception)
23+
{
24+
}
25+
2226
public void Dispose()
2327
{
2428
}

src/HotChocolate/Fusion/src/Core/Execution/Nodes/Resolve.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ private void ProcessResponses(
150150

151151
if (response.TransportException is not null)
152152
{
153+
context.DiagnosticEvents.SubgraphRequestError(
154+
subgraphName,
155+
response.TransportException);
156+
153157
CreateTransportErrors(
154158
response.TransportException,
155159
context.Result,

src/HotChocolate/Fusion/src/Core/Execution/Nodes/ResolveByKeyBatch.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ private void ProcessResult(
153153

154154
if (response.TransportException is not null)
155155
{
156+
context.DiagnosticEvents.SubgraphRequestError(subgraphName, response.TransportException);
157+
156158
foreach (var state in batchExecutionState)
157159
{
158160
CreateTransportErrors(

src/HotChocolate/Fusion/src/Core/Execution/Nodes/ResolveNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ protected override async Task OnExecuteNodesAsync(
6969
{
7070
typeName = context.ParseTypeNameFromId(formattedId.Value);
7171
}
72-
catch (IdSerializationException ex)
72+
catch (Exception exception)
7373
{
74-
context.Result.AddError(InvalidNodeFormat(_selection, ex), _selection);
74+
context.Result.AddError(InvalidNodeFormat(_selection, exception), _selection);
7575
return;
7676
}
7777

0 commit comments

Comments
 (0)