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

Marked SentryUser.Segment as deprecated #3437

Merged
merged 6 commits into from
Jun 20, 2024
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Obsoletion

- Marked SentryUser.Segment as deprecated ([#3437](https://github.com/getsentry/sentry-dotnet/pull/3437))

### Features

- Added a new package `Sentry.AspNetCore.Blazor.WebAssembly`. This packages provides you with an extension to `WebAssemblyHostBuilder` to allow SDK configuration via the builder pattern. This package gives us an entry point and the ability to extend the SDKs support and out-of-the-box offering. You can follow the progress and leave feedback either ([here](https://github.com/getsentry/sentry-dotnet/issues/2329)) for extending the support for Blazor Server or ([here](https://github.com/getsentry/sentry-dotnet/issues/2021)) for Blazor WebAssembly support ([#3386](https://github.com/getsentry/sentry-dotnet/pull/3386))
Expand Down
2 changes: 2 additions & 0 deletions src/Sentry.NLog/SentryTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ private void InnerWrite(LogEventInfo logEvent)
Username = User.Username?.Render(logEvent),
Email = User.Email?.Render(logEvent),
IpAddress = User.IpAddress?.Render(logEvent),
#pragma warning disable CS0618 // Type or member is obsolete
Segment = User.Segment?.Render(logEvent)
#pragma warning restore CS0618 // Type or member is obsolete
};

if (User.Other?.Count > 0)
Expand Down
2 changes: 2 additions & 0 deletions src/Sentry/DynamicSamplingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public static DynamicSamplingContext CreateFromTransaction(TransactionTracer tra
var traceId = transaction.TraceId;
var sampled = transaction.IsSampled;
var sampleRate = transaction.SampleRate!.Value;
#pragma warning disable CS0618 // Type or member is obsolete
var userSegment = transaction.User.Segment;
#pragma warning restore CS0618 // Type or member is obsolete
var transactionName = transaction.NameSource.IsHighQuality() ? transaction.Name : null;

// These two may not have been set yet on the transaction, but we can get them directly.
Expand Down
4 changes: 4 additions & 0 deletions src/Sentry/Platforms/Android/Extensions/UserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public static SentryUser ToUser(this JavaSdk.Protocol.User user) =>
Id = user.Id,
IpAddress = user.IpAddress,
Username = user.Username,
#pragma warning disable CS0618 // Type or member is obsolete
Segment = user.Segment,
#pragma warning restore CS0618 // Type or member is obsolete
Other = user.Data ?? EmptyDictionary
};

Expand All @@ -23,7 +25,9 @@ public static JavaSdk.Protocol.User ToJavaUser(this SentryUser user) =>
Id = user.Id,
IpAddress = user.IpAddress,
Username = user.Username,
#pragma warning disable CS0618 // Type or member is obsolete
Segment = user.Segment,
#pragma warning restore CS0618 // Type or member is obsolete
Data = user.Other.Count == 0 ? null : user.Other
};
}
4 changes: 4 additions & 0 deletions src/Sentry/Platforms/Cocoa/Extensions/UserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public static SentryUser ToUser(this CocoaSdk.SentryUser user, IDiagnosticLogger
Id = user.UserId,
IpAddress = user.IpAddress,
Username = user.Username,
#pragma warning disable CS0618 // Type or member is obsolete
Segment = user.Segment,
#pragma warning restore CS0618 // Type or member is obsolete
Other = user.Data.ToStringDictionary(logger)
};

Expand All @@ -23,7 +25,9 @@ public static CocoaSdk.SentryUser ToCocoaUser(this SentryUser user)
UserId = user.Id,
IpAddress = user.IpAddress,
Username = user.Username,
#pragma warning disable CS0618 // Type or member is obsolete
Segment = user.Segment,
#pragma warning restore CS0618 // Type or member is obsolete
Data = user.Other.ToNullableNSDictionary()
};

Expand Down
9 changes: 9 additions & 0 deletions src/Sentry/SentryUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public string? IpAddress
/// <summary>
/// The segment the user belongs to.
/// </summary>
[Obsolete("This property is deprecated and will be removed in a future version.")]
public string? Segment
{
get => _segment;
Expand Down Expand Up @@ -136,7 +137,9 @@ internal void CopyTo(SentryUser? user)
user.Username ??= Username;
user.Email ??= Email;
user.IpAddress ??= IpAddress;
#pragma warning disable CS0618 // Type or member is obsolete
user.Segment ??= Segment;
#pragma warning restore CS0618 // Type or member is obsolete

user._other ??= _other?.ToDictionary(
entry => entry.Key,
Expand All @@ -148,7 +151,9 @@ Id is not null ||
Username is not null ||
Email is not null ||
IpAddress is not null ||
#pragma warning disable CS0618 // Type or member is obsolete
Segment is not null ||
#pragma warning restore CS0618 // Type or member is obsolete
_other?.Count > 0;

/// <inheritdoc />
Expand All @@ -160,7 +165,9 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? _)
writer.WriteStringIfNotWhiteSpace("username", Username);
writer.WriteStringIfNotWhiteSpace("email", Email);
writer.WriteStringIfNotWhiteSpace("ip_address", IpAddress);
#pragma warning disable CS0618 // Type or member is obsolete
writer.WriteStringIfNotWhiteSpace("segment", Segment);
#pragma warning restore CS0618 // Type or member is obsolete
writer.WriteStringDictionaryIfNotEmpty("other", _other!);

writer.WriteEndObject();
Expand All @@ -184,7 +191,9 @@ public static SentryUser FromJson(JsonElement json)
Username = username,
Email = email,
IpAddress = ip,
#pragma warning disable CS0618 // Type or member is obsolete
Segment = segment,
#pragma warning restore CS0618 // Type or member is obsolete
_other = other?.WhereNotNullValue().ToDict()
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
Username: ,
Email: ,
IpAddress: ,
Segment: ,
Other: {
mood: joyous
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
Username: ,
Email: ,
IpAddress: ,
Segment: ,
Other: {
mood: joyous
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
Username: ,
Email: ,
IpAddress: ,
Segment: ,
Other: {
mood: joyous
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
Username: ,
Email: ,
IpAddress: ,
Segment: ,
Other: {
mood: joyous
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
Username: ,
Email: ,
IpAddress: ,
Segment: ,
Other: {
mood: joyous
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ namespace Sentry
public string? Id { get; set; }
public string? IpAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> Other { get; set; }
[System.Obsolete("This property is deprecated and will be removed in a future version.")]
public string? Segment { get; set; }
public string? Username { get; set; }
public Sentry.SentryUser Clone() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ namespace Sentry
public string? Id { get; set; }
public string? IpAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> Other { get; set; }
[System.Obsolete("This property is deprecated and will be removed in a future version.")]
public string? Segment { get; set; }
public string? Username { get; set; }
public Sentry.SentryUser Clone() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ namespace Sentry
public string? Id { get; set; }
public string? IpAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> Other { get; set; }
[System.Obsolete("This property is deprecated and will be removed in a future version.")]
public string? Segment { get; set; }
public string? Username { get; set; }
public Sentry.SentryUser Clone() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ namespace Sentry
public string? Id { get; set; }
public string? IpAddress { get; set; }
public System.Collections.Generic.IDictionary<string, string> Other { get; set; }
[System.Obsolete("This property is deprecated and will be removed in a future version.")]
public string? Segment { get; set; }
public string? Username { get; set; }
public Sentry.SentryUser Clone() { }
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Tests/DynamicSamplingContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ public void CreateFromTransaction(bool? isSampled)
SampleRate = 0.5,
User =
{
#pragma warning disable CS0618 // Type or member is obsolete
Segment = "Group A"
#pragma warning restore CS0618 // Type or member is obsolete
},
};

Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Tests/Protocol/ScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public void HasUser_UserWithIpAddress_ReturnsTrue()
public void HasUser_UserWithSegment_ReturnsTrue()
{
var sut = _fixture.GetSut();
#pragma warning disable CS0618 // Type or member is obsolete
sut.User.Segment = "test";
#pragma warning restore CS0618 // Type or member is obsolete
Assert.True(sut.HasUser());
}

Expand Down
8 changes: 8 additions & 0 deletions test/Sentry.Tests/Protocol/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
Username = "user-name",
Email = "test@sentry.io",
IpAddress = "::1",
#pragma warning disable CS0618 // Type or member is obsolete
Segment = "A1",
#pragma warning restore CS0618 // Type or member is obsolete
Other = new Dictionary<string, string> { { "testCustomValueKey", "testCustomValue" } }
};

Expand Down Expand Up @@ -48,7 +50,9 @@ public void Clone_CopyValues()
Email = "emal@sentry.io",
IpAddress = "::1",
Username = "user",
#pragma warning disable CS0618 // Type or member is obsolete
Segment = "segment",
#pragma warning restore CS0618 // Type or member is obsolete
Other = new Dictionary<string, string>
{
{"testCustomValueKey", "testCustomValue"}
Expand All @@ -61,7 +65,9 @@ public void Clone_CopyValues()
Assert.Equal(sut.Username, clone.Username);
Assert.Equal(sut.Email, clone.Email);
Assert.Equal(sut.IpAddress, clone.IpAddress);
#pragma warning disable CS0618 // Type or member is obsolete
Assert.Equal(sut.Segment, clone.Segment);
#pragma warning restore CS0618 // Type or member is obsolete
Assert.Equal(sut.Other, clone.Other);
}

Expand All @@ -80,7 +86,9 @@ public static IEnumerable<object[]> TestCases()
yield return new object[] { (new SentryUser { Username = "some username" }, """{"username":"some username"}""") };
yield return new object[] { (new SentryUser { Email = "some email" }, """{"email":"some email"}""") };
yield return new object[] { (new SentryUser { IpAddress = "some ipAddress" }, """{"ip_address":"some ipAddress"}""") };
#pragma warning disable CS0618 // Type or member is obsolete
yield return new object[] { (new SentryUser { Segment = "some segment" }, """{"segment":"some segment"}""") };
#pragma warning restore CS0618 // Type or member is obsolete

var other = new Dictionary<string, string> { { "testCustomValueKey", "testCustomValue" } };
yield return new object[] { (new SentryUser { Other = other }, """{"other":{"testCustomValueKey":"testCustomValue"}}""") };
Expand Down
Loading