-
Notifications
You must be signed in to change notification settings - Fork 404
[Geneva] Fix ETW metadata to allow .NET EventSource subscriptions #4729
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a65a6c4
Fix ETW metadata to allow .Net EventSource subscriptions
zvorygin 560e630
Fix comments
zvorygin f2cdc0b
Fix comments and build warnings
zvorygin ce4116b
Remove UTF8-BOM
zvorygin 23da510
[Geneva] Fix CHANGELOG entry
martincostello 8cd3566
[Geneva] Update constant
martincostello 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| namespace OpenTelemetry.Exporter.Geneva.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Collection definition for ETW tests. | ||
| /// <para/> | ||
| /// Since ETW is a system-global (not even process-global) resource, these tests shouldn't be run in parallel. | ||
| /// </summary> | ||
| [CollectionDefinition(Name, DisableParallelization = true)] | ||
| #pragma warning disable CA1711 // Identifiers should not have incorrect suffix | ||
| public sealed class EtwCollection | ||
| #pragma warning restore CA1711 // Identifiers should not have incorrect suffix | ||
| { | ||
| public const string Name = "ETW collection"; | ||
| } |
69 changes: 69 additions & 0 deletions
69
test/OpenTelemetry.Exporter.Geneva.Tests/Internal/Transports/EtwDataTransportTests.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,69 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using System.Diagnostics.Tracing; | ||
| using OpenTelemetry.Exporter.Geneva.Transports; | ||
|
|
||
| namespace OpenTelemetry.Exporter.Geneva.Tests.Internal.Transports; | ||
|
|
||
| [Collection(EtwCollection.Name)] | ||
| public class EtwDataTransportTests | ||
| { | ||
| [Fact] | ||
| public void TestEtwMessageRoundtrip() | ||
| { | ||
| var randomProviderName = "x" + Guid.NewGuid().ToString("N"); | ||
| using var listener = new TestEventSourceListener(randomProviderName); | ||
| using var transport = new EtwDataTransport(randomProviderName); | ||
| byte[] payload = [1, 2, 3, 4]; | ||
|
|
||
| transport.Send(payload, payload.Length); | ||
|
|
||
| Assert.Single(listener.Events); | ||
| var theEvent = listener.Events[0]; | ||
| Assert.NotNull(theEvent.Payload); | ||
| Assert.Single(theEvent.Payload); | ||
|
|
||
| var rawPayload = theEvent.Payload[0] as byte[]; | ||
| Assert.NotNull(rawPayload); | ||
| Assert.Equal(payload, rawPayload); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test event source listener. | ||
| /// </summary> | ||
| private sealed class TestEventSourceListener : EventListener | ||
| { | ||
| /// <summary> | ||
| /// Event source name to automatically attach to. | ||
| /// </summary> | ||
| private readonly string eventSourceName; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="TestEventSourceListener"/> class. | ||
| /// </summary> | ||
| /// <param name="eventSourceName">The name of the event source to attach to.</param> | ||
| public TestEventSourceListener(string eventSourceName) | ||
| { | ||
| this.eventSourceName = eventSourceName; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets events emitted by ETW. | ||
| /// </summary> | ||
| public List<EventWrittenEventArgs> Events { get; } = new(); | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override void OnEventSourceCreated(EventSource eventSource) | ||
| { | ||
| base.OnEventSourceCreated(eventSource); | ||
| if (string.Equals(eventSource.Name, this.eventSourceName, StringComparison.Ordinal)) | ||
| { | ||
| this.EnableEvents(eventSource, EventLevel.LogAlways); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| protected override void OnEventWritten(EventWrittenEventArgs eventData) => this.Events.Add(eventData); | ||
| } | ||
| } |
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.