-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathCommandExecuteNonQueryWithBehaviorIntegration.cs
More file actions
51 lines (48 loc) · 2.47 KB
/
CommandExecuteNonQueryWithBehaviorIntegration.cs
File metadata and controls
51 lines (48 loc) · 2.47 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="CommandExecuteNonQueryWithBehaviorIntegration.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 Datadog.Trace.ClrProfiler.CallTarget;
using Datadog.Trace.PlatformHelpers;
namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.AdoNet
{
/// <summary>
/// CallTarget instrumentation for:
/// int [Command].ExecuteNonQuery(CommandBehavior)
/// </summary>
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class CommandExecuteNonQueryWithBehaviorIntegration
{
/// <summary>
/// OnMethodBegin callback
/// </summary>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <typeparam name="TBehavior">Command Behavior type</typeparam>
/// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
/// <param name="commandBehavior">Command behavior</param>
/// <returns>Calltarget state value</returns>
internal static CallTargetState OnMethodBegin<TTarget, TBehavior>(TTarget instance, TBehavior commandBehavior)
{
return new CallTargetState(DbScopeFactory.Cache<TTarget>.CreateDbCommandScope(Tracer.Instance, (IDbCommand)instance, BaseHash.B64Value));
}
/// <summary>
/// OnMethodEnd callback
/// </summary>
/// <typeparam name="TTarget">Type of the target</typeparam>
/// <typeparam name="TReturn">Type of the return value</typeparam>
/// <param name="instance">Instance value, aka `this` of the instrumented method.</param>
/// <param name="returnValue">Task of 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>
internal static CallTargetReturn<TReturn> OnMethodEnd<TTarget, TReturn>(TTarget instance, TReturn returnValue, Exception exception, in CallTargetState state)
{
state.Scope.DisposeWithException(exception);
return new CallTargetReturn<TReturn>(returnValue);
}
}
}