Skip to content
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

Enable message logging in Sentry #215

Merged
merged 1 commit into from
Feb 4, 2025
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
4 changes: 2 additions & 2 deletions src/Cody.Core/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Error(string message, [CallerMemberName] string callerName = "")
// TODO: _fileLogger.Error(customMessage);
DebugWrite(customMessage);
_outputWindowPane?.Error(message, callerName);
_sentryLog?.Error(customMessage, callerName);
_sentryLog?.Error(message, callerName);
_testLogger?.WriteLog(message, "ERROR", callerName);
}

Expand All @@ -87,7 +87,7 @@ public void Error(string message, Exception ex, [CallerMemberName] string caller
// TODO: _fileLogger.Error(originalException, customMessage);
DebugWrite(customMessage);
_outputWindowPane?.Error(outputMessage, callerName);
_sentryLog?.Error(outputMessage, originalException, callerName);
_sentryLog?.Error(message, originalException, callerName);
_testLogger?.WriteLog(message, "ERROR", callerName);
}

Expand Down
17 changes: 13 additions & 4 deletions src/Cody.Core/Logging/SentryLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@ namespace Cody.Core.Logging
public class SentryLog : ISentryLog
{
public const string CodyAssemblyPrefix = "Cody.";
public const string ErrorData = "ErrorData";

public void Error(string message, Exception ex, [CallerMemberName] string callerName = "")
{
SentrySdk.CaptureException(ex, scope =>
{
scope.SetExtra(nameof(callerName), callerName);
scope.SetExtra(nameof(message), message);
scope.Contexts[ErrorData] = new
{
Message = message,
CallerName = callerName,
};
});
}

public void Error(string message, [CallerMemberName] string callerName = "")
{
SentrySdk.CaptureMessage(message, scope =>
{
scope.SetExtra(nameof(callerName), callerName);
scope.Contexts[ErrorData] = new
{
Message = message,
CallerName = callerName,
};
});
}

Expand All @@ -49,9 +57,10 @@ public static void Initialize()
if (se.Exception?.Source?.StartsWith(CodyAssemblyPrefix) ?? false) return se;
if (se.Exception?.InnerException?.Source?.StartsWith(CodyAssemblyPrefix) ?? false) return se;
if (se.Message != null) return se;
if (se.Contexts.ContainsKey(ErrorData)) return se;
if (se.SentryExceptions == null) return se;

foreach(var ex in se.SentryExceptions)
foreach (var ex in se.SentryExceptions)
{
if (ex.Module?.StartsWith(CodyAssemblyPrefix) ?? false) return se;
if (ex.Stacktrace != null)
Expand Down
6 changes: 3 additions & 3 deletions src/Cody.VisualStudio/Client/AgentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public async Task<IAgentService> Initialize(ClientInfo clientInfo)

private void OnDisconnected(object sender, JsonRpcDisconnectedEventArgs e)
{
if(e.Exception != null)
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})");
log.Error($"Agent disconnected due to {e.Description} (reason: {e.Reason})");
}

private void CreateAgentService()
Expand Down Expand Up @@ -139,7 +139,7 @@ public void Stop()

private void DisconnectInternal()
{
jsonRpc.Dispose();
if (!jsonRpc.IsDisposed) jsonRpc.Dispose();
connector.ErrorReceived -= OnErrorReceived;
connector.Disconnected -= OnAgentDisconnected;
connector.Disconnect();
Expand Down
1 change: 0 additions & 1 deletion src/Cody.VisualStudio/CodyPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ private void ReportSentryVsVersion()
{
scope.SetTag("vs", VsVersionService.DisplayVersion);
scope.SetTag("agent", VersionService.Agent);
SentrySdk.CaptureMessage("Initialized");
});
}

Expand Down
Loading