Skip to content

Commit

Permalink
Update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn committed Aug 11, 2024
1 parent 4c3d3ed commit 98838b5
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 36 deletions.
20 changes: 9 additions & 11 deletions src/HotChocolate/Diagnostics/src/Diagnostics/ActivityEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,23 +595,21 @@ protected virtual void EnrichError(IError error, Activity activity)
var tags = new ActivityTagsCollection
{
new(AttributeExceptionMessage, error.Message),
new(AttributeExceptionType, error.Code)
new(AttributeExceptionType, error.Code ?? "GRAPHQL_ERROR"),
};

if (error.Locations is { Count: > 0, })
if (error.Path is not null)
{
for (var i = 0; i < error.Locations.Count; i++)
{
tags["graphql.error.location.column"] = error.Locations[i].Column;
tags["graphql.error.location.line"] = error.Locations[i].Line;

activity.AddEvent(new ActivityEvent(AttributeExceptionEventName, default, tags));
}
tags["graphql.error.path"] = error.Path.ToString();
}
else

if (error.Locations is { Count: > 0 })
{
activity.AddEvent(new ActivityEvent(AttributeExceptionEventName, default, tags));
tags["graphql.error.location.column"] = error.Locations[0].Column;
tags["graphql.error.location.line"] = error.Locations[0].Line;
}

activity.AddEvent(new ActivityEvent(AttributeExceptionEventName, default, tags));
}

private static ISyntaxNode CreateVariablesNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public async Task Validation_error_when_rename_root_is_activated()
.ExecuteRequestAsync("{ abc123 }");

// assert
Assert.Equal("CaptureActivities: Begin Validate Document", Activity.Current!.DisplayName);
Assert.Equal("CaptureActivities: Begin Validate Document",
Activity.Current!.DisplayName);
}
}

Expand Down Expand Up @@ -353,13 +354,65 @@ public async Task Cause_a_resolver_error_that_deletes_the_whole_result()
}
}

[Fact]
public async Task Cause_a_resolver_error_that_deletes_the_whole_result_deep()
{
using (CaptureActivities(out var activities))
{
// arrange & act
await new ServiceCollection()
.AddGraphQL()
.AddInstrumentation(o =>
{
o.Scopes = ActivityScopes.All;
o.IncludeDocument = true;
})
.AddQueryType<SimpleQuery>()
.ExecuteRequestAsync(
"""
query SayHelloOperation {
deep {
deeper {
deeps {
deeper {
causeFatalError
}
}
}
}
}
""");

// assert
#if NET7_0_OR_GREATER
activities.MatchSnapshot(new SnapshotNameExtension("_NET7"));
#else
activities.MatchSnapshot();
#endif
}
}

public class SimpleQuery
{
public string SayHello() => "hello";

public string CauseFatalError() => throw new GraphQLException("fail");

public Deep Deep() => new Deep();

public Task<string> DataLoader(CustomDataLoader dataLoader, string key)
=> dataLoader.LoadAsync(key);
}

public class Deep
{
public Deeper Deeper() => new Deeper();

public string CauseFatalError() => throw new GraphQLException("fail");
}

public class Deeper
{
public Deep[] Deeps() => [new Deep()];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@
],
"event": [
{
"Name": "Error",
"Name": "exception",
"Tags": {
"graphql.error.message": "fail",
"exception.message": "fail",
"exception.type": "GRAPHQL_ERROR",
"graphql.error.path": "/causeFatalError",
"graphql.error.location.column": 27,
"graphql.error.location.line": 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,20 @@
],
"event": [
{
"Name": "Error",
"Name": "exception",
"Tags": [
{
"Key": "graphql.error.message",
"Key": "exception.message",
"Value": "fail"
},
{
"Key": "exception.type",
"Value": "GRAPHQL_ERROR"
},
{
"Key": "graphql.error.path",
"Value": "/causeFatalError"
},
{
"Key": "graphql.error.location.column",
"Value": 27
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"activities": [
{
"OperationName": "ExecuteRequest",
"DisplayName": "Execute Request",
"Status": "Error",
"tags": [
{
"Key": "graphql.document.id",
"Value": "803df9346db185e9dc0b22dd3909aa70"
},
{
"Key": "graphql.document.hash",
"Value": "803df9346db185e9dc0b22dd3909aa70"
},
{
"Key": "graphql.document.body",
"Value": "query SayHelloOperation {\n deep {\n deeper {\n deeps {\n deeper {\n causeFatalError\n }\n }\n }\n }\n}"
},
{
"Key": "otel.status_code",
"Value": "ERROR"
}
],
"event": [],
"activities": [
{
"OperationName": "ParseDocument",
"DisplayName": "Parse Document",
"Status": "Ok",
"tags": [
{
"Key": "otel.status_code",
"Value": "OK"
}
],
"event": []
},
{
"OperationName": "ValidateDocument",
"DisplayName": "Validate Document",
"Status": "Error",
"tags": [
{
"Key": "otel.status_code",
"Value": "ERROR"
},
{
"Key": "graphql.document.id",
"Value": "803df9346db185e9dc0b22dd3909aa70"
},
{
"Key": "graphql.document.hash",
"Value": "803df9346db185e9dc0b22dd3909aa70"
}
],
"event": [
{
"Name": "exception",
"Tags": {
"exception.message": "The field `causeFatalError` does not exist on the type `Deeper`.",
"exception.type": "GRAPHQL_ERROR",
"graphql.error.path": "/deep/deeper/deeps/deeper",
"graphql.error.location.column": 21,
"graphql.error.location.line": 6
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"activities": [
{
"OperationName": "ExecuteRequest",
"DisplayName": "Execute Request",
"Status": "Error",
"tags": [
{
"Key": "graphql.document.id",
"Value": "803df9346db185e9dc0b22dd3909aa70"
},
{
"Key": "graphql.document.hash",
"Value": "803df9346db185e9dc0b22dd3909aa70"
},
{
"Key": "graphql.document.body",
"Value": "query SayHelloOperation {\n deep {\n deeper {\n deeps {\n deeper {\n causeFatalError\n }\n }\n }\n }\n}"
},
{
"Key": "otel.status_code",
"Value": "ERROR"
}
],
"event": [],
"activities": [
{
"OperationName": "ParseDocument",
"DisplayName": "Parse Document",
"Status": "Ok",
"tags": [
{
"Key": "otel.status_code",
"Value": "OK"
}
],
"event": []
},
{
"OperationName": "ValidateDocument",
"DisplayName": "Validate Document",
"Status": "Error",
"tags": [
{
"Key": "otel.status_code",
"Value": "ERROR"
},
{
"Key": "graphql.document.id",
"Value": "803df9346db185e9dc0b22dd3909aa70"
},
{
"Key": "graphql.document.hash",
"Value": "803df9346db185e9dc0b22dd3909aa70"
}
],
"event": [
{
"Name": "exception",
"Tags": [
{
"Key": "exception.message",
"Value": "The field `causeFatalError` does not exist on the type `Deeper`."
},
{
"Key": "exception.type",
"Value": "GRAPHQL_ERROR"
},
{
"Key": "graphql.error.path",
"Value": "/deep/deeper/deeps/deeper"
},
{
"Key": "graphql.error.location.column",
"Value": 21
},
{
"Key": "graphql.error.location.line",
"Value": 6
}
]
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@
],
"event": [
{
"Name": "Error",
"Name": "exception",
"Tags": {
"graphql.error.message": "The field `sayHello_` does not exist on the type `SimpleQuery`.",
"exception.message": "The field `sayHello_` does not exist on the type `SimpleQuery`.",
"exception.type": "GRAPHQL_ERROR",
"graphql.error.location.column": 27,
"graphql.error.location.line": 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@
],
"event": [
{
"Name": "Error",
"Name": "exception",
"Tags": [
{
"Key": "graphql.error.message",
"Key": "exception.message",
"Value": "The field `sayHello_` does not exist on the type `SimpleQuery`."
},
{
"Key": "exception.type",
"Value": "GRAPHQL_ERROR"
},
{
"Key": "graphql.error.location.column",
"Value": 27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
],
"event": [
{
"Name": "Error",
"Name": "exception",
"Tags": {
"graphql.error.message": "Found a NameStart character `n` (110) following a number, which is disallowed.",
"graphql.error.code": "HC0011",
"exception.message": "Found a NameStart character `n` (110) following a number, which is disallowed.",
"exception.type": "HC0011",
"graphql.error.location.column": 37,
"graphql.error.location.line": 10
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
],
"event": [
{
"Name": "Error",
"Name": "exception",
"Tags": [
{
"Key": "graphql.error.message",
"Key": "exception.message",
"Value": "Found a NameStart character `n` (110) following a number, which is disallowed."
},
{
"Key": "graphql.error.code",
"Key": "exception.type",
"Value": "HC0011"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
],
"event": [
{
"Name": "Error",
"Name": "exception",
"Tags": {
"graphql.error.message": "Expected a `Name`-token, but found a `Integer`-token.",
"graphql.error.code": "HC0011",
"exception.message": "Expected a `Name`-token, but found a `Integer`-token.",
"exception.type": "HC0011",
"graphql.error.location.column": 21,
"graphql.error.location.line": 3
}
Expand Down
Loading

0 comments on commit 98838b5

Please sign in to comment.