From f8739d98b97cc23afe48fca66a8744e41d65819e Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Tue, 8 Aug 2023 21:20:53 +0530 Subject: [PATCH 1/5] custom listener example --- .../Usage/Cosmos.Samples.Usage.sln | 8 +- .../AppSettings.json | 4 + .../CustomDiagnosticAndEventListener.cs | 167 ++++++++++++++++++ .../CustomDiagnosticAndEventListener.csproj | 31 ++++ .../Program.cs | 91 ++++++++++ 5 files changed, 300 insertions(+), 1 deletion(-) create mode 100644 Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/AppSettings.json create mode 100644 Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs create mode 100644 Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj create mode 100644 Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/Program.cs diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/Cosmos.Samples.Usage.sln b/Microsoft.Azure.Cosmos.Samples/Usage/Cosmos.Samples.Usage.sln index 999b48d928..5e23b5c075 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/Cosmos.Samples.Usage.sln +++ b/Microsoft.Azure.Cosmos.Samples/Usage/Cosmos.Samples.Usage.sln @@ -53,7 +53,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CFPullModelLatestVersionMod EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry", "OpenTelemetry\OpenTelemetry.csproj", "{C6EF6948-C085-4013-A21F-99303ECBA7A9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplicationInsights", "ApplicationInsights\ApplicationInsights.csproj", "{55149A3C-A263-4EE5-AD2D-02FE9AC4D291}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationInsights", "ApplicationInsights\ApplicationInsights.csproj", "{55149A3C-A263-4EE5-AD2D-02FE9AC4D291}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomDiagnosticAndEventListener", "CustomDiagnosticAndEventListener\CustomDiagnosticAndEventListener.csproj", "{9BE3551E-31A1-4186-9D2F-DC325411A39D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -165,6 +167,10 @@ Global {55149A3C-A263-4EE5-AD2D-02FE9AC4D291}.Debug|Any CPU.Build.0 = Debug|Any CPU {55149A3C-A263-4EE5-AD2D-02FE9AC4D291}.Release|Any CPU.ActiveCfg = Release|Any CPU {55149A3C-A263-4EE5-AD2D-02FE9AC4D291}.Release|Any CPU.Build.0 = Release|Any CPU + {9BE3551E-31A1-4186-9D2F-DC325411A39D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9BE3551E-31A1-4186-9D2F-DC325411A39D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9BE3551E-31A1-4186-9D2F-DC325411A39D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9BE3551E-31A1-4186-9D2F-DC325411A39D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/AppSettings.json b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/AppSettings.json new file mode 100644 index 0000000000..f6b062537f --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/AppSettings.json @@ -0,0 +1,4 @@ +{ + "CosmosDBEndPointUrl": "https://localhost:8081", + "CosmosDBAuthorizationKey": "Super secret key" +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs new file mode 100644 index 0000000000..35dfb703d8 --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs @@ -0,0 +1,167 @@ +namespace Sample.Listeners +{ + using System.Diagnostics.Tracing; + using System.Diagnostics; + using System.Collections.Concurrent; + + internal class CustomDiagnosticAndEventListener : + EventListener, // Override Event Listener to capture Event source events + IObserver>, // Override IObserver to capture Activity events + IObserver, + IDisposable + { + private readonly string diagnosticSourceName; + private readonly string eventSourceName; + + private ConcurrentBag? Subscriptions = new(); + private ConcurrentBag Activities { get; } = new(); + + public CustomDiagnosticAndEventListener(string diagnosticSourceName, string eventSourceName) + { + this.diagnosticSourceName = diagnosticSourceName; + this.eventSourceName = eventSourceName; + + DiagnosticListener.AllListeners.Subscribe(this); + } + + /// + /// IObserver Override + /// + public void OnCompleted() { + throw new NotImplementedException(); + } + + /// + /// IObserver Override + /// + public void OnError(Exception error) { + throw new NotImplementedException(); + } + + /// + /// IObserver Override + /// + public void OnNext(KeyValuePair value) + { + lock (this.Activities) + { + // Check for disposal + if (this.Subscriptions == null) return; + + string startSuffix = ".Start"; + string stopSuffix = ".Stop"; + string exceptionSuffix = ".Exception"; + + if (Activity.Current == null) + { + return; + } + + if (value.Key.EndsWith(startSuffix)) + { + this.Activities.Add(Activity.Current); + } + else if (value.Key.EndsWith(stopSuffix) || value.Key.EndsWith(exceptionSuffix)) + { + foreach (Activity activity in this.Activities) + { + if (activity.Id == Activity.Current.Id) + { + Console.WriteLine(); + Console.WriteLine("---------------------------------------------------------------------------------------------------------"); + Console.WriteLine($" Activity Name: {activity.DisplayName}"); + Console.WriteLine($" Activity Operation Name: {activity.OperationName}"); + foreach (KeyValuePair actualTag in activity.Tags) + { + Console.WriteLine($" {actualTag.Key} ==> {actualTag.Value}"); + } + Console.WriteLine("---------------------------------------------------------------------------------------------------------"); + return; + } + } + } + } + } + + /// + /// IObserver Override + /// + public void OnNext(DiagnosticListener value) + { + if (value.Name == this.diagnosticSourceName && this.Subscriptions != null) + { + Console.WriteLine(); + Console.WriteLine($"CustomDiagnosticAndEventListener : OnNext : {value.Name}"); + lock (this.Activities) + { + this.Subscriptions?.Add(value.Subscribe(this)); + } + } + } + + /// + /// EventListener Override + /// + protected override void OnEventSourceCreated(EventSource eventSource) + { + if (eventSource != null && eventSource.Name.Equals(this.eventSourceName)) + { + Console.WriteLine(); + Console.WriteLine($"CustomDiagnosticAndEventListener : OnEventSourceCreated : {eventSource.Name}"); + this.EnableEvents(eventSource, EventLevel.Informational); // Enable information level events + } + } + + /// + /// EventListener Override + /// + protected override void OnEventWritten(EventWrittenEventArgs eventData) + { + Console.WriteLine(); + Console.WriteLine("---------------------------------------------------------------------------------------------------------"); + Console.WriteLine($" Event Name: {eventData.EventName}"); + Console.WriteLine($" Event Level: {eventData.Level}"); + if(eventData.Payload != null) + { + int counter = 0; + foreach (object? payload in eventData.Payload) + { + Console.WriteLine($" Event Payload {counter++}: {payload}"); + } + } + else + { + Console.WriteLine($" Event Payload: NULL"); + } + Console.WriteLine("---------------------------------------------------------------------------------------------------------"); + } + + public override void Dispose() + { + Console.WriteLine("CustomDiagnosticAndEventListener : Dispose"); + base.Dispose(); + + if (this.Subscriptions == null) + { + return; + } + + ConcurrentBag subscriptions; + lock (this.Activities) + { + subscriptions = this.Subscriptions; + this.Subscriptions = null; + } + + foreach (IDisposable subscription in subscriptions) + { + subscription.Dispose(); // Dispose of DiagnosticListener subscription + } + + foreach (Activity activity in this.Activities) + { + activity.Dispose(); // Dispose of Activity + } + } + } +} diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj new file mode 100644 index 0000000000..73556aa3c2 --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj @@ -0,0 +1,31 @@ + + + + Exe + net6.0 + enable + enable + + + + + False + 3.33.0-preview + Content + Microsoft.Azure.Cosmos + false + + + + + + + + + + + + PreserveNewest + + + diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/Program.cs b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/Program.cs new file mode 100644 index 0000000000..551519d29b --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/Program.cs @@ -0,0 +1,91 @@ +namespace Cosmos.Samples.ApplicationInsights +{ + using System.Net; + using Microsoft.Azure.Cosmos; + using Microsoft.Extensions.Configuration; + using Newtonsoft.Json; + using Sample.Listeners; + + internal class Program + { + private static readonly string databaseName = "samples"; + private static readonly string containerName = "custom-listener-sample"; + + static async Task Main() + { + IConfigurationRoot configuration = new ConfigurationBuilder() + .AddJsonFile("AppSettings.json") + .Build(); + + string endpoint = configuration["CosmosDBEndPointUrl"]; + if (string.IsNullOrEmpty(endpoint)) + { + throw new ArgumentNullException("Please specify a valid CosmosDBEndPointUrl in the appSettings.json"); + } + + string authKey = configuration["CosmosDBAuthorizationKey"]; + if (string.IsNullOrEmpty(authKey) || string.Equals(authKey, "Super secret key")) + { + throw new ArgumentException("Please specify a valid CosmosDBAuthorizationKey in the appSettings.json"); + } + + using CustomDiagnosticAndEventListener listener + = new CustomDiagnosticAndEventListener( + diagnosticSourceName: "Azure.Cosmos.Operation", + eventSourceName: "Azure-Cosmos-Operation-Request-Diagnostics"); + + CosmosClientOptions options = new CosmosClientOptions() + { + IsDistributedTracingEnabled = true // Defaults to true, set to false to disable + }; + using (CosmosClient client = new CosmosClient(endpoint, authKey, options)) + { + Console.WriteLine($"Getting container reference for {containerName}."); + + ContainerProperties properties = new ContainerProperties(containerName, partitionKeyPath: "/id"); + + await client.CreateDatabaseIfNotExistsAsync(databaseName); + Container container = await client.GetDatabase(databaseName).CreateContainerIfNotExistsAsync(properties); + + await Program.RunCrudDemo(container); + } + } + + public static async Task RunCrudDemo(Container container) + { + // Any operations will automatically generate telemetry + + for (int i = 1; i <= 5; i++) + { + await container.CreateItemAsync(new Item { Id = $"{i}", Status = "new" }, new PartitionKey($"{i}")); + Console.WriteLine($"Created document with id: {i}"); + } + + for (int i = 1; i <= 5; i++) + { + await container.ReadItemAsync($"{i}", new PartitionKey($"{i}")); + Console.WriteLine($"Read document with id: {i}"); + } + + for (int i = 1; i <= 5; i++) + { + await container.ReplaceItemAsync(new Item { Id = $"{i}", Status = "updated" }, $"{i}", new PartitionKey($"{i}")); + Console.WriteLine($"Updated document with id: {i}"); + } + + for (int i = 1; i <= 5; i++) + { + await container.DeleteItemAsync($"{i}", new PartitionKey($"{i}")); + Console.WriteLine($"Deleted document with id: {i}"); + } + } + } + + internal class Item + { + [JsonProperty("id")] + public string Id { get; set; } + + public string Status { get; set; } + } +} \ No newline at end of file From 6e65ee7f42532f0b3ddc6c07d8b2311bf632473e Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Wed, 9 Aug 2023 14:35:20 +0530 Subject: [PATCH 2/5] removed unwanted code --- .../CustomDiagnosticAndEventListener.cs | 14 ++++---------- .../CustomDiagnosticAndEventListener.csproj | 10 ---------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs index 35dfb703d8..77534966fe 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs @@ -28,14 +28,14 @@ public CustomDiagnosticAndEventListener(string diagnosticSourceName, string even /// IObserver Override /// public void OnCompleted() { - throw new NotImplementedException(); + Console.WriteLine("OnCompleted"); } /// /// IObserver Override /// public void OnError(Exception error) { - throw new NotImplementedException(); + Console.WriteLine($"OnError : {error}"); } /// @@ -67,15 +67,13 @@ public void OnNext(KeyValuePair value) { if (activity.Id == Activity.Current.Id) { - Console.WriteLine(); - Console.WriteLine("---------------------------------------------------------------------------------------------------------"); Console.WriteLine($" Activity Name: {activity.DisplayName}"); Console.WriteLine($" Activity Operation Name: {activity.OperationName}"); foreach (KeyValuePair actualTag in activity.Tags) { Console.WriteLine($" {actualTag.Key} ==> {actualTag.Value}"); } - Console.WriteLine("---------------------------------------------------------------------------------------------------------"); + Console.WriteLine(); return; } } @@ -90,7 +88,6 @@ public void OnNext(DiagnosticListener value) { if (value.Name == this.diagnosticSourceName && this.Subscriptions != null) { - Console.WriteLine(); Console.WriteLine($"CustomDiagnosticAndEventListener : OnNext : {value.Name}"); lock (this.Activities) { @@ -106,7 +103,6 @@ protected override void OnEventSourceCreated(EventSource eventSource) { if (eventSource != null && eventSource.Name.Equals(this.eventSourceName)) { - Console.WriteLine(); Console.WriteLine($"CustomDiagnosticAndEventListener : OnEventSourceCreated : {eventSource.Name}"); this.EnableEvents(eventSource, EventLevel.Informational); // Enable information level events } @@ -117,8 +113,6 @@ protected override void OnEventSourceCreated(EventSource eventSource) /// protected override void OnEventWritten(EventWrittenEventArgs eventData) { - Console.WriteLine(); - Console.WriteLine("---------------------------------------------------------------------------------------------------------"); Console.WriteLine($" Event Name: {eventData.EventName}"); Console.WriteLine($" Event Level: {eventData.Level}"); if(eventData.Payload != null) @@ -133,7 +127,7 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData) { Console.WriteLine($" Event Payload: NULL"); } - Console.WriteLine("---------------------------------------------------------------------------------------------------------"); + Console.WriteLine(); } public override void Dispose() diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj index 73556aa3c2..342b8d2571 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj @@ -7,16 +7,6 @@ enable - - - False - 3.33.0-preview - Content - Microsoft.Azure.Cosmos - false - - - From 833e5bd70c7079338f5ecf21ce590a58ff93a9b4 Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Wed, 9 Aug 2023 21:23:32 +0530 Subject: [PATCH 3/5] add comments --- .../CustomDiagnosticAndEventListener.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs index 77534966fe..17348d9a22 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.cs @@ -4,6 +4,12 @@ using System.Diagnostics; using System.Collections.Concurrent; + /// + /// This listener can cover following aspects: + /// 1. Write its own monitoring library with the custom implementation of aggregation or whatever you want to do with this data. + /// 2. Support an APM tool which is not open telemetry compliant. + /// + /// It is a simple sample. Anybody can get as creative as they want to make it better in terms of usability and performance. internal class CustomDiagnosticAndEventListener : EventListener, // Override Event Listener to capture Event source events IObserver>, // Override IObserver to capture Activity events From 567ca5599423d20b5181976869001c71e3c9aa9d Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Thu, 10 Aug 2023 00:49:14 +0530 Subject: [PATCH 4/5] fix appsettings --- .../Usage/ApplicationInsights/AppSettings.json | 5 ----- .../ApplicationInsights/ApplicationInsights.csproj | 8 ++------ .../Usage/ApplicationInsights/Program.cs | 6 ++---- .../AppSettings.json | 4 ---- .../CustomDiagnosticAndEventListener.csproj | 5 ++--- .../CustomDiagnosticAndEventListener/Program.cs | 5 ++--- .../Usage/OpenTelemetry/AppSettings.json | 12 ------------ .../Usage/OpenTelemetry/OpenTelemetry.csproj | 4 +--- .../Usage/OpenTelemetry/Program.cs | 4 ++-- .../Usage/appSettings.json | 10 +++++++++- 10 files changed, 20 insertions(+), 43 deletions(-) delete mode 100644 Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/AppSettings.json delete mode 100644 Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/AppSettings.json delete mode 100644 Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/AppSettings.json diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/AppSettings.json b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/AppSettings.json deleted file mode 100644 index 028030099b..0000000000 --- a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/AppSettings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "CosmosDBEndPointUrl": "https://localhost:8081", - "CosmosDBAuthorizationKey": "Super secret key", - "ApplicationInsightsConnectionString": "Super secret connection string" -} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/ApplicationInsights.csproj b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/ApplicationInsights.csproj index 59162abaca..2ade53a665 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/ApplicationInsights.csproj +++ b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/ApplicationInsights.csproj @@ -1,10 +1,8 @@ - + Exe net6.0 - Cosmos.Samples.ApplicationInsights - Cosmos.Samples.ApplicationInsights latest @@ -15,11 +13,9 @@ - - + PreserveNewest - diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/Program.cs b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/Program.cs index 288ce80c64..fbc1ae7894 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/Program.cs +++ b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/Program.cs @@ -4,12 +4,10 @@ using System.Threading.Tasks; using Newtonsoft.Json; using Microsoft.Azure.Cosmos; - using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.WorkerService; - using Microsoft.Extensions.Logging.ApplicationInsights; internal class Program { @@ -26,13 +24,13 @@ static async Task Main() .AddJsonFile("AppSettings.json") .Build(); - string endpoint = configuration["CosmosDBEndPointUrl"]; + string endpoint = configuration["EndPointUrl"]; if (string.IsNullOrEmpty(endpoint)) { throw new ArgumentNullException("Please specify a valid CosmosDBEndPointUrl in the appSettings.json"); } - string authKey = configuration["CosmosDBAuthorizationKey"]; + string authKey = configuration["AuthorizationKey"]; if (string.IsNullOrEmpty(authKey) || string.Equals(authKey, "Super secret key")) { throw new ArgumentException("Please specify a valid CosmosDBAuthorizationKey in the appSettings.json"); diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/AppSettings.json b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/AppSettings.json deleted file mode 100644 index f6b062537f..0000000000 --- a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/AppSettings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "CosmosDBEndPointUrl": "https://localhost:8081", - "CosmosDBAuthorizationKey": "Super secret key" -} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj index 342b8d2571..eeb17eb145 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/CustomDiagnosticAndEventListener.csproj @@ -1,4 +1,4 @@ - + Exe @@ -12,9 +12,8 @@ - - + PreserveNewest diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/Program.cs b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/Program.cs index 551519d29b..77580936f7 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/Program.cs +++ b/Microsoft.Azure.Cosmos.Samples/Usage/CustomDiagnosticAndEventListener/Program.cs @@ -1,6 +1,5 @@ namespace Cosmos.Samples.ApplicationInsights { - using System.Net; using Microsoft.Azure.Cosmos; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; @@ -17,13 +16,13 @@ static async Task Main() .AddJsonFile("AppSettings.json") .Build(); - string endpoint = configuration["CosmosDBEndPointUrl"]; + string endpoint = configuration["EndPointUrl"]; if (string.IsNullOrEmpty(endpoint)) { throw new ArgumentNullException("Please specify a valid CosmosDBEndPointUrl in the appSettings.json"); } - string authKey = configuration["CosmosDBAuthorizationKey"]; + string authKey = configuration["AuthorizationKey"]; if (string.IsNullOrEmpty(authKey) || string.Equals(authKey, "Super secret key")) { throw new ArgumentException("Please specify a valid CosmosDBAuthorizationKey in the appSettings.json"); diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/AppSettings.json b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/AppSettings.json deleted file mode 100644 index e0d21e3e09..0000000000 --- a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/AppSettings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Logging": { - "OpenTelemetry": { - "LogLevel": { - "Azure.Cosmos.Operation.Request.Diagnostics": "Warning" - } - } - }, - "CosmosDBEndPointUrl": "https://localhost:8081", - "CosmosDBAuthorizationKey": "Super secret key", - "ApplicationInsightsConnectionString": "Super secret connection string" -} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/OpenTelemetry.csproj b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/OpenTelemetry.csproj index 83224d4570..20ddd0e96d 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/OpenTelemetry.csproj +++ b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/OpenTelemetry.csproj @@ -14,11 +14,9 @@ - - + PreserveNewest - diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/Program.cs b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/Program.cs index b4729e41c7..8fb38c3fdb 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/Program.cs +++ b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/Program.cs @@ -28,13 +28,13 @@ static async Task Main() .AddJsonFile("AppSettings.json") .Build(); - string endpoint = configuration["CosmosDBEndPointUrl"]; + string endpoint = configuration["EndPointUrl"]; if (string.IsNullOrEmpty(endpoint)) { throw new ArgumentNullException("Please specify a valid CosmosDBEndPointUrl in the appSettings.json"); } - string authKey = configuration["CosmosDBAuthorizationKey"]; + string authKey = configuration["AuthorizationKey"]; if (string.IsNullOrEmpty(authKey) || string.Equals(authKey, "Super secret key")) { throw new ArgumentException("Please specify a valid CosmosDBAuthorizationKey in the appSettings.json"); diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/appSettings.json b/Microsoft.Azure.Cosmos.Samples/Usage/appSettings.json index 64a8acc501..8285d9b99e 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/appSettings.json +++ b/Microsoft.Azure.Cosmos.Samples/Usage/appSettings.json @@ -1,4 +1,12 @@ { "EndPointUrl": "https://localhost:8081", - "AuthorizationKey": "Super secret key" + "AuthorizationKey": "Super secret key", + "ApplicationInsightsConnectionString": "Super secret connection string", + "Logging": { + "OpenTelemetry": { + "LogLevel": { + "Azure.Cosmos.Operation.Request.Diagnostics": "Warning" + } + } + } } From 4137c58b95e2ead8ffa2002e9c23ed08da433fa5 Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Thu, 10 Aug 2023 01:39:42 +0530 Subject: [PATCH 5/5] revert changes --- .../Usage/ApplicationInsights/AppSettings.json | 5 +++++ .../ApplicationInsights/ApplicationInsights.csproj | 8 ++++++-- .../Usage/ApplicationInsights/Program.cs | 6 ++++-- .../Usage/OpenTelemetry/AppSettings.json | 12 ++++++++++++ .../Usage/OpenTelemetry/OpenTelemetry.csproj | 4 +++- .../Usage/OpenTelemetry/Program.cs | 4 ++-- .../Usage/appSettings.json | 10 +--------- 7 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/AppSettings.json create mode 100644 Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/AppSettings.json diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/AppSettings.json b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/AppSettings.json new file mode 100644 index 0000000000..028030099b --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/AppSettings.json @@ -0,0 +1,5 @@ +{ + "CosmosDBEndPointUrl": "https://localhost:8081", + "CosmosDBAuthorizationKey": "Super secret key", + "ApplicationInsightsConnectionString": "Super secret connection string" +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/ApplicationInsights.csproj b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/ApplicationInsights.csproj index 2ade53a665..59162abaca 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/ApplicationInsights.csproj +++ b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/ApplicationInsights.csproj @@ -1,8 +1,10 @@ - + Exe net6.0 + Cosmos.Samples.ApplicationInsights + Cosmos.Samples.ApplicationInsights latest @@ -13,9 +15,11 @@ + - + PreserveNewest + diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/Program.cs b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/Program.cs index fbc1ae7894..288ce80c64 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/Program.cs +++ b/Microsoft.Azure.Cosmos.Samples/Usage/ApplicationInsights/Program.cs @@ -4,10 +4,12 @@ using System.Threading.Tasks; using Newtonsoft.Json; using Microsoft.Azure.Cosmos; + using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.WorkerService; + using Microsoft.Extensions.Logging.ApplicationInsights; internal class Program { @@ -24,13 +26,13 @@ static async Task Main() .AddJsonFile("AppSettings.json") .Build(); - string endpoint = configuration["EndPointUrl"]; + string endpoint = configuration["CosmosDBEndPointUrl"]; if (string.IsNullOrEmpty(endpoint)) { throw new ArgumentNullException("Please specify a valid CosmosDBEndPointUrl in the appSettings.json"); } - string authKey = configuration["AuthorizationKey"]; + string authKey = configuration["CosmosDBAuthorizationKey"]; if (string.IsNullOrEmpty(authKey) || string.Equals(authKey, "Super secret key")) { throw new ArgumentException("Please specify a valid CosmosDBAuthorizationKey in the appSettings.json"); diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/AppSettings.json b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/AppSettings.json new file mode 100644 index 0000000000..e0d21e3e09 --- /dev/null +++ b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/AppSettings.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "OpenTelemetry": { + "LogLevel": { + "Azure.Cosmos.Operation.Request.Diagnostics": "Warning" + } + } + }, + "CosmosDBEndPointUrl": "https://localhost:8081", + "CosmosDBAuthorizationKey": "Super secret key", + "ApplicationInsightsConnectionString": "Super secret connection string" +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/OpenTelemetry.csproj b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/OpenTelemetry.csproj index 20ddd0e96d..83224d4570 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/OpenTelemetry.csproj +++ b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/OpenTelemetry.csproj @@ -14,9 +14,11 @@ + - + PreserveNewest + diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/Program.cs b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/Program.cs index 8fb38c3fdb..b4729e41c7 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/Program.cs +++ b/Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/Program.cs @@ -28,13 +28,13 @@ static async Task Main() .AddJsonFile("AppSettings.json") .Build(); - string endpoint = configuration["EndPointUrl"]; + string endpoint = configuration["CosmosDBEndPointUrl"]; if (string.IsNullOrEmpty(endpoint)) { throw new ArgumentNullException("Please specify a valid CosmosDBEndPointUrl in the appSettings.json"); } - string authKey = configuration["AuthorizationKey"]; + string authKey = configuration["CosmosDBAuthorizationKey"]; if (string.IsNullOrEmpty(authKey) || string.Equals(authKey, "Super secret key")) { throw new ArgumentException("Please specify a valid CosmosDBAuthorizationKey in the appSettings.json"); diff --git a/Microsoft.Azure.Cosmos.Samples/Usage/appSettings.json b/Microsoft.Azure.Cosmos.Samples/Usage/appSettings.json index 8285d9b99e..64a8acc501 100644 --- a/Microsoft.Azure.Cosmos.Samples/Usage/appSettings.json +++ b/Microsoft.Azure.Cosmos.Samples/Usage/appSettings.json @@ -1,12 +1,4 @@ { "EndPointUrl": "https://localhost:8081", - "AuthorizationKey": "Super secret key", - "ApplicationInsightsConnectionString": "Super secret connection string", - "Logging": { - "OpenTelemetry": { - "LogLevel": { - "Azure.Cosmos.Operation.Request.Diagnostics": "Warning" - } - } - } + "AuthorizationKey": "Super secret key" }