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

[DEVEX-155] Account for nullable events #324

Merged
merged 5 commits into from
Nov 1, 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
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Generate certificates
run: |
mkdir -p certs
Expand All @@ -89,7 +89,7 @@ jobs:
sudo chown -R $USER:$USER certs
sudo chmod -R 755 certs
- name: Upload certificates
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: certs
path: certs
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
run: |
dotnet build --configuration ${{ matrix.configuration }} --framework ${{ matrix.framework }} src/EventStore.Client
- name: Download certificates
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: certs
path: certs
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:
/p:RepositoryUrl=https://github.com/EventStore/EventStore-Client-Dotnet \
/p:RepositoryType=git
- name: Publish Artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
path: packages
name: nuget-packages
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract

using System.Diagnostics;
using EventStore.Diagnostics;
using EventStore.Diagnostics.Telemetry;
Expand Down Expand Up @@ -32,7 +34,7 @@ public static void TraceSubscriptionEvent(
EventStoreClientSettings settings,
UserCredentials? userCredentials
) {
if (source.HasNoActiveListeners())
if (source.HasNoActiveListeners() || resolvedEvent.Event is null)
return;

var parentContext = resolvedEvent.Event.Metadata.ExtractPropagationContext();
Expand Down
2 changes: 1 addition & 1 deletion src/EventStore.Client/EventStore.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
<PackageReference Include="System.Linq.Async" Version="6.0.1"/>
<PackageReference Include="System.Text.Json" Version="8.0.4"/>
<PackageReference Include="System.Text.Json" Version="8.0.5"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ReSharper disable ConditionalAccessQualifierIsNonNullableAccordingToAPIContract

using EventStore.Client.Diagnostics;
using EventStore.Diagnostics.Tracing;

Expand Down Expand Up @@ -171,4 +173,49 @@ async Task Subscribe(IAsyncEnumerator<StreamMessage> internalEnumerator) {
}
}
}

[Fact]
[Trait("Category", "Special cases")]
public async Task should_not_trace_when_event_is_null() {
var category = Guid.NewGuid().ToString("N");
var streamName = category + "-123";

var seedEvents = Fixture.CreateTestEvents(type: $"{category}-{Fixture.GetStreamName()}").ToArray();
await Fixture.Streams.AppendToStreamAsync(streamName, StreamState.NoStream, seedEvents);

await Fixture.Streams.DeleteAsync(streamName, StreamState.StreamExists);

await using var subscription = Fixture.Streams.SubscribeToStream("$ce-" + category, FromStream.Start, resolveLinkTos: true);

await using var enumerator = subscription.Messages.GetAsyncEnumerator();

Assert.True(await enumerator.MoveNextAsync());

Assert.IsType<StreamMessage.SubscriptionConfirmation>(enumerator.Current);

await Subscribe().WithTimeout();

var appendActivities = Fixture
.GetActivitiesForOperation(TracingConstants.Operations.Append, streamName)
.ShouldNotBeNull();

var subscribeActivities = Fixture
.GetActivitiesForOperation(TracingConstants.Operations.Subscribe, "$ce-" + category)
.ToArray();

appendActivities.ShouldHaveSingleItem();
subscribeActivities.ShouldBeEmpty();

return;

async Task Subscribe() {
while (await enumerator.MoveNextAsync()) {
if (enumerator.Current is not StreamMessage.Event(var resolvedEvent))
continue;

if (resolvedEvent.Event?.EventType is "$metadata")
return;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace EventStore.Client.Tests;
public class DiagnosticsFixture : EventStoreFixture {
readonly ConcurrentDictionary<(string Operation, string Stream), List<Activity>> _activities = [];

public DiagnosticsFixture() {
public DiagnosticsFixture() : base(x => x.RunProjections()) {
var diagnosticActivityListener = new ActivityListener {
ShouldListenTo = source => source.Name == EventStoreClientDiagnostics.InstrumentationName,
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllDataAndRecorded,
Expand Down
Loading