Skip to content

Commit

Permalink
Filtering Sentry events (#188)
Browse files Browse the repository at this point in the history
Filtering out errors that don't involve Codi.

## Test plan
Watch for new errors in Sentry to see if they involve Codi
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

Co-authored-by: Tomasz Gołębiowski <tgolebiowski@virtuslab.com>
  • Loading branch information
tomaszgolebiowski and Tomasz Gołębiowski authored Jan 3, 2025
1 parent 35144e8 commit ca2008c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/Cody.Core/Cody.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
<Compile Include="Infrastructure\IProgressService.cs" />
<Compile Include="Logging\ISentryLog.cs" />
<Compile Include="Logging\ITestLogger.cs" />
<Compile Include="Logging\SentryExceptionFilter.cs" />
<Compile Include="Logging\SentryLog.cs" />
<Compile Include="Trace\FileTraceListener.cs" />
<Compile Include="Trace\LogioTraceListener.cs" />
Expand Down
1 change: 0 additions & 1 deletion src/Cody.Core/DocumentSync/DocumentSyncCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public void OnFocus(string fullPath)
{
trace.TraceEvent("DidFocus", "{0}", fullPath);
agentService.DidFocus(new CodyFilePath { Uri = ToUri(fullPath) });

}

public void OnOpened(string fullPath, string content, DocumentRange visibleRange, DocumentRange selection)
Expand Down
32 changes: 0 additions & 32 deletions src/Cody.Core/Logging/SentryExceptionFilter.cs

This file was deleted.

25 changes: 24 additions & 1 deletion src/Cody.Core/Logging/SentryLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
using Sentry;
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;

namespace Cody.Core.Logging
{
public class SentryLog : ISentryLog
{
public const string CodyAssemblyPrefix = "Cody.";

public void Error(Exception exception)
{
SentrySdk.CaptureException(exception);
Expand All @@ -30,9 +33,29 @@ public static void Initialize()
{
options.Dsn = "https://d129345ba8e1848a01435eb2596ca899@o19358.ingest.us.sentry.io/4508375896752129";
options.IsGlobalModeEnabled = true;
options.MaxBreadcrumbs = 10;
options.Environment = env;
options.Release = "cody-vs@" + version.ToString();
options.AddExceptionFilter(new SentryExceptionFilter());
options.SetBeforeSend(se =>
{
if (se.Exception?.Source?.StartsWith(CodyAssemblyPrefix) ?? false) return se;
if (se.Exception?.InnerException?.Source?.StartsWith(CodyAssemblyPrefix) ?? false) return se;
if (se.SentryExceptions == null) return se;

foreach(var ex in se.SentryExceptions)
{
if (ex.Module?.StartsWith(CodyAssemblyPrefix) ?? false) return se;
if (ex.Stacktrace != null)
{
foreach (var frame in ex.Stacktrace.Frames)
{
if (frame.Package?.StartsWith(CodyAssemblyPrefix) ?? false) return se;
}
}
}

return null;
});
});
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Cody.VisualStudio/Client/AgentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public async Task<IAgentService> Initialize(ClientInfo clientInfo)

private void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e)
{
log.Error($"Agent disconnected due to {e.Description} (reason: {e.Reason})", e.Exception);
if(e.Exception != null)
log.Error($"Agent disconnected due to {e.Description} (reason: {e.Reason})", e.Exception);
else
log.Info($"Agent disconnected due to {e.Description} (reason: {e.Reason})");
}

private void CreateAgentService()
Expand Down

0 comments on commit ca2008c

Please sign in to comment.