-
-
Notifications
You must be signed in to change notification settings - Fork 225
Add Hint support #2351
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
Merged
Merged
Add Hint support #2351
Changes from 14 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
556ba4c
Added SentryOptions.SetBeforeSend
jamescrosswell a713108
Added tests for new CaptureHint overloads taking a Hint parameter
jamescrosswell 36699e8
Failed requests add a Hint for the HttpResponseMessage
jamescrosswell baed55b
Added BeforeBreadcrumb Hint support (for breadcrumbs on the scope only)
jamescrosswell 836ac09
- Fixed ScopeExtensionTests
jamescrosswell 7b4efa1
Added stub of Android platform code to enable builds to complete
jamescrosswell 52e5a33
Sentry.Samples.Console.Customized now demonstrates using hints with b…
jamescrosswell baee2ca
Added missing XML docs on Hint constructors
jamescrosswell d3dae05
Updated MiddlewareLoggerIntegration tests to account for modified imp…
jamescrosswell fb6e9cf
Updated verified tests for CaptureTransaction_BeforeSendTransactionTh…
jamescrosswell d211548
Tail chasing Verify test errors
jamescrosswell 6c9be76
Merge branch 'main' into feat/hint-before-send
mattjohnsonpint c1c2777
Update CHANGELOG.md
mattjohnsonpint eded3b6
Fix iOS compilation issue
mattjohnsonpint 6d78761
Moved hint data from base Hint class to Items property, for clarity
jamescrosswell 9142abf
Added XML docs for Hint.Items property
jamescrosswell 8868e47
Updated Customized console sample to use new Hint
jamescrosswell 0f701eb
- Added Hints to BeforeSendTransaction
jamescrosswell 25b61f4
Attachments from the Scope get included in Hints before adding Bookma…
jamescrosswell aa6d91e
Added hint support for Transaction/Event processors
jamescrosswell aa3750f
Merge remote-tracking branch 'getsentry/main' into feat/hint-before-send
jamescrosswell 860af91
- Renamed Contextual processors to ProcessorWithHint (more specific)
jamescrosswell f27a650
Merge remote-tracking branch 'origin/main' into feat/hint-before-send
jamescrosswell afb18bd
Merge branch 'main' into feat/hint-before-send
mattjohnsonpint d02f33a
Add overloads without hints
mattjohnsonpint e382114
Cleanup Hint. Just expose Attachments, not AddAttachments.
mattjohnsonpint c3fdad4
Update API snapshots
mattjohnsonpint 13c70d6
Ensure hint modifications to attachments are sent
mattjohnsonpint af95623
Update CHANGELOG.md
mattjohnsonpint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Net.Mail; | ||
| using Sentry.Internal.Extensions; | ||
|
|
||
| namespace Sentry; | ||
|
|
||
| /// <summary> | ||
| /// A hint that can be provided when capturing a <see cref="SentryEvent"/> or adding a <see cref="Breadcrumb"/>. | ||
| /// Hints can be used to filter or modify events or breadcrumbs before they are sent to Sentry. | ||
| /// </summary> | ||
| public class Hint : ICollection, IEnumerable<KeyValuePair<string, object?>> | ||
| { | ||
| private readonly Dictionary<string, object?> _internalStorage = new(); | ||
| private readonly List<Attachment> _attachments = new(); | ||
jamescrosswell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// <summary> | ||
| /// Creates a new instance of <see cref="Hint"/>. | ||
| /// </summary> | ||
| public Hint() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new hint with a single key/value pair. | ||
| /// </summary> | ||
| /// <param name="key"></param> | ||
| /// <param name="value"></param> | ||
| public Hint(string key, object? value) | ||
| : this() | ||
| { | ||
| _internalStorage[key] = value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets additional values to be provided with the hint | ||
| /// </summary> | ||
| /// <param name="key">The key</param> | ||
| /// <returns>The value with the specified key or null if none exist.</returns> | ||
| public object? this[string key] | ||
| { | ||
| get => _internalStorage.GetValueOrDefault(key); | ||
| set => _internalStorage[key] = value; | ||
| } | ||
|
|
||
| internal void AddAttachmentsInternal(IEnumerable<Attachment> attachments) | ||
| { | ||
| if (attachments is not null) | ||
| { | ||
| _attachments.AddRange(attachments); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds one or more attachments to the Hint. | ||
| /// </summary> | ||
| /// <param name="attachments"></param> | ||
| public void AddAttachments(params Attachment[] attachments) => AddAttachmentsInternal(attachments); | ||
|
|
||
| /// <summary> | ||
| /// Adds multiple attachments to the Hint. | ||
| /// </summary> | ||
| /// <param name="attachments"></param> | ||
| public void AddAttachments(IEnumerable<Attachment> attachments) => AddAttachmentsInternal(attachments); | ||
|
|
||
| /// <summary> | ||
| /// Attachments added to the Hint. | ||
| /// </summary> | ||
| public ICollection<Attachment> Attachments => _attachments; | ||
|
|
||
| /// <summary> | ||
| /// Clears any values stored in <see cref="this[string]"/> | ||
| /// </summary> | ||
| public void Clear() => _internalStorage.Clear(); | ||
|
|
||
| /// <summary> | ||
| /// Checks if the specified key exists | ||
| /// </summary> | ||
| /// <param name="key">The key</param> | ||
| /// <returns>True if the key exists. False otherwise.</returns> | ||
| public bool ContainsKey(string key) => _internalStorage.ContainsKey(key); | ||
|
|
||
| /// <inheritdoc /> | ||
| public void CopyTo(Array array, int index) => ((ICollection)_internalStorage).CopyTo(array, index); | ||
|
|
||
| /// <inheritdoc /> | ||
| public int Count => _internalStorage.Count; | ||
|
|
||
| IEnumerator IEnumerable.GetEnumerator() => _internalStorage.GetEnumerator(); | ||
|
|
||
| /// <inheritdoc /> | ||
| public IEnumerator<KeyValuePair<string, object?>> GetEnumerator() | ||
| => ((IEnumerable<KeyValuePair<string, object?>>)_internalStorage).GetEnumerator(); | ||
|
|
||
| /// <summary> | ||
| /// Gets the value with the specified key as type <typeparamref name="T"/> | ||
| /// </summary> | ||
| /// <typeparam name="T">They expected value type</typeparam> | ||
| /// <param name="key">The key</param> | ||
| /// <returns>A value of type <typeparamref name="T"/> if one exists with the specified key or null otherwise.</returns> | ||
| public T? GetValue<T>(string key) where T : class? => (this[key] is T typedHintValue) ? typedHintValue : null; | ||
|
|
||
| /// <inheritdoc /> | ||
| public bool IsSynchronized => ((ICollection)_internalStorage).IsSynchronized; | ||
|
|
||
| /// <summary> | ||
| /// Remves the value with the specified key | ||
| /// </summary> | ||
| /// <param name="key"></param> | ||
| public void Remove(string key) => _internalStorage.Remove(key); | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a Screenshot for the Hint | ||
| /// </summary> | ||
| public Attachment? Screenshot { get; set; } | ||
|
|
||
| /// <inheritdoc /> | ||
| public object SyncRoot => ((ICollection)_internalStorage).SyncRoot; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a ViewHierarchy for the Hint | ||
| /// </summary> | ||
| public Attachment? ViewHierarchy { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new Hint with one or more attachments. | ||
| /// </summary> | ||
| /// <param name="attachment"></param> | ||
| /// <returns></returns> | ||
| public static Hint WithAttachments(params Attachment[] attachment) => Hint.WithAttachments(attachment.ToList()); | ||
|
|
||
| /// <summary> | ||
| /// Creates a new Hint with attachments. | ||
| /// </summary> | ||
| /// <param name="attachments"></param> | ||
| /// <returns></returns> | ||
| public static Hint WithAttachments(ICollection<Attachment> attachments) | ||
| { | ||
| var hint = new Hint(); | ||
| hint.AddAttachments(attachments); | ||
| return hint; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| namespace Sentry; | ||
|
|
||
| /// <summary> | ||
| /// Constants used to name Hints generated by the Sentry SDK | ||
| /// </summary> | ||
| public static class HintTypes | ||
| { | ||
| /// <summary> | ||
| /// Used for HttpResponseMessage hints | ||
| /// </summary> | ||
| public const string HttpResponseMessage = "http-response-message"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.