-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathAddTelemetryOptions.cs
More file actions
89 lines (76 loc) · 4.41 KB
/
AddTelemetryOptions.cs
File metadata and controls
89 lines (76 loc) · 4.41 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
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
84
85
86
87
88
89
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.IO.Abstractions;
using Azure.DataApiBuilder.Config;
using Azure.DataApiBuilder.Config.ObjectModel;
using Azure.DataApiBuilder.Product;
using Cli.Constants;
using CommandLine;
using Microsoft.Extensions.Logging;
using OpenTelemetry.Exporter;
using static Cli.Utils;
namespace Cli.Commands
{
/// <summary>
/// Telemetry command options
/// </summary>
[Verb("add-telemetry", isDefault: false, HelpText = "Add telemetry for Data Api builder Application", Hidden = false)]
public class AddTelemetryOptions : Options
{
public AddTelemetryOptions(
string? appInsightsConnString = null,
CliBool? appInsightsEnabled = null,
string? openTelemetryEndpoint = null,
CliBool? openTelemetryEnabled = null,
string? openTelemetryHeaders = null,
OtlpExportProtocol? openTelemetryExportProtocol = null,
string? openTelemetryServiceName = null,
string? config = null) : base(config)
{
AppInsightsConnString = appInsightsConnString;
AppInsightsEnabled = appInsightsEnabled;
OpenTelemetryEndpoint = openTelemetryEndpoint;
OpenTelemetryEnabled = openTelemetryEnabled;
OpenTelemetryHeaders = openTelemetryHeaders;
OpenTelemetryExportProtocol = openTelemetryExportProtocol;
OpenTelemetryServiceName = openTelemetryServiceName;
}
// Connection string for the Application Insights resource to which telemetry data should be sent.
// This option is required and must be provided with a valid connection string when using app insights.
[Option("app-insights-conn-string", Required = false, HelpText = "Connection string for the Application Insights resource for telemetry data")]
public string? AppInsightsConnString { get; }
// To specify whether Application Insights telemetry should be enabled. This flag is optional and default value is false.
[Option("app-insights-enabled", Default = CliBool.False, Required = false, HelpText = "Enable/Disable Application Insights.")]
public CliBool? AppInsightsEnabled { get; }
// Connection string for the Open Telemetry resource to which telemetry data should be sent.
// This option is required and must be provided with a valid connection string when using open telemetry.
[Option("otel-endpoint", Required = false, HelpText = "Endpoint for Open Telemetry for telemetry data")]
public string? OpenTelemetryEndpoint { get; }
// To specify whether Open Telemetry telemetry should be enabled. This flag is optional and default value is false.
[Option("otel-enabled", Default = CliBool.False, Required = false, HelpText = "Enable/Disable OTEL.")]
public CliBool? OpenTelemetryEnabled { get; }
// Headers for the Open Telemetry resource to which telemetry data should be sent.
[Option("otel-headers", Required = false, HelpText = "Headers for Open Telemetry for telemetry data")]
public string? OpenTelemetryHeaders { get; }
// Specify the Open Telemetry protocol. This flag is optional and default value is grpc.
[Option("otel-protocol", Default = OtlpExportProtocol.Grpc, Required = false, HelpText = "Accepted: grpc/httpprotobuf.")]
public OtlpExportProtocol? OpenTelemetryExportProtocol { get; }
// Service Name for the Open Telemetry resource to which telemetry data should be sent. This flag is optional and default value is dab.
[Option("otel-service-name", Default = "dab", Required = false, HelpText = "Service name for Open Telemetry.")]
public string? OpenTelemetryServiceName { get; }
public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem)
{
logger.LogInformation("{productName} {version}", PRODUCT_NAME, ProductInfo.GetProductVersion());
bool isSuccess = ConfigGenerator.TryAddTelemetry(this, loader, fileSystem);
if (isSuccess)
{
logger.LogInformation("Successfully added telemetry to the configuration file.");
}
else
{
logger.LogError("Failed to add telemetry to the configuration file.");
}
return isSuccess ? CliReturnCode.SUCCESS : CliReturnCode.GENERAL_ERROR;
}
}
}