Skip to content

Commit

Permalink
feat: Renamed Sentry.User to SentryUser (#3015)
Browse files Browse the repository at this point in the history
* renamed

* Updated CHANGELOG.md

* verify

* Update CHANGELOG.md

---------

Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
  • Loading branch information
bitsandfoxes and bruno-garcia authored Jan 8, 2024
1 parent cfad9a5 commit f93d62b
Show file tree
Hide file tree
Showing 33 changed files with 155 additions and 149 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

### API breaking Changes

#### Changed APIs

- Class renamed `Sentry.User` to `Sentry.SentryUser` ([#3015](https://github.com/getsentry/sentry-dotnet/pull/3015))

### Dependencies

- Bump CLI from v2.23.2 to v2.24.1 ([#3012](https://github.com/getsentry/sentry-dotnet/pull/3012))
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override void OnCreate(Bundle? savedInstanceState)
{
scope.AddBreadcrumb("Custom Breadcrumb");
scope.SetExtra("Test", "Custom Extra Data");
scope.User = new User
scope.User = new SentryUser
{
Username = "SomeUser",
Email = "test@example.com",
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry.AspNetCore/DefaultUserFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public DefaultUserFactory(IHttpContextAccessor httpContextAccessor)
_httpContextAccessor = httpContextAccessor;
}

public User? Create() => _httpContextAccessor?.HttpContext is {} httpContext ? Create(httpContext) : null;
public SentryUser? Create() => _httpContextAccessor?.HttpContext is {} httpContext ? Create(httpContext) : null;

public User? Create(HttpContext context)
public SentryUser? Create(HttpContext context)
{
var principal = context.User;
if (principal is null)
Expand Down Expand Up @@ -56,7 +56,7 @@ public DefaultUserFactory(IHttpContextAccessor httpContextAccessor)

return email is null && id is null && username is null && ipAddress is null
? null
: new User
: new SentryUser
{
Id = id,
Email = email,
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Log4Net/SentryAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected override void Append(LoggingEvent loggingEvent)

if (SendIdentity && !string.IsNullOrEmpty(loggingEvent.Identity))
{
evt.User = new User
evt.User = new SentryUser
{
Id = loggingEvent.Identity
};
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry.NLog/SentryTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private void InnerWrite(LogEventInfo logEvent)
Level = logEvent.Level.ToSentryLevel(),
Release = Options.Release,
Environment = Options.Environment,
User = GetUser(logEvent) ?? new User(),
User = GetUser(logEvent) ?? new SentryUser(),
};

if (evt.Sdk is { } sdk)
Expand Down Expand Up @@ -439,14 +439,14 @@ private void InnerWrite(LogEventInfo logEvent)
}
}

private User? GetUser(LogEventInfo logEvent)
private SentryUser? GetUser(LogEventInfo logEvent)
{
if (User is null)
{
return null;
}

var user = new User
var user = new SentryUser
{
Id = User.Id?.Render(logEvent),
Username = User.Username?.Render(logEvent),
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/IEventLike.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface IEventLike : IHasTags, IHasExtra
/// <value>
/// The user.
/// </value>
User User { get; set; }
SentryUser User { get; set; }

/// <summary>
/// The release version of the application.
Expand Down Expand Up @@ -194,7 +194,7 @@ public static void AddBreadcrumb(
}

/// <summary>
/// Whether a <see cref="User"/> has been set to the object with any of its fields non null.
/// Whether a <see cref="SentryUser"/> has been set to the object with any of its fields non null.
/// </summary>
public static bool HasUser(this IEventLike eventLike) => eventLike.User.HasAnyData();

Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/IScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public interface IScopeObserver
/// <summary>
/// Sets the user information.
/// </summary>
void SetUser(User? user);
void SetUser(SentryUser? user);
}
4 changes: 2 additions & 2 deletions src/Sentry/ISentryUserFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Sentry;
public interface ISentryUserFactory
{
/// <summary>
/// Creates a Sentry <see cref="User"/> representing the current principal.
/// Creates a Sentry <see cref="SentryUser"/> representing the current principal.
/// </summary>
/// <returns>The protocol user</returns>
public User? Create();
public SentryUser? Create();
}
2 changes: 1 addition & 1 deletion src/Sentry/Internal/NoOpTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Contexts Contexts{
set { }
}

public User User
public SentryUser User
{
get => new();
set { }
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/Internal/ScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void UnsetTag(string key)

public abstract void UnsetTagImpl(string key);

public void SetUser(User? user)
public void SetUser(SentryUser? user)
{
if (user is null)
{
Expand All @@ -82,7 +82,7 @@ public void SetUser(User? user)
}
}

public abstract void SetUserImpl(User user);
public abstract void SetUserImpl(SentryUser user);

public abstract void UnsetUserImpl();
}
2 changes: 1 addition & 1 deletion src/Sentry/Platforms/Android/AndroidScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void UnsetTag(string key)
}
}

public void SetUser(User? user)
public void SetUser(SentryUser? user)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/Platforms/Android/Extensions/UserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ internal static class UserExtensions
private static readonly IDictionary<string, string> EmptyDictionary =
new ReadOnlyDictionary<string, string>(new Dictionary<string, string>());

public static User ToUser(this JavaSdk.Protocol.User user) =>
public static SentryUser ToUser(this JavaSdk.Protocol.User user) =>
new()
{
Email = user.Email,
Expand All @@ -16,7 +16,7 @@ public static User ToUser(this JavaSdk.Protocol.User user) =>
Other = user.Data ?? EmptyDictionary
};

public static JavaSdk.Protocol.User ToJavaUser(this User user) =>
public static JavaSdk.Protocol.User ToJavaUser(this SentryUser user) =>
new()
{
Email = user.Email,
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void UnsetTag(string key)
}
}

public void SetUser(User? user)
public void SetUser(SentryUser? user)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/Platforms/Cocoa/Extensions/UserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Sentry.Cocoa.Extensions;

internal static class UserExtensions
{
public static User ToUser(this CocoaSdk.SentryUser user, IDiagnosticLogger? logger = null) =>
public static SentryUser ToUser(this CocoaSdk.SentryUser user, IDiagnosticLogger? logger = null) =>
new()
{
Email = user.Email,
Expand All @@ -15,7 +15,7 @@ public static User ToUser(this CocoaSdk.SentryUser user, IDiagnosticLogger? logg
Other = user.Data.ToStringDictionary(logger)
};

public static CocoaSdk.SentryUser ToCocoaUser(this User user)
public static CocoaSdk.SentryUser ToCocoaUser(this SentryUser user)
{
var cocoaUser = new CocoaSdk.SentryUser
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Platforms/Native/NativeScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void SetExtraImpl(string key, string? value) =>

public override void UnsetTagImpl(string key) => C.sentry_remove_tag(key);

public override void SetUserImpl(User user)
public override void SetUserImpl(SentryUser user)
{
// see https://develop.sentry.dev/sdk/event-payloads/user/
var cUser = C.sentry_value_new_object();
Expand Down
8 changes: 4 additions & 4 deletions src/Sentry/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Contexts Contexts
}

// Internal for testing.
internal Action<User?> UserChanged => user =>
internal Action<SentryUser?> UserChanged => user =>
{
if (Options.EnableScopeSync &&
Options.ScopeObserver is { } observer)
Expand All @@ -116,12 +116,12 @@ public Contexts Contexts
}
};

private User? _user;
private SentryUser? _user;

/// <inheritdoc />
public User User
public SentryUser User
{
get => _user ??= new User
get => _user ??= new SentryUser
{
PropertyChanged = UserChanged
};
Expand Down
8 changes: 4 additions & 4 deletions src/Sentry/SentryEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ public Contexts Contexts
set => _contexts.ReplaceWith(value);
}

private User? _user;
private SentryUser? _user;

/// <inheritdoc />
public User User
public SentryUser User
{
get => _user ??= new User();
get => _user ??= new SentryUser();
set => _user = value;
}

Expand Down Expand Up @@ -304,7 +304,7 @@ internal static SentryEvent FromJson(JsonElement json, Exception? exception)
var transaction = json.GetPropertyOrNull("transaction")?.GetString();
var request = json.GetPropertyOrNull("request")?.Pipe(Request.FromJson);
var contexts = json.GetPropertyOrNull("contexts")?.Pipe(Contexts.FromJson);
var user = json.GetPropertyOrNull("user")?.Pipe(User.FromJson);
var user = json.GetPropertyOrNull("user")?.Pipe(SentryUser.FromJson);
var environment = json.GetPropertyOrNull("environment")?.GetString();
var sdk = json.GetPropertyOrNull("sdk")?.Pipe(SdkVersion.FromJson) ?? new SdkVersion();
var fingerprint = json.GetPropertyOrNull("fingerprint")?.EnumerateArray().Select(j => j.GetString()).ToArray();
Expand Down
16 changes: 8 additions & 8 deletions src/Sentry/User.cs → src/Sentry/SentryUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace Sentry;
/// An interface which describes the authenticated User for a request.
/// </summary>
/// <see href="https://develop.sentry.dev/sdk/event-payloads/user/"/>
public sealed class User : IJsonSerializable
public sealed class SentryUser : IJsonSerializable
{
internal Action<User>? PropertyChanged { get; set; }
internal Action<SentryUser>? PropertyChanged { get; set; }

private string? _id;
private string? _username;
Expand Down Expand Up @@ -115,17 +115,17 @@ public IDictionary<string, string> Other
}

/// <summary>
/// Clones the current <see cref="User"/> instance.
/// Clones the current <see cref="SentryUser"/> instance.
/// </summary>
/// <returns>The cloned user.</returns>
public User Clone()
public SentryUser Clone()
{
var user = new User();
var user = new SentryUser();
CopyTo(user);
return user;
}

internal void CopyTo(User? user)
internal void CopyTo(SentryUser? user)
{
if (user == null)
{
Expand Down Expand Up @@ -169,7 +169,7 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? _)
/// <summary>
/// Parses from JSON.
/// </summary>
public static User FromJson(JsonElement json)
public static SentryUser FromJson(JsonElement json)
{
var id = json.GetPropertyOrNull("id")?.GetString();
var username = json.GetPropertyOrNull("username")?.GetString();
Expand All @@ -178,7 +178,7 @@ public static User FromJson(JsonElement json)
var segment = json.GetPropertyOrNull("segment")?.GetString();
var other = json.GetPropertyOrNull("other")?.GetStringDictionaryOrNull();

return new User
return new SentryUser
{
Id = id,
Username = username,
Expand Down
8 changes: 4 additions & 4 deletions src/Sentry/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ public Contexts Contexts
set => _contexts.ReplaceWith(value);
}

private User? _user;
private SentryUser? _user;

/// <inheritdoc />
public User User
public SentryUser User
{
get => _user ??= new User();
get => _user ??= new SentryUser();
set => _user = value;
}

Expand Down Expand Up @@ -369,7 +369,7 @@ public static Transaction FromJson(JsonElement json)
var distribution = json.GetPropertyOrNull("dist")?.GetString();
var request = json.GetPropertyOrNull("request")?.Pipe(Request.FromJson);
var contexts = json.GetPropertyOrNull("contexts")?.Pipe(Contexts.FromJson) ?? new();
var user = json.GetPropertyOrNull("user")?.Pipe(User.FromJson);
var user = json.GetPropertyOrNull("user")?.Pipe(SentryUser.FromJson);
var environment = json.GetPropertyOrNull("environment")?.GetString();
var sdk = json.GetPropertyOrNull("sdk")?.Pipe(SdkVersion.FromJson) ?? new SdkVersion();
var fingerprint = json.GetPropertyOrNull("fingerprint")?
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry/TransactionTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ public Contexts Contexts
set => _contexts.ReplaceWith(value);
}

private User? _user;
private SentryUser? _user;

/// <inheritdoc />
public User User
public SentryUser User
{
get => _user ??= new User();
get => _user ??= new SentryUser();
set => _user = value;
}

Expand Down
2 changes: 1 addition & 1 deletion test/Sentry.OpenTelemetry.Tests/AspNetCoreEnricherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void Enrich_SendDefaultPii_UserOnScope()
var hub = Substitute.For<IHub>();
hub.ConfigureScope(Arg.Do<Action<Scope>>(action => action(scope)));

var user = new User{ Id = "foo" };
var user = new SentryUser{ Id = "foo" };
var userFactory = Substitute.For<ISentryUserFactory>();
userFactory.Create().Returns(user);

Expand Down
Loading

0 comments on commit f93d62b

Please sign in to comment.