Repository navigation
[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 17 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
| 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
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) : IActivity | ||
|
Evangelink marked this conversation as resolved.
Resolved
|
||
| { | ||
| public string? Id => activity.Id; | ||
|
|
||
| public IActivity 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> | ||
|
Evangelink marked this conversation as resolved.
Resolved
|
||
| 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.
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); | ||
| } | ||
39 changes: 39 additions & 0 deletions
39
...rosoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csproj
|
Evangelink marked this conversation as resolved.
Resolved
|
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,39 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>netstandard2.0;$(MicrosoftTestingTargetFrameworks)</TargetFrameworks> | ||
|
Evangelink marked this conversation as resolved.
Resolved
|
||
| </PropertyGroup> | ||
|
|
||
| <!-- NuGet properties --> | ||
| <PropertyGroup> | ||
| <PackageDescription> | ||
| <![CDATA[Microsoft Testing is a set of platform, framework and protocol intended to make it possible to run any test on any target or device. | ||
|
|
||
| This package provides Open Telemetry for the platform.]]> | ||
| </PackageDescription> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <InternalsVisibleTo Include="Microsoft.Testing.Extensions.UnitTests" Key="$(VsPublicKey)" /> | ||
| <InternalsVisibleTo Include="DynamicProxyGenAssembly2" Key="$(MoqPublicKey)" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <AdditionalFiles Include="BannedSymbols.txt" /> | ||
| <AdditionalFiles Include="PublicAPI/PublicAPI.Shipped.txt" /> | ||
| <AdditionalFiles Include="PublicAPI/PublicAPI.Unshipped.txt" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="OpenTelemetry" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform\Microsoft.Testing.Platform.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="Polyfills" /> | ||
|
Evangelink marked this conversation as resolved.
Resolved
|
||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
35 changes: 35 additions & 0 deletions
35
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/OpenTelemetryPlatformService.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,35 @@ | ||
| // 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 OpenTelemetryPlatformService : IPlatformOpenTelemetryService | ||
| { | ||
| internal const string ActivitySourceName = "Microsoft.Testing.Platform"; | ||
| internal const string MeterName = "Microsoft.Testing.Platform"; | ||
|
|
||
| private readonly ActivitySource _activitySource = new(ActivitySourceName, PlatformVersion.Version); | ||
| private readonly Meter _meter = new(MeterName, PlatformVersion.Version); | ||
|
|
||
| public IActivity? TestFrameworkActivity { get; set; } | ||
|
|
||
| public IActivity? StartActivity([CallerMemberName] string name = "", IEnumerable<KeyValuePair<string, object?>>? tags = null, string? parentId = null, DateTimeOffset startTime = default) | ||
| => _activitySource.StartActivity(name, ActivityKind.Internal, tags: tags, startTime: startTime, parentId: parentId) is Activity activity | ||
| ? new ActivityWrapper(activity) | ||
| : null; | ||
|
|
||
| public ICounter<T> CreateCounter<T>(string name, string? unit = null, string? description = null, IEnumerable<KeyValuePair<string, object?>>? tags = null) | ||
| where T : struct | ||
| => new CounterWrapper<T>(_meter.CreateCounter<T>(name, unit, description, tags!)); | ||
|
|
||
| public IHistogram<T> CreateHistogram<T>(string name, string? unit = null, string? description = null, IEnumerable<KeyValuePair<string, object?>>? tags = null) | ||
| where T : struct | ||
| => new HistogramWrapper<T>(_meter.CreateHistogram<T>(name, unit, description, tags)); | ||
|
|
||
| public void Dispose() | ||
| => _activitySource.Dispose(); | ||
| } |
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.