-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathCommandExecuteReaderWithCancellationAsyncIntegration.cs
More file actions
51 lines (48 loc) · 2.46 KB
/
CommandExecuteReaderWithCancellationAsyncIntegration.cs
File metadata and controls
51 lines (48 loc) · 2.46 KB
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
// <copyright file="CommandExecuteReaderWithCancellationAsyncIntegration.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>
using System;
using System.ComponentModel;
using System.Data;
using System.Threading;
using Datadog.Trace.ClrProfiler.CallTarget;
using Datadog.Trace.PlatformHelpers;
namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.AdoNet
{
/// <summary>
/// CallTarget instrumentation for:
/// Task[*DataReader] [Command].ExecuteReaderAsync(CancellationToken)
/// </summary>
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class CommandExecuteReaderWithCancellationAsyncIntegration
{
/// <summary>
/// OnMethodBegin callback
/// </summary>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
/// <param name="cancellationToken">CancellationToken value</param>
/// <returns>Calltarget state value</returns>
internal static CallTargetState OnMethodBegin<TTarget>(TTarget instance, CancellationToken cancellationToken)
{
return new CallTargetState(DbScopeFactory.Cache<TTarget>.CreateDbCommandScope(Tracer.Instance, (IDbCommand)instance, BaseHash.B64Value));
}
/// <summary>
/// OnAsyncMethodEnd callback
/// </summary>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <typeparam name="TReturn">Type of the return value, 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="returnValue">Return value 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>
internal static TReturn OnAsyncMethodEnd<TTarget, TReturn>(TTarget instance, TReturn returnValue, Exception exception, in CallTargetState state)
{
state.Scope.DisposeWithException(exception);
return returnValue;
}
}
}