-
Notifications
You must be signed in to change notification settings - Fork 292
[MTP] Add initial support for OTel #6511
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
29 commits
Select commit
Hold shift + click to select a range
0e8493c
[MTP] Add initial support for OTel
Evangelink 0adb084
Apply suggestion from @Evangelink
Evangelink 73b1d5b
Apply suggestion from @Evangelink
Evangelink d0f172c
Apply suggestion from @Evangelink
Evangelink 509f306
Apply suggestion from @Evangelink
Evangelink 1ba53c7
Apply suggestion from @Evangelink
Evangelink 856f380
Apply suggestion from @Evangelink
Evangelink 2a8b2a0
Merge branch 'rel/4.0' into dev/amauryleve/otel-mtp
Evangelink 1495423
Fixes
Evangelink ed4fc44
Add more sub-activities
Evangelink eaead9b
Merge branch 'main' into dev/amauryleve/otel-mtp
Evangelink e47bac4
Merge branch 'main' into dev/amauryleve/otel-mtp
Evangelink 573a081
Fix public APIs
Evangelink 32f2fa0
Apply suggestion from @Evangelink
Evangelink d216378
Apply suggestion from @Evangelink
Evangelink c47dc25
Update Directory.Packages.props
Evangelink 4d2a70f
Update samples/Playground/Playground.csproj
Evangelink 059b84b
Updates
Evangelink b41d8f6
Merge branch 'main' into dev/amauryleve/otel-mtp
Evangelink 476777b
More fixes
Evangelink 195c2d7
More feedback
Evangelink 9d066f6
Fix polyfill issues
Evangelink 5daf9c1
Merge branch 'main' into dev/amauryleve/otel-mtp
Evangelink 33f307e
Add MTP otel sample
Evangelink 0c1a745
Fix playground build
Evangelink d0abceb
Apply suggestion from @Evangelink
Evangelink 625eff9
Merge branch 'main' into dev/amauryleve/otel-mtp
Evangelink fe2778a
Fix conflicts + update versions
Evangelink 2f6998a
Fix obsolete warning
Evangelink 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 |
|---|---|---|
|
|
@@ -15,5 +15,7 @@ public class TestClass | |
| [TestMethod] | ||
| public void Test1() | ||
| { | ||
| Thread.Sleep(5000); | ||
| Assert.IsPositive(1); | ||
| } | ||
| } | ||
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 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <GenerateProgramFile>false</GenerateProgramFile> | ||
| <NoWarn>$(NoWarn);NETSDK1023;SA0001;EnableGenerateDocumentationFile</NoWarn> | ||
|
|
||
| <IsTestingPlatformApplication>true</IsTestingPlatformApplication> | ||
| <GenerateDocumentationFile>false</GenerateDocumentationFile> | ||
| <RepoRoot>$(MSBuildThisFileDirectory)..\..\..\</RepoRoot> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform\Microsoft.Testing.Platform.csproj" /> | ||
| <ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.OpenTelemetry\Microsoft.Testing.Extensions.OpenTelemetry.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="OpenTelemetry.Exporter.Console" VersionOverride="1.13.1" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectCapability Include="TestingPlatformServer" /> | ||
| <ProjectCapability Include="TestContainer" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Import the capabilities for the Microsoft.Testing.Platform --> | ||
| <Import Project="$(RepoRoot)src\Platform\Microsoft.Testing.Platform\buildMultiTargeting\Microsoft.Testing.Platform.props" /> | ||
| </Project> |
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,47 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Testing.Extensions; | ||
| using Microsoft.Testing.Platform.Builder; | ||
| using Microsoft.Testing.Platform.Extensions.Messages; | ||
| using Microsoft.Testing.Platform.Extensions.TestFramework; | ||
| using Microsoft.Testing.Platform.Messages; | ||
| using Microsoft.Testing.Platform.Capabilities.TestFramework; | ||
| using Microsoft.Testing.Platform.Services; | ||
| using Microsoft.Testing.Platform.TestHost; | ||
|
|
||
| using OpenTelemetry.Metrics; | ||
| using OpenTelemetry.Trace; | ||
|
|
||
| namespace MTPOTel; | ||
|
|
||
| public class Program | ||
| { | ||
| public static async Task<int> Main(string[] args) | ||
| { | ||
| ITestApplicationBuilder testApplicationBuilder = await TestApplication.CreateBuilderAsync(args); | ||
|
|
||
| // Register our simple test framework | ||
| testApplicationBuilder.RegisterTestFramework( | ||
| _ => new TestFrameworkCapabilities(), | ||
| (capabilities, serviceProvider) => new SimpleTestFramework(serviceProvider)); | ||
|
|
||
| // Enable OpenTelemetry with console exporter | ||
| testApplicationBuilder.AddOpenTelemetryProvider( | ||
| tracing => | ||
| { | ||
| tracing.AddTestingPlatformInstrumentation(); | ||
| tracing.AddConsoleExporter(); | ||
| }, | ||
| metrics => | ||
| { | ||
| metrics.AddTestingPlatformInstrumentation(); | ||
| metrics.AddConsoleExporter(); | ||
| }); | ||
|
|
||
| using ITestApplication testApplication = await testApplicationBuilder.BuildAsync(); | ||
| return await testApplication.RunAsync(); | ||
| } | ||
| } |
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,87 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Testing.Platform.Extensions.Messages; | ||
| using Microsoft.Testing.Platform.Extensions.TestFramework; | ||
| using Microsoft.Testing.Platform.TestHost; | ||
|
|
||
| namespace MTPOTel; | ||
|
|
||
| internal sealed class SimpleTestFramework : ITestFramework, IDataProducer | ||
| { | ||
| private readonly IServiceProvider _serviceProvider; | ||
|
|
||
| public SimpleTestFramework(IServiceProvider serviceProvider) | ||
| => _serviceProvider = serviceProvider; | ||
|
|
||
| public string Uid => nameof(SimpleTestFramework); | ||
|
|
||
| public string Version => "1.0.0"; | ||
|
|
||
| public string DisplayName => "Simple Test Framework"; | ||
|
|
||
| public string Description => "A simple test framework that returns 5 tests run sequentially"; | ||
|
|
||
| public Type[] DataTypesProduced => [typeof(TestNodeUpdateMessage)]; | ||
|
|
||
| public Task<bool> IsEnabledAsync() => Task.FromResult(true); | ||
|
|
||
| public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context) | ||
| => Task.FromResult(new CreateTestSessionResult { IsSuccess = true }); | ||
|
|
||
| public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context) | ||
| => Task.FromResult(new CloseTestSessionResult { IsSuccess = true }); | ||
|
|
||
| public async Task ExecuteRequestAsync(ExecuteRequestContext context) | ||
| { | ||
| var sessionUid = new SessionUid("SimpleTestSession"); | ||
|
|
||
| // Create 5 tests to run sequentially | ||
| for (int i = 1; i <= 5; i++) | ||
| { | ||
| string testId = $"Test{i}"; | ||
| string testName = $"Simple Test {i}"; | ||
|
|
||
| // Publish test node as in-progress | ||
| await context.MessageBus.PublishAsync( | ||
| this, | ||
| new TestNodeUpdateMessage( | ||
| sessionUid, | ||
| new TestNode | ||
| { | ||
| Uid = testId, | ||
| DisplayName = testName, | ||
| Properties = new PropertyBag(new InProgressTestNodeStateProperty()), | ||
| })); | ||
|
|
||
| // Simulate test execution | ||
| Console.WriteLine($"Executing {testName}..."); | ||
| await Task.Delay(500); // Simulate some work | ||
|
|
||
| // Determine test result (all pass for now) | ||
| bool testPassed = true; | ||
|
|
||
| // Publish test node as passed or failed | ||
| IProperty resultProperty = testPassed | ||
| ? new PassedTestNodeStateProperty() | ||
| : new FailedTestNodeStateProperty(new InvalidOperationException($"{testName} failed")); | ||
|
|
||
| await context.MessageBus.PublishAsync( | ||
| this, | ||
| new TestNodeUpdateMessage( | ||
| sessionUid, | ||
| new TestNode | ||
| { | ||
| Uid = testId, | ||
| DisplayName = testName, | ||
| Properties = new PropertyBag(resultProperty), | ||
| })); | ||
|
|
||
| Console.WriteLine($"{testName} completed: {(testPassed ? "Passed" : "Failed")}"); | ||
| } | ||
|
|
||
| context.Complete(); | ||
| } | ||
| } |
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
19 changes: 19 additions & 0 deletions
19
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/ActivityWrapper.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,19 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using Microsoft.Testing.Platform.Telemetry; | ||
|
|
||
| namespace Microsoft.Testing.Extensions.OpenTelemetry; | ||
|
|
||
| internal sealed class ActivityWrapper(Activity activity) : IPlatformActivity | ||
| { | ||
| public string? Id => activity.Id; | ||
|
|
||
| public IPlatformActivity SetTag(string key, object? value) | ||
| { | ||
| activity.SetTag(key, value); | ||
| return this; | ||
| } | ||
|
|
||
| public void Dispose() => activity.Dispose(); | ||
| } |
4 changes: 4 additions & 0 deletions
4
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/BannedSymbols.txt
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,4 @@ | ||
| M:System.String.IsNullOrEmpty(System.String); Use 'TAString.IsNullOrEmpty' instead | ||
| M:System.String.IsNullOrWhiteSpace(System.String); Use 'TAString.IsNullOrWhiteSpace' instead | ||
| M:System.Diagnostics.Debug.Assert(System.Boolean); Use 'RoslynDebug.Assert' instead | ||
| M:System.Diagnostics.Debug.Assert(System.Boolean,System.String); Use 'RoslynDebug.Assert' instead |
20 changes: 20 additions & 0 deletions
20
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/CounterWrapper.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 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Diagnostics.Metrics; | ||
|
|
||
| using Microsoft.Testing.Platform.Telemetry; | ||
|
|
||
| namespace Microsoft.Testing.Extensions.OpenTelemetry; | ||
|
|
||
| internal sealed class CounterWrapper<T> : ICounter<T> | ||
| where T : struct | ||
| { | ||
| private readonly Counter<T> _counter; | ||
|
|
||
| public CounterWrapper(Counter<T> counter) | ||
| => _counter = counter | ||
| ?? throw new ArgumentNullException(nameof(counter)); | ||
|
|
||
| public void Add(T delta) => _counter.Add(delta); | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/HistogramWrapper.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,21 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Diagnostics.Metrics; | ||
|
|
||
| using Microsoft.Testing.Platform.Telemetry; | ||
|
|
||
| namespace Microsoft.Testing.Extensions.OpenTelemetry; | ||
|
|
||
| internal sealed class HistogramWrapper<T> : IHistogram<T> | ||
Evangelink marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| where T : struct | ||
| { | ||
| private readonly Histogram<T> _histogram; | ||
|
|
||
| public HistogramWrapper(Histogram<T> histogram) | ||
| => _histogram = histogram | ||
| ?? throw new ArgumentNullException(nameof(histogram)); | ||
|
|
||
| public void Record(T value) | ||
| => _histogram.Record(value); | ||
| } | ||
Oops, something went wrong.
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.