-
Notifications
You must be signed in to change notification settings - Fork 132
/
HttpClientHandlerIntegration.cs
55 lines (52 loc) · 2.7 KB
/
HttpClientHandlerIntegration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Threading;
using Datadog.Trace.ClrProfiler.CallTarget;
using Datadog.Trace.Configuration;
namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.HttpClientHandler
{
/// <summary>
/// System.Net.Http.HttpClientHandler calltarget instrumentation
/// </summary>
[InstrumentMethod(
AssemblyName = "System.Net.Http",
TypeName = "System.Net.Http.HttpClientHandler",
MethodName = "SendAsync",
ReturnTypeName = ClrNames.HttpResponseMessageTask,
ParameterTypeNames = new[] { ClrNames.HttpRequestMessage, ClrNames.CancellationToken },
MinimumVersion = "4.0.0",
MaximumVersion = "5.*.*",
IntegrationName = IntegrationName)]
public class HttpClientHandlerIntegration
{
private const string IntegrationName = nameof(IntegrationIds.HttpMessageHandler);
/// <summary>
/// OnMethodBegin callback
/// </summary>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <typeparam name="TRequest">Type of the request</typeparam>
/// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
/// <param name="requestMessage">HttpRequest message instance</param>
/// <param name="cancellationToken">CancellationToken value</param>
/// <returns>Calltarget state value</returns>
public static CallTargetState OnMethodBegin<TTarget, TRequest>(TTarget instance, TRequest requestMessage, CancellationToken cancellationToken)
where TRequest : IHttpRequestMessage
{
return HttpClientHandlerCommon.OnMethodBegin(instance, requestMessage, cancellationToken);
}
/// <summary>
/// OnAsyncMethodEnd callback
/// </summary>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <typeparam name="TResponse">Type of the response, in an async scenario will be T of Task of T</typeparam>
/// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
/// <param name="responseMessage">HttpResponse message instance</param>
/// <param name="exception">Exception instance in case the original code threw an exception.</param>
/// <param name="state">Calltarget state value</param>
/// <returns>A response value, in an async scenario will be T of Task of T</returns>
public static TResponse OnAsyncMethodEnd<TTarget, TResponse>(TTarget instance, TResponse responseMessage, Exception exception, CallTargetState state)
where TResponse : IHttpResponseMessage
{
return HttpClientHandlerCommon.OnMethodEnd(instance, responseMessage, exception, state);
}
}
}