-
-
Notifications
You must be signed in to change notification settings - Fork 229
feat: Send transactions as Span v2 streams #4912
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
Draft
jamescrosswell
wants to merge
9
commits into
main
Choose a base branch
from
span-first-envelopes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a491075
Added protocol classes
jamescrosswell fc0cebc
Unit tests
jamescrosswell 6a023d0
Format code
getsentry-bot 3baa855
Added TraceLifeCycle to SentryOptions
jamescrosswell 1ed499e
Use traceLifeCycle in SentryClient
jamescrosswell c36fb39
Added logic to convert from static spans
jamescrosswell 0f09f57
Format code
getsentry-bot aa8266d
Fixed tests
jamescrosswell 28f0b75
Format code
getsentry-bot 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
Submodule sentry-native
updated
30 files
| +26 −14 | .github/workflows/ci.yml | |
| +2 −2 | .gitignore | |
| +11 −0 | CHANGELOG.md | |
| +6 −0 | examples/example.c | |
| +49 −1 | include/sentry.h | |
| +1 −1 | ndk/gradle.properties | |
| +0 −54 | scripts/start-android.sh | |
| +222 −8 | src/backends/sentry_backend_crashpad.cpp | |
| +8 −0 | src/path/sentry_path_unix.c | |
| +12 −0 | src/path/sentry_path_windows.c | |
| +4 −1 | src/sentry_core.c | |
| +147 −0 | src/sentry_database.c | |
| +6 −0 | src/sentry_database.h | |
| +3 −3 | src/sentry_envelope.c | |
| +6 −0 | src/sentry_envelope.h | |
| +34 −0 | src/sentry_options.c | |
| +5 −0 | src/sentry_options.h | |
| +7 −0 | src/sentry_path.h | |
| +1 −1 | tests/__init__.py | |
| +181 −0 | tests/test_integration_cache.py | |
| +185 −0 | tests/test_integration_crashpad.py | |
| +13 −1,617 | tests/test_integration_http.py | |
| +443 −0 | tests/test_integration_logs.py | |
| +423 −0 | tests/test_integration_metrics.py | |
| +239 −0 | tests/test_integration_proxy.py | |
| +468 −0 | tests/test_integration_transactions.py | |
| +1 −0 | tests/unit/CMakeLists.txt | |
| +292 −0 | tests/unit/test_cache.c | |
| +59 −0 | tests/unit/test_path.c | |
| +6 −0 | tests/unit/tests.inc |
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
20 changes: 20 additions & 0 deletions
20
src/Sentry/Internal/Extensions/SentryTransactionExtensions.cs
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,20 @@ | ||
| using Sentry.Protocol.Spans; | ||
|
|
||
| namespace Sentry.Internal.Extensions; | ||
|
|
||
| internal static class SentryTransactionExtensions | ||
| { | ||
| /// <summary> | ||
| /// Allows us to convert a Transaction and its chiled spans to the new SpanV2 format during the transition period. | ||
| /// This is temporary - we can remove it once transactions have been deprecated. | ||
| /// </summary> | ||
| public static IEnumerable<SpanV2> ToSpanV2Spans(this SentryTransaction transaction) | ||
| { | ||
| // Collect spans: transaction span + child spans. | ||
| yield return new SpanV2(transaction); | ||
| foreach (var span in transaction.Spans) | ||
| { | ||
| yield return new SpanV2(span); | ||
| } | ||
| } | ||
| } |
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,176 @@ | ||
| using Sentry.Extensibility; | ||
|
|
||
| namespace Sentry.Protocol; | ||
|
|
||
| internal class SentryAttributes : Dictionary<string, SentryAttribute>, ISentryJsonSerializable | ||
| { | ||
| public SentryAttributes() : base(StringComparer.Ordinal) | ||
| { | ||
| } | ||
|
|
||
| public SentryAttributes(int capacity) : base(capacity, StringComparer.Ordinal) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the attribute value associated with the specified key. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Returns <see langword="true"/> if this <see cref="SentryMetric"/> contains an attribute with the specified key which is of type <typeparamref name="TAttribute"/> and it's value is not <see langword="null"/>. | ||
| /// Otherwise <see langword="false"/>. | ||
| /// Supported types: | ||
| /// <list type="table"> | ||
| /// <listheader> | ||
| /// <term>Type</term> | ||
| /// <description>Range</description> | ||
| /// </listheader> | ||
| /// <item> | ||
| /// <term>string</term> | ||
| /// <description><see langword="string"/> and <see langword="char"/></description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <term>boolean</term> | ||
| /// <description><see langword="false"/> and <see langword="true"/></description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <term>integer</term> | ||
| /// <description>64-bit signed integral numeric types</description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <term>double</term> | ||
| /// <description>64-bit floating-point numeric types</description> | ||
| /// </item> | ||
| /// </list> | ||
| /// Unsupported types: | ||
| /// <list type="table"> | ||
| /// <listheader> | ||
| /// <term>Type</term> | ||
| /// <description>Result</description> | ||
| /// </listheader> | ||
| /// <item> | ||
| /// <term><see langword="object"/></term> | ||
| /// <description><c>ToString</c> as <c>"type": "string"</c></description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <term>Collections</term> | ||
| /// <description><c>ToString</c> as <c>"type": "string"</c></description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <term><see langword="null"/></term> | ||
| /// <description>ignored</description> | ||
| /// </item> | ||
| /// </list> | ||
| /// </remarks> | ||
| /// <seealso href="https://develop.sentry.dev/sdk/telemetry/metrics/"/> | ||
| public bool TryGetAttribute<TAttribute>(string key, [MaybeNullWhen(false)] out TAttribute value) | ||
| { | ||
| if (TryGetValue(key, out var attribute) && attribute.Value is TAttribute attributeValue) | ||
| { | ||
| value = attributeValue; | ||
| return true; | ||
| } | ||
|
|
||
| value = default; | ||
| return false; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Set a key-value pair of data attached to the metric. | ||
| /// </summary> | ||
| public void SetAttribute<TAttribute>(string key, TAttribute value) where TAttribute : notnull | ||
| { | ||
| if (value is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| this[key] = new SentryAttribute(value); | ||
| } | ||
|
|
||
| internal void SetAttribute(string key, string value) | ||
| { | ||
| this[key] = new SentryAttribute(value, "string"); | ||
| } | ||
|
|
||
| internal void SetAttribute(string key, char value) | ||
| { | ||
| this[key] = new SentryAttribute(value.ToString(), "string"); | ||
| } | ||
|
|
||
| internal void SetAttribute(string key, int value) | ||
| { | ||
| this[key] = new SentryAttribute(value, "integer"); | ||
| } | ||
|
|
||
| internal void SetDefaultAttributes(SentryOptions options, SdkVersion sdk) | ||
| { | ||
| var environment = options.SettingLocator.GetEnvironment(); | ||
| SetAttribute("sentry.environment", environment); | ||
|
|
||
| var release = options.SettingLocator.GetRelease(); | ||
| if (release is not null) | ||
| { | ||
| SetAttribute("sentry.release", release); | ||
| } | ||
|
|
||
| if (sdk.Name is { } name) | ||
| { | ||
| SetAttribute("sentry.sdk.name", name); | ||
| } | ||
| if (sdk.Version is { } version) | ||
| { | ||
| SetAttribute("sentry.sdk.version", version); | ||
| } | ||
| } | ||
|
|
||
| internal void SetAttributes(IEnumerable<KeyValuePair<string, object>>? attributes) | ||
| { | ||
| if (attributes is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER | ||
| if (attributes.TryGetNonEnumeratedCount(out var count)) | ||
| { | ||
| _ = EnsureCapacity(Count + count); | ||
| } | ||
| #endif | ||
|
|
||
| foreach (var attribute in attributes) | ||
| { | ||
| this[attribute.Key] = new SentryAttribute(attribute.Value); | ||
| } | ||
| } | ||
|
|
||
| internal void SetAttributes(ReadOnlySpan<KeyValuePair<string, object>> attributes) | ||
| { | ||
| if (attributes.IsEmpty) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER | ||
| _ = EnsureCapacity(Count + attributes.Length); | ||
| #endif | ||
|
|
||
| foreach (var attribute in attributes) | ||
| { | ||
| this[attribute.Key] = new SentryAttribute(attribute.Value); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc cref="ISentryJsonSerializable.WriteTo(Utf8JsonWriter, IDiagnosticLogger)" /> | ||
| public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger) | ||
| { | ||
| writer.WritePropertyName("attributes"); | ||
| writer.WriteStartObject(); | ||
|
|
||
| foreach (var attribute in this) | ||
| { | ||
| SentryAttributeSerializer.WriteAttribute(writer, attribute.Key, attribute.Value, logger); | ||
| } | ||
|
|
||
| writer.WriteEndObject(); | ||
| } | ||
| } |
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,31 @@ | ||
| using Sentry.Extensibility; | ||
| using Sentry.Internal.Extensions; | ||
|
|
||
| namespace Sentry.Protocol.Spans; | ||
|
|
||
| /// <summary> | ||
| /// Links connect spans to other spans or traces, enabling distributed tracing | ||
| /// </summary> | ||
| internal readonly struct SentryLink(SentryId traceId, SpanId spanId, bool sampled) : ISentryJsonSerializable | ||
| { | ||
| private readonly SentryAttributes _attributes = new(); | ||
|
|
||
| public SpanId SpanId { get; } = spanId; | ||
| public SentryId TraceId { get; } = traceId; | ||
| public bool Sampled { get; } = sampled; | ||
| public IReadOnlyDictionary<string, SentryAttribute> Attributes => _attributes; | ||
|
|
||
| /// <inheritdoc cref="ISentryJsonSerializable.WriteTo(Utf8JsonWriter, IDiagnosticLogger)" /> | ||
| public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger) | ||
| { | ||
| writer.WriteStartObject(); | ||
|
|
||
| writer.WriteSerializableIfNotNull("span_id", SpanId.NullIfDefault(), logger); | ||
| writer.WriteSerializableIfNotNull("trace_id", TraceId.NullIfDefault(), logger); | ||
| writer.WriteBoolean("sampled", Sampled); | ||
|
|
||
| _attributes.WriteTo(writer, logger); | ||
|
|
||
| writer.WriteEndObject(); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Flash0ver just a heads up, I needed Attributes for the span streaming stuff so extracted this functionality out from the
SentryMetricsclass... just in case you might change any of this in another PR.