|
| 1 | +using Sentry.Extensibility; |
| 2 | +using Sentry.Internal; |
| 3 | +using Sentry.Internal.Extensions; |
| 4 | + |
| 5 | +namespace Sentry.Protocol; |
| 6 | + |
| 7 | +/// <summary> |
| 8 | +/// Sentry Replay context interface. |
| 9 | +/// </summary> |
| 10 | +/// <example> |
| 11 | +/// { |
| 12 | +/// "contexts": { |
| 13 | +/// "replay": { |
| 14 | +/// "replay_id": "12312012123120121231201212312012" |
| 15 | +/// } |
| 16 | +/// } |
| 17 | +/// } |
| 18 | +/// </example> |
| 19 | +/// <see href="https://develop.sentry.dev/sdk/data-model/event-payloads/contexts/#replay-context"/> |
| 20 | +public sealed class Replay : ISentryJsonSerializable, ICloneable<Replay>, IUpdatable<Replay> |
| 21 | +{ |
| 22 | + /// <summary> |
| 23 | + /// Tells Sentry which type of context this is. |
| 24 | + /// </summary> |
| 25 | + public const string Type = "replay"; |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// The name of the runtime. |
| 29 | + /// </summary> |
| 30 | + public SentryId? ReplayId { get; set; } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Clones this instance. |
| 34 | + /// </summary> |
| 35 | + public Replay Clone() |
| 36 | + { |
| 37 | + var response = new Replay(); |
| 38 | + |
| 39 | + response.UpdateFrom(this); |
| 40 | + |
| 41 | + return response; |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Updates this instance with data from the properties in the <paramref name="source"/>, |
| 46 | + /// unless there is already a value in the existing property. |
| 47 | + /// </summary> |
| 48 | + public void UpdateFrom(Replay source) |
| 49 | + { |
| 50 | + ReplayId ??= source.ReplayId; |
| 51 | + } |
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// Updates this instance with data from the properties in the <paramref name="source"/>, |
| 55 | + /// unless there is already a value in the existing property. |
| 56 | + /// </summary> |
| 57 | + public void UpdateFrom(object source) |
| 58 | + { |
| 59 | + if (source is Replay response) |
| 60 | + { |
| 61 | + UpdateFrom(response); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + /// <inheritdoc /> |
| 66 | + public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger) |
| 67 | + { |
| 68 | + writer.WriteStartObject(); |
| 69 | + |
| 70 | + writer.WriteString("type", Type); |
| 71 | + writer.WriteSerializableIfNotNull("replay_id", ReplayId, logger); |
| 72 | + |
| 73 | + writer.WriteEndObject(); |
| 74 | + } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Parses from JSON. |
| 78 | + /// </summary> |
| 79 | + public static Replay FromJson(JsonElement json) |
| 80 | + { |
| 81 | + var replayId = json.GetPropertyOrNull("replay_id")?.Pipe(SentryId.FromJson); |
| 82 | + |
| 83 | + return new Replay |
| 84 | + { |
| 85 | + ReplayId = replayId |
| 86 | + }; |
| 87 | + } |
| 88 | +} |
0 commit comments