Repository navigation
Enable OTel telemetry for purely-AOT operations #54544
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
Changes from all commits
660d667
1267a00
d9f7dec
0d3d4fe
f8a824c
f5e34bd
1b9d857
efba412
17c6b19
e79f768
e5600f4
35fd2b5
692c31b
a84fedc
7153f10
4d89ae2
66afcab
6dbe5fa
ab9a5ab
76f0492
220e661
118b477
7c4aeba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,22 @@ | |
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\CommandParsingException.cs" Link="CommandParsingException.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\CommandNotAvailableInAotException.cs" Link="CommandNotAvailableInAotException.cs" /> | ||
| <Compile Include="$(RepoRoot)src\Common\EnvironmentVariableNames.cs" LinkBase="Common" /> | ||
| <Compile Include="$(RepoRoot)src\Common\CompileOptions.cs" LinkBase="Common" /> | ||
| <Compile Include="$(RepoRoot)src\Common\CliFolderPathCalculatorCore.cs" LinkBase="Common" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\TelemetryClient.cs" Link="TelemetryClient.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\TelemetryCommonProperties.cs" Link="TelemetryCommonProperties.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\ITelemetryClient.cs" Link="ITelemetryClient.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\TelemetryDiskLogger.cs" Link="TelemetryDiskLogger.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\IDockerContainerDetector.cs" Link="Telemetry\IDockerContainerDetector.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\DockerContainerDetectorForTelemetry.cs" Link="Telemetry\DockerContainerDetectorForTelemetry.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\ILLMEnvironmentDetector.cs" Link="Telemetry\ILLMEnvironmentDetector.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\LLMEnvironmentDetectorForTelemetry.cs" Link="Telemetry\LLMEnvironmentDetectorForTelemetry.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\MacAddressGetter.cs" Link="Telemetry\MacAddressGetter.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\DevDeviceIDGetter.cs" Link="Telemetry\DevDeviceIDGetter.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Telemetry\ExternalTelemetryProperties.cs" Link="Telemetry\ExternalTelemetryProperties.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Extensions\ActivityExtensions.cs" Link="ActivityExtensions.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Extensions\ParseResultExtensions.cs" Link="ParseResultExtensions.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\Microsoft.TemplateEngine.Cli\SymbolExtensions.cs" Link="SymbolExtensions.cs" /> | ||
|
Comment on lines
+34
to
+49
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bunch of the telemetry-related code as well as a few extensions files that are used in computing some of the telemetry data. |
||
| </ItemGroup> | ||
|
|
||
| <!-- Common AOT scaffolding: generated string resources referenced by command sources. --> | ||
|
|
@@ -44,7 +60,6 @@ | |
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\SlnFileFactory.cs" Link="SlnFileFactory.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\SlnfFileHelper.cs" Link="SlnfFileHelper.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\MsbuildProject.cs" Link="MsbuildProject.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\Microsoft.DotNet.FileBasedPrograms\ProjectLocator.cs" Link="ProjectLocator.cs" /> | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two removals are because I added a project reference to the actual ProjectTools/FileBasedPrograms code as part of this work, so there were build-time type-load conflicts. |
||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Commands\Solution\SolutionCommandParser.cs" Link="Commands\Solution\SolutionCommandParser.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Commands\Solution\SolutionArgumentValidator.cs" Link="Commands\Solution\SolutionArgumentValidator.cs" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\dotnet\Commands\Solution\List\SolutionListCommand.cs" Link="Commands\Solution\List\SolutionListCommand.cs" /> | ||
|
|
@@ -54,7 +69,6 @@ | |
|
|
||
| <!-- 'dotnet sln' command: command-specific dependencies. --> | ||
| <ItemGroup> | ||
| <EmbeddedResource Include="$(MSBuildThisFileDirectory)..\Microsoft.DotNet.FileBasedPrograms\FileBasedProgramsResources.resx" Link="FileBasedProgramsResources.resx" GenerateSource="true" Namespace="Microsoft.DotNet.FileBasedPrograms" /> | ||
| <ProjectReference Include="$(MSBuildThisFileDirectory)..\Microsoft.DotNet.Cli.Definitions\Microsoft.DotNet.Cli.Definitions.csproj" GlobalPropertiesToRemove="PublishDir" /> | ||
| <PackageReference Include="Microsoft.VisualStudio.SolutionPersistence" /> | ||
| </ItemGroup> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| extern alias NativeWrapper; | ||
|
|
||
| using System.Diagnostics; | ||
| using Microsoft.DotNet.Cli.Utils; | ||
| using Microsoft.DotNet.NativeWrapper; | ||
| using NativeConstants = NativeWrapper::Microsoft.DotNet.NativeWrapper.Constants; | ||
|
|
||
| namespace Microsoft.DotNet.Cli; | ||
|
|
||
|
|
@@ -122,6 +127,7 @@ public static int RunApp(string hostPath, string dotnetRoot, string hostfxrPath, | |
|
|
||
| try | ||
| { | ||
| var _init = Activities.Source.StartActivity("aot-hostfxr-initialization"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
| StatusCode result = Interop.hostfxr_initialize_for_dotnet_command_line( | ||
| args.Length, | ||
| args, | ||
|
|
@@ -130,8 +136,15 @@ public static int RunApp(string hostPath, string dotnetRoot, string hostfxrPath, | |
|
|
||
| if (result != StatusCode.Success && handle == 0) | ||
| { | ||
| _init?.SetStatus(ActivityStatusCode.Error); | ||
| _init?.Stop(); | ||
| throw new InvalidOperationException($"hostfxr_initialize_for_dotnet_command_line failed. Status: {result} (0x{(uint)result:X8})"); | ||
| } | ||
| else | ||
| { | ||
| _init?.SetStatus(ActivityStatusCode.Ok); | ||
| _init?.Stop(); | ||
| } | ||
|
|
||
| try | ||
| { | ||
|
|
@@ -141,14 +154,28 @@ public static int RunApp(string hostPath, string dotnetRoot, string hostfxrPath, | |
| if (!string.IsNullOrEmpty(hostfxrPath)) | ||
| { | ||
| StatusCode propertyResult = Interop.hostfxr_set_runtime_property_value( | ||
| handle, Constants.RuntimeProperty.HostFxrPath, hostfxrPath); | ||
| handle, NativeConstants.RuntimeProperty.HostFxrPath, hostfxrPath); | ||
| if (propertyResult != StatusCode.Success) | ||
| { | ||
| throw new InvalidOperationException( | ||
| $"hostfxr_set_runtime_property_value failed for {Constants.RuntimeProperty.HostFxrPath}. Status: {propertyResult} (0x{(uint)propertyResult:X8})"); | ||
| $"hostfxr_set_runtime_property_value failed for {NativeConstants.RuntimeProperty.HostFxrPath}. Status: {propertyResult} (0x{(uint)propertyResult:X8})"); | ||
| } | ||
| } | ||
|
|
||
| // Propagate OTel trace context to the managed CLI so that its spans | ||
| // become children of the AOT-side main activity. | ||
| if (Activity.Current is { } currentActivity) | ||
| { | ||
| string traceparent = $"00-{currentActivity.Context.TraceId}-{currentActivity.Context.SpanId}-{(currentActivity.Context.TraceFlags == ActivityTraceFlags.Recorded ? "01" : "00")}"; | ||
| Interop.hostfxr_set_runtime_property_value(handle, Activities.TRACEPARENT, traceparent); | ||
|
|
||
| if (!string.IsNullOrEmpty(currentActivity.Context.TraceState)) | ||
| { | ||
| Interop.hostfxr_set_runtime_property_value(handle, Activities.TRACESTATE, currentActivity.Context.TraceState); | ||
|
Comment on lines
+167
to
+174
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to ensure that if we were tracking OTel activities, the 'inner' managed call would recognize that and configure itself as a 'child' of the caller. To do this, I needed to somehow communicate the 'trace parent' and 'trace state' concepts to the child. We already had a way of pulling traceparent/tracestate data from env vars, but I didn't want the managed host to set env vars - that is 'leaky' to other processes that are spawned from the managed cli. These runtime properties seemed like a nice compromise. |
||
| } | ||
| } | ||
|
|
||
| using var invoke = Activities.Source.StartActivity("aot-coreclr-invocation"); | ||
| StatusCode appResult = Interop.hostfxr_run_app(handle); | ||
| return (int)appResult; | ||
| } | ||
|
|
||
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.
this is a convenience thing that I added because creating the tarballs was painful on the inner loop