Commit 4aa6f7d
authored
Fix GRPC instrumentation for BuildHttpErrorResponse. Enable integration tests. (#7457)
## Summary of changes
[This
error](https://app.datadoghq.com/error-tracking?query=source%3Adotnet%20-%2AStackOverflowException%2A%20-%2Adebugger%2A%20-%2Aappsec%2A&et-side=data&et-viz=events&order=total_count&refresh_mode=sliding&source=all&sp=%5B%7B%22p%22%3A%7B%22issueId%22%3A%225b4a9f2a-3ae6-11f0-9077-da7ad0900002%22%7D%2C%22i%22%3A%22error-tracking-issue%22%7D%5D&view=spans&from_ts=1756801478434&to_ts=1756887878434&live=true)
was logged:
```
Error : Exception occurred when calling the CallTarget integration continuation.
System.TypeInitializationException ---> Datadog.Trace.ClrProfiler.CallTarget.CallTargetInvokerException ---> System.ArgumentException
at Datadog.Trace.Util.ThrowHelper.ThrowArgumentException(String message)
at Datadog.Trace.ClrProfiler.CallTarget.Handlers.IntegrationMapper.CreateBeginMethodDelegate(Type integrationType, Type targetType, Type[] argumentsTypes)
at Datadog.Trace.ClrProfiler.CallTarget.Handlers.BeginMethodHandler`6..cctor()
```
This error would only happen when method
Grpc.AspNetCore.Server.Internal.GrpcProtocolHelpers.BuildHttpErrorResponse
is called, which happens when there is an error during the Grpc call.
In order to fix it, the signature of OnMethodBegin<TTarget,
TGrpcStatusCode> in
GrpcProtocolHelpersBuildHttpErrorResponseIntegration.cs had to be
changed by adding generic types.
To test this change, a new case has been added to the GRPC sample
application. By adding this header to the request
(context.Request.Headers["content-type"] = "application/json";), we can
test this instrumentation by causing an error during the GRPC call:
Content-Type 'application/json' is not supported
Additionally, some fixes have been done in the test app. In the
following code, we were always throwing the exception because the delay
set in theVerySlow method was 300 msecs, lower than 600, so the method
would finish on time, which is not the expected outcome :
```
try
{
_logger.LogInformation("Sending very slow request to self");
await client.VerySlowAsync(new HelloRequest { Name = "GreeterClient" }, deadline: DateTime.UtcNow.AddMilliseconds(600));
throw new Exception("Received reply, when should have exceeded deadline");
}
```
By setting a lower deadline, we make sure that the deadline is exceeded.
We were not detecting this unexpected behavior because in grpctests.cs,
we were capturing the exception ExitCodeException:
```
catch (ExitCodeException)
{
// There is a race condition in GRPC version < v2.43.0 that can cause ObjectDisposedException
// when a deadline is exceeded. Skip the test if we hit it: grpc/grpc-dotnet#1550
if (!string.IsNullOrEmpty(packageVersion)
&& new Version(packageVersion) < new Version("2.43.0")
&& processResult is not null
&& processResult.StandardError.Contains("ObjectDisposedException"))
{
throw new SkipException("Hit race condition in GRPC deadline exceeded");
}
}
```
After capturing the exception, we would not launch an SkipException but
we would end the test without errors. A new throw statement has been
added to control that we only skip the tests in the case of
ObjectDisposedException.
This change in the GRPC tests has also effectively enabled the GRPC
legacy tests, that have a different instrumentation but were suffering
the same issue (throw exception and skip). The snapshots of the legacy
tests were not matching exactly the result obtained after enabling these
tests. The instrumentation of the legacy methods or the legacy sample
app have not changed significantly, so we would probably need to
evaluate if the results that we are getting are the expected ones.
Anyway, this work would probably be out of the scope of this PR.
## Reason for change
## Implementation details
## Test coverage
## Other details
<!-- Fixes #{issue} -->
<!-- 1 parent 7f14b71 commit 4aa6f7d
File tree
14 files changed
+762
-320
lines changed- tracer
- src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Grpc/GrpcDotNet/GrpcAspNetCoreServer
- test
- Datadog.Trace.ClrProfiler.IntegrationTests
- snapshots
- test-applications/integrations
- Samples.GrpcDotNet
- Protos
- Services
- Samples.GrpcLegacy
- Protos
14 files changed
+762
-320
lines changedLines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
| |||
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
43 | | - | |
| 47 | + | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
| |||
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
52 | | - | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | 135 | | |
138 | 136 | | |
139 | 137 | | |
| |||
426 | 424 | | |
427 | 425 | | |
428 | 426 | | |
| 427 | + | |
| 428 | + | |
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
| |||
0 commit comments