Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"Logging": {
"LogLevel": {
"Azure-Cosmos-Operation-Request-Diagnostics": "Information"
"OpenTelemetry": {
"LogLevel": {
"Azure.Cosmos.Operation.Request.Diagnostics": "Warning"
}
}
},
"CosmosDBEndPointUrl": "https://localhost:8081",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.0.0-beta.10" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.33.0-preview" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.3" />
<PackageReference Include="OpenTelemetry" Version="1.4.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="7.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
</ItemGroup>

Expand Down
31 changes: 22 additions & 9 deletions Microsoft.Azure.Cosmos.Samples/Usage/OpenTelemetry/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ static async Task Main()
try
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.AddJsonFile("AppSettings.json")
.Build();
.AddJsonFile("AppSettings.json")
.Build();

string endpoint = configuration["CosmosDBEndPointUrl"];
if (string.IsNullOrEmpty(endpoint))
Expand All @@ -52,12 +52,16 @@ static async Task Main()
serviceVersion: "1.0.0");

// Set up logging to forward logs to chosen exporter
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddOpenTelemetry(options =>
{
options.IncludeFormattedMessage = true;
options.SetResourceBuilder(resource);
options.AddAzureMonitorLogExporter(o => o.ConnectionString = aiConnectionString); // Set up exporter of your choice
}));
using ILoggerFactory loggerFactory
= LoggerFactory.Create(builder => builder
.AddConfiguration(configuration.GetSection("Logging"))
.AddOpenTelemetry(options =>
{
options.IncludeFormattedMessage = true;
options.SetResourceBuilder(resource);
options.AddAzureMonitorLogExporter(o => o.ConnectionString = aiConnectionString); // Set up exporter of your choice
}));
/*.AddFilter(level => level == LogLevel.Error) // Filter is irrespective of event type or event name*/

AzureEventSourceLogForwarder logforwader = new AzureEventSourceLogForwarder(loggerFactory);
logforwader.Start();
Expand All @@ -76,6 +80,7 @@ static async Task Main()
{
IsDistributedTracingEnabled = true // Defaults to true, set to false to disable
};

// </EnableDistributedTracing>
using (CosmosClient client = new CosmosClient(endpoint, authKey, options))
{
Expand All @@ -88,7 +93,6 @@ static async Task Main()

await Program.RunCrudDemo(container);
}

}
finally
{
Expand Down Expand Up @@ -116,6 +120,15 @@ public static async Task RunCrudDemo(Container container)
Console.WriteLine($"Read document with id: {i}");
}

try
{
await container.ReadItemAsync<Item>($"random key", new PartitionKey($"random partition"));
}
catch(Exception)
{
Console.WriteLine("Generate exception by reading an invalid key");
}

for (int i = 1; i <= 5; i++)
{
await container.ReplaceItemAsync(new Item { Id = $"{i}", Status = "updated" }, $"{i}", new PartitionKey($"{i}"));
Expand Down