-
Notifications
You must be signed in to change notification settings - Fork 263
/
NoOpTelemetryChannel.cs
83 lines (71 loc) · 2.54 KB
/
NoOpTelemetryChannel.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using Microsoft.ApplicationInsights.Channel;
namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Correlation
{
/// <summary>
/// A stub of <see cref="ITelemetryChannel"/>.
/// </summary>
public sealed class NoOpTelemetryChannel : ITelemetryChannel
{
/// <summary>
/// Initializes a new instance of the <see cref="NoOpTelemetryChannel"/> class.
/// </summary>
public NoOpTelemetryChannel()
{
this.OnSend = telemetry => { };
this.OnFlush = () => { };
this.OnDispose = () => { };
}
/// <summary>
/// Gets or sets a value indicating whether this channel is in developer mode.
/// </summary>
public bool? DeveloperMode { get; set; }
/// <summary>
/// Gets or sets a value indicating the channel's URI. To this URI the telemetry is expected to be sent.
/// </summary>
public string EndpointAddress { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to throw an error.
/// </summary>
public bool ThrowError { get; set; }
/// <summary>
/// Gets or sets the callback invoked by the <see cref="Send"/> method.
/// </summary>
public Action<ITelemetry> OnSend { get; set; }
/// <summary>
/// Gets or sets the callback invoked by the <see cref="Flush"/> method.
/// </summary>
public Action OnFlush { get; set; }
/// <summary>
/// Gets or sets the callback invoked by the <see cref="Dispose"/> method.
/// </summary>
public Action OnDispose { get; set; }
/// <summary>
/// Implements the <see cref="ITelemetryChannel.Send"/> method by invoking the <see cref="OnSend"/> callback.
/// </summary>
public void Send(ITelemetry item)
{
if (this.ThrowError)
{
throw new Exception("test error");
}
this.OnSend(item);
}
/// <summary>
/// Implements the <see cref="IDisposable.Dispose"/> method.
/// </summary>
public void Dispose()
{
this.OnDispose();
}
/// <summary>
/// Implements the <see cref="ITelemetryChannel.Flush" /> method.
/// </summary>
public void Flush()
{
this.OnFlush();
}
}
}