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

feat: Check-In Upserts #3330

Merged
merged 37 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4337094
added missing properties
bitsandfoxes Apr 22, 2024
f3e54e4
enriching checkins
bitsandfoxes Apr 24, 2024
d3097ea
adding the trace id to the check-in
bitsandfoxes Apr 24, 2024
16f7bcd
simplify
bitsandfoxes Apr 24, 2024
c527a33
tests
bitsandfoxes Apr 25, 2024
bfc4098
real tests
bitsandfoxes Apr 25, 2024
4431428
Updated CHANGELOG.md
bitsandfoxes Apr 25, 2024
0111dcc
verify
bitsandfoxes Apr 25, 2024
b04d045
Merge branch 'main' into fix/crons-1
bitsandfoxes Apr 25, 2024
e1832d1
Merge branch 'fix/crons-1' of https://github.com/getsentry/sentry-dot…
bitsandfoxes Apr 25, 2024
8dfe884
Update test/Sentry.Tests/HubTests.cs
bitsandfoxes Apr 25, 2024
7803f45
added monitor config to checkins
bitsandfoxes Apr 25, 2024
45a283d
.
bitsandfoxes Apr 26, 2024
d8e7525
fixed test
bitsandfoxes Apr 26, 2024
fa23112
.
bitsandfoxes Apr 26, 2024
7cad476
verify
bitsandfoxes Apr 26, 2024
775b908
merge
bitsandfoxes Apr 26, 2024
d549bbb
iterating on it
bitsandfoxes May 6, 2024
77cdd2f
Merge branch 'main' into fix/crons-2
bitsandfoxes May 6, 2024
fbb0017
Merge branch 'main' into fix/crons-2
bitsandfoxes May 21, 2024
9d25bc5
pass the config callback to the client
bitsandfoxes May 21, 2024
a485094
tests
bitsandfoxes May 21, 2024
f9297ad
verify
bitsandfoxes May 21, 2024
899cf7f
timezones. how about no
bitsandfoxes May 21, 2024
f5f6c81
verify
bitsandfoxes May 21, 2024
ece0995
Updated CHANGELOG.md
bitsandfoxes May 21, 2024
c3149de
Updated CHANGELOG.md
bitsandfoxes May 21, 2024
2490e22
forward options
bitsandfoxes May 24, 2024
a81774c
validating crontab
bitsandfoxes May 24, 2024
07dcc56
.
bitsandfoxes May 24, 2024
a868b2e
Merge branch 'main' into fix/crons-2
bitsandfoxes May 24, 2024
5a30c16
verify
bitsandfoxes May 24, 2024
f23ab39
Merge branch 'fix/crons-2' of https://github.com/getsentry/sentry-dot…
bitsandfoxes May 24, 2024
4b28b64
Merge branch 'main' into fix/crons-2
bitsandfoxes May 27, 2024
5554bd4
regex optimization
bitsandfoxes May 28, 2024
cf2cec3
fixes
bitsandfoxes May 28, 2024
8875318
verify
bitsandfoxes May 28, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Features

- The SDK now supports monitor upserting. You can programmatically set up your monitors via the options callback in `SentrySdk.CaptureCheckIn` ([#3330](https://github.com/getsentry/sentry-dotnet/pull/3330))
- Added an `SentrySdk.RunAsyncVoid` helper method that lets you capture exceptions from `async void` methods ([#3379](https://github.com/getsentry/sentry-dotnet/pull/3379))

### Fixes
Expand Down
9 changes: 9 additions & 0 deletions src/Sentry/Extensibility/DiagnosticLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ public static void LogError(
string message)
=> logger.LogIfEnabled(SentryLevel.Error, null, message);

/// <summary>
/// Log an error message.
/// </summary>
public static void LogError<TArg>(
this IDiagnosticLogger logger,
string message,
TArg arg)
=> logger.LogIfEnabled(SentryLevel.Error, null, message, arg);

/// <summary>
/// Log an exception with an error message.
/// </summary>
Expand Down
9 changes: 7 additions & 2 deletions src/Sentry/Extensibility/DisabledHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,13 @@ public void CaptureSession(SessionUpdate sessionUpdate)
/// <summary>
/// No-Op
/// </summary>
public SentryId CaptureCheckIn(string monitorSlug, CheckInStatus status, SentryId? sentryId = null,
TimeSpan? duration = null, Scope? scope = null)
public SentryId CaptureCheckIn(
string monitorSlug,
CheckInStatus status,
SentryId? sentryId = null,
TimeSpan? duration = null,
Scope? scope = null,
Action<SentryMonitorOptions>? configureMonitorOptions = null)
=> SentryId.Empty;

/// <summary>
Expand Down
11 changes: 8 additions & 3 deletions src/Sentry/Extensibility/HubAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,14 @@ public void CaptureSession(SessionUpdate sessionUpdate)
/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>.
/// </summary>
public SentryId CaptureCheckIn(string monitorSlug, CheckInStatus status, SentryId? sentryId = null,
TimeSpan? duration = null, Scope? scope = null)
=> SentrySdk.CaptureCheckIn(monitorSlug, status, sentryId, duration);
public SentryId CaptureCheckIn(
string monitorSlug,
CheckInStatus status,
SentryId? sentryId = null,
TimeSpan? duration = null,
Scope? scope = null,
Action<SentryMonitorOptions>? monitorOptions = null)
=> SentrySdk.CaptureCheckIn(monitorSlug, status, sentryId, duration, scope, monitorOptions);

/// <summary>
/// Forwards the call to <see cref="SentrySdk"/>
Expand Down
9 changes: 7 additions & 2 deletions src/Sentry/ISentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ public interface ISentryClient
/// <param name="sentryId"></param>
/// <param name="duration"></param>
/// <param name="scope"></param>
SentryId CaptureCheckIn(string monitorSlug, CheckInStatus status, SentryId? sentryId = null,
TimeSpan? duration = null, Scope? scope = null);
/// <param name="configureMonitorOptions">The optional monitor config used to create a Check-In programmatically.</param>
SentryId CaptureCheckIn(string monitorSlug,
CheckInStatus status,
SentryId? sentryId = null,
TimeSpan? duration = null,
Scope? scope = null,
Action<SentryMonitorOptions>? configureMonitorOptions = null);

/// <summary>
/// Flushes the queue of captured events until the timeout is reached.
Expand Down
10 changes: 7 additions & 3 deletions src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,13 @@ public void CaptureSession(SessionUpdate sessionUpdate)
}
}

public SentryId CaptureCheckIn(string monitorSlug, CheckInStatus status, SentryId? sentryId = null,
public SentryId CaptureCheckIn(
string monitorSlug,
CheckInStatus status,
SentryId? sentryId = null,
TimeSpan? duration = null,
Scope? scope = null)
Scope? scope = null,
Action<SentryMonitorOptions>? configureMonitorOptions = null)
{
if (!IsEnabled)
{
Expand All @@ -580,7 +584,7 @@ public SentryId CaptureCheckIn(string monitorSlug, CheckInStatus status, SentryI
scope = currentScope;
}

return _ownedClient.CaptureCheckIn(monitorSlug, status, sentryId, duration, scope);
return _ownedClient.CaptureCheckIn(monitorSlug, status, sentryId, duration, scope, configureMonitorOptions);
}
catch (Exception e)
{
Expand Down
18 changes: 13 additions & 5 deletions src/Sentry/SentryCheckIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Sentry;

/// <summary>
/// The Checkin Status
/// The Check-In Status
/// </summary>
public enum CheckInStatus
{
Expand All @@ -25,13 +25,13 @@ public enum CheckInStatus
}

/// <summary>
/// Sentry Checkin
/// Sentry Check-In
/// </summary>
// https://develop.sentry.dev/sdk/check-ins/
public class SentryCheckIn : ISentryJsonSerializable
{
/// <summary>
/// CheckIn ID
/// Check-In ID
/// </summary>
public SentryId Id { get; }

Expand All @@ -40,13 +40,14 @@ public class SentryCheckIn : ISentryJsonSerializable
/// </summary>
public string MonitorSlug { get; }


/// <summary>
/// The status of the Checkin
/// The status of the Check-In
/// </summary>
public CheckInStatus Status { get; }

/// <summary>
/// The duration of the check-in in seconds. Will only take effect if the status is ok or error.
/// The duration of the Check-In in seconds. Will only take effect if the status is ok or error.
/// </summary>
public TimeSpan? Duration { get; set; }

Expand All @@ -65,6 +66,11 @@ public class SentryCheckIn : ISentryJsonSerializable
/// </summary>
internal SentryId? TraceId { get; set; }

/// <summary>
/// The Monitor Config
/// </summary>
internal SentryMonitorOptions? MonitorOptions { get; set; }

/// <summary>
/// Initializes a new instance of <see cref="SentryCheckIn"/>.
/// </summary>
Expand Down Expand Up @@ -103,6 +109,8 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
writer.WriteEndObject();
}

MonitorOptions?.WriteTo(writer, logger);

writer.WriteEndObject();
}

Expand Down
17 changes: 15 additions & 2 deletions src/Sentry/SentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,13 @@ public void CaptureSession(SessionUpdate sessionUpdate)
=> CaptureEnvelope(Envelope.FromSession(sessionUpdate));

/// <inheritdoc />
public SentryId CaptureCheckIn(string monitorSlug, CheckInStatus status, SentryId? sentryId = null, TimeSpan? duration = null, Scope? scope = null)
public SentryId CaptureCheckIn(
string monitorSlug,
CheckInStatus status,
SentryId? sentryId = null,
TimeSpan? duration = null,
Scope? scope = null,
Action<SentryMonitorOptions>? configureMonitorOptions = null)
{
scope ??= new Scope(_options);

Expand All @@ -234,9 +240,16 @@ public SentryId CaptureCheckIn(string monitorSlug, CheckInStatus status, SentryI
var checkIn = new SentryCheckIn(monitorSlug, status, sentryId)
{
Duration = duration,
TraceId = traceId
TraceId = traceId,
};

if (configureMonitorOptions is not null)
{
var monitorOptions = new SentryMonitorOptions();
configureMonitorOptions.Invoke(monitorOptions);
checkIn.MonitorOptions = monitorOptions;
}

_enricher.Apply(checkIn);

return CaptureEnvelope(Envelope.FromCheckIn(checkIn))
Expand Down
Loading
Loading