-
-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes when auditing to CosmosDB a CosmosException occurs #625
Comments
Looks like you're getting a timeout from cosmosDB when trying to save the audit event. Is your audit event too large? Have you seen Diagnose and troubleshoot Azure Cosmos DB .NET SDK request timeout exceptions? Maybe you need to customize the timeout. |
You could be right about the audit event size. I'll dive into that. |
Also, you could implement your own data provider, by inheriting from For example: public class AzureCosmosCustomProvider : AzureCosmosDataProvider
{
public AzureCosmosCustomProvider() : base() { }
public AzureCosmosCustomProvider(Action<IAzureCosmosProviderConfigurator> config) : base(config) { }
public override object InsertEvent(AuditEvent auditEvent)
{
try
{
return base.InsertEvent(auditEvent);
}
catch (CosmosException ex) when (ex.StatusCode == HttpStatusCode.RequestTimeout)
{
// timed out
return null;
}
}
public override async Task<object> InsertEventAsync(AuditEvent auditEvent, CancellationToken cancellationToken = default)
{
try
{
return await base.InsertEventAsync(auditEvent, cancellationToken);
}
catch (CosmosException ex) when (ex.StatusCode == HttpStatusCode.RequestTimeout)
{
// timed out
return null;
}
}
} Then you can set up the data provider like this: Audit.Core.Configuration.Setup()
.Use(new AzureCosmosCustomProvider(_ => _
.Endpoint(...)
.Database(...)
.Container(...)
.AuthKey(...))); |
If you're looking for a retry mechanism. check this: #372 (comment) |
A big thanks, your suggestions will solve my issue 👍 |
Describe the bug
Sometimes when auditing to CosmosDB a CosmosException occurs in
Audit.AzureCosmos.Providers.AzureCosmosDataProvider+d__39.MoveNext
Expected behavior
Audit exceptions should not stop the code flow
Libraries (specify the Audit.NET extensions being used including version):
For example:
Target .NET framework:
For example:
Additional context
Response status code does not indicate success: RequestTimeout (408);
Microsoft.Azure.Cosmos.CosmosException:
at Microsoft.Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode (Microsoft.Azure.Cosmos.Client, Version=3.35.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.ProcessMessage (Microsoft.Azure.Cosmos.Client, Version=3.35.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.Azure.Cosmos.ContainerCore+d__56
1.MoveNext (Microsoft.Azure.Cosmos.Client, Version=3.35.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.Azure.Cosmos.ClientContextCore+<RunWithDiagnosticsHelperAsync>d__40
1.MoveNext (Microsoft.Azure.Cosmos.Client, Version=3.35.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.Cosmos.ClientContextCore+d__30`1.MoveNext (Microsoft.Azure.Cosmos.Client, Version=3.35.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Audit.AzureCosmos.Providers.AzureCosmosDataProvider+d__39.MoveNext (Audit.NET.AzureCosmos, Version=21.0.3.0, Culture=neutral, PublicKeyToken=571d6b80b242c87e)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Audit.Core.AuditScope+d__41.MoveNext (Audit.NET, Version=21.0.3.0, Culture=neutral, PublicKeyToken=571d6b80b242c87e)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Audit.Core.AuditScope+d__35.MoveNext (Audit.NET, Version=21.0.3.0, Culture=neutral, PublicKeyToken=571d6b80b242c87e)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Audit.EntityFramework.DbContextHelper+d__23.MoveNext (Audit.EntityFramework.Core, Version=21.0.3.0, Culture=neutral, PublicKeyToken=571d6b80b242c87e)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Audit.EntityFramework.DbContextHelper+d__40.MoveNext (Audit.EntityFramework.Core, Version=21.0.3.0, Culture=neutral, PublicKeyToken=571d6b80b242c87e)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Audit.EntityFramework.DbContextHelper+d__37.MoveNext (Audit.EntityFramework.Core, Version=21.0.3.0, Culture=neutral, PublicKeyToken=571d6b80b242c87e)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Audit.EntityFramework.AuditDbContext+d__57.MoveNext (Audit.EntityFramework.Core, Version=21.0.3.0, Culture=neutral, PublicKeyToken=571d6b80b242c87e)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Fiberworkz.Database.FiberworkzDbContext+d__92.MoveNext (Fiberworkz.Database, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: /home/runner/work/fiberworkz/fiberworkz/Fiberworkz.Database/FiberworkzDbContext.cs:75)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at ConnectedApp.ConnectedAppUpdateService+d__11.MoveNext (ConnectedApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: /home/runner/work/fiberworkz/fiberworkz/ConnectedApp.Domain/ConnectedAppUpdateService.cs:135)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at ConnectedApp.ConnectedAppUpdateService+d__10.MoveNext (ConnectedApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: /home/runner/work/fiberworkz/fiberworkz/ConnectedApp.Domain/ConnectedAppUpdateService.cs:85)
The text was updated successfully, but these errors were encountered: