Skip to content

Commit 237bf59

Browse files
committed
very basic spans
1 parent 0dd5258 commit 237bf59

File tree

8 files changed

+47
-12
lines changed

8 files changed

+47
-12
lines changed

NuGet.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
1414
<add key="vssdk" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vssdk/nuget/v3/index.json" />
1515
<add key="vs-impl" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl/nuget/v3/index.json" />
16+
<add key="Nuget.org" value="https://api.nuget.org/v3/index.json" />
1617
</packageSources>
1718
<disabledPackageSources>
1819
<clear />

src/Compiler/Driver/ParseAndCheckInputs.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
module internal FSharp.Compiler.ParseAndCheckInputs
55

66
open System
7+
open System.Diagnostics
78
open System.IO
89
open System.Collections.Generic
910

@@ -21,6 +22,7 @@ open FSharp.Compiler.CompilerConfig
2122
open FSharp.Compiler.CompilerDiagnostics
2223
open FSharp.Compiler.CompilerImports
2324
open FSharp.Compiler.Diagnostics
25+
open FSharp.Compiler.Diagnostics.Activity
2426
open FSharp.Compiler.DiagnosticsLogger
2527
open FSharp.Compiler.Features
2628
open FSharp.Compiler.IO

src/Compiler/Driver/fsc.fs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ open FSharp.Compiler.CompilerGlobalState
3939
open FSharp.Compiler.CreateILModule
4040
open FSharp.Compiler.DependencyManager
4141
open FSharp.Compiler.Diagnostics
42+
open FSharp.Compiler.Diagnostics.Activity
4243
open FSharp.Compiler.DiagnosticsLogger
4344
open FSharp.Compiler.IlxGen
4445
open FSharp.Compiler.InfoReader
@@ -166,6 +167,8 @@ let TypeCheck
166167
inputs,
167168
exiter: Exiter
168169
) =
170+
use typecheckActivity = activitySource.StartActivity("typecheck_inputs")
171+
169172
try
170173
if isNil inputs then
171174
error (Error(FSComp.SR.fscNoImplementationFiles (), rangeStartup))
@@ -529,6 +532,7 @@ let main1
529532

530533
// Process command line, flags and collect filenames
531534
let sourceFiles =
535+
use parseActivity = activitySource.StartActivity("fcs:main1:determine_sources")
532536

533537
// The ParseCompilerOptions function calls imperative function to process "real" args
534538
// Rather than start processing, just collect names, then process them.
@@ -562,6 +566,8 @@ let main1
562566

563567
// If there's a problem building TcConfig, abort
564568
let tcConfig =
569+
use createConfigActivity = activitySource.StartActivity("fcs:main1:create_tc_config")
570+
565571
try
566572
TcConfig.Create(tcConfigB, validate = false)
567573
with e ->
@@ -586,10 +592,12 @@ let main1
586592
let foundationalTcConfigP = TcConfigProvider.Constant tcConfig
587593

588594
let sysRes, otherRes, knownUnresolved =
595+
use splitResolutionsActivity = activitySource.StartActivity("fcs:main1:split_resolutions")
589596
TcAssemblyResolutions.SplitNonFoundationalResolutions(tcConfig)
590597

591598
// Import basic assemblies
592599
let tcGlobals, frameworkTcImports =
600+
use frameworkImportsActivity = activitySource.StartActivity("fcs:main:import_framework_references")
593601
TcImports.BuildFrameworkTcImports(foundationalTcConfigP, sysRes, otherRes)
594602
|> NodeCode.RunImmediateWithoutCancellation
595603

@@ -642,6 +650,7 @@ let main1
642650
ReportTime tcConfig "Import non-system references"
643651

644652
let tcImports =
653+
use nonFrameworkImportsActivity = activitySource.StartActivity("fcs:main1:import_non_framework_references")
645654
TcImports.BuildNonFrameworkTcImports(tcConfigP, frameworkTcImports, otherRes, knownUnresolved, dependencyProvider)
646655
|> NodeCode.RunImmediateWithoutCancellation
647656

@@ -660,6 +669,7 @@ let main1
660669
use unwindParsePhase = PushThreadBuildPhaseUntilUnwind BuildPhase.TypeCheck
661670

662671
let tcEnv0, openDecls0 =
672+
use initialTcEnvActivity = activitySource.StartActivity("fcs:main1:get_initial_tc_env")
663673
GetInitialTcEnv(assemblyName, rangeStartup, tcConfig, tcImports, tcGlobals)
664674

665675
// Type check the inputs
@@ -719,7 +729,9 @@ let main1OfAst
719729
disposables: DisposablesTracker,
720730
inputs: ParsedInput list
721731
) =
722-
732+
733+
use main1AstActivity = activitySource.StartActivity("fcs:main1_ast")
734+
723735
let tryGetMetadataSnapshot = (fun _ -> None)
724736

725737
let directoryBuildingFrom = Directory.GetCurrentDirectory()
@@ -904,6 +916,8 @@ let main2
904916
exiter: Exiter,
905917
ilSourceDocs))
906918
=
919+
use main2Activity = activitySource.StartActivity("fcs:main2")
920+
907921

908922
if tcConfig.typeCheckOnly then
909923
exiter.Exit 0
@@ -1012,7 +1026,7 @@ let main3
10121026
exiter: Exiter,
10131027
ilSourceDocs))
10141028
=
1015-
1029+
use main3Activity = activitySource.StartActivity("fcs:main3")
10161030
// Encode the signature data
10171031
ReportTime tcConfig "Encode Interface Data"
10181032
let exportRemapping = MakeExportRemapping generatedCcu generatedCcu.Contents
@@ -1108,6 +1122,7 @@ let main4
11081122
exiter: Exiter,
11091123
ilSourceDocs))
11101124
=
1125+
use main4Activity = activitySource.StartActivity("fcs:main4")
11111126

11121127
match tcImportsCapture with
11131128
| None -> ()
@@ -1212,6 +1227,7 @@ let main5
12121227
exiter: Exiter,
12131228
ilSourceDocs))
12141229
=
1230+
use main5Activity = activitySource.StartActivity("fcs:main5")
12151231

12161232
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind BuildPhase.Output
12171233

@@ -1244,6 +1260,7 @@ let main6
12441260
exiter: Exiter,
12451261
ilSourceDocs))
12461262
=
1263+
use main6Activity = activitySource.StartActivity("fcs:main6")
12471264

12481265
ReportTime tcConfig "Write .NET Binary"
12491266

@@ -1368,6 +1385,7 @@ let CompileFromCommandLineArguments
13681385
tcImportsCapture,
13691386
dynamicAssemblyCreator
13701387
) =
1388+
use mainActivity = activitySource.StartActivity("fcs:main")
13711389

13721390
use disposables = new DisposablesTracker()
13731391
let savedOut = Console.Out

src/Compiler/FSharp.Compiler.Service.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Project Sdk="Microsoft.NET.Sdk">
44

55
<PropertyGroup>
6-
<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
6+
<TargetFrameworks>netstandard2.0;net472;</TargetFrameworks>
77
<OutputType>Library</OutputType>
88
<NoWarn>$(NoWarn);44</NoWarn> <!-- Obsolete -->
99
<NoWarn>$(NoWarn);57</NoWarn> <!-- Experimental -->
@@ -497,6 +497,7 @@
497497
<ItemGroup>
498498
<PackageReference Include="System.Runtime.Loader" Version="$(SystemRuntimeLoaderVersion)" />
499499
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
500+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemdiagnosticsDiagnosticSourceVersion)" />
500501
<PackageReference Include="System.Diagnostics.Process" Version="$(SystemDiagnosticsProcessVersion)" />
501502
<PackageReference Include="System.Diagnostics.TraceSource" Version="$(SystemDiagnosticsTraceSourceVersion)" />
502503
<PackageReference Include="System.Linq.Expressions" Version="$(SystemLinqExpressionsVersion)" />

src/Compiler/Facilities/Logger.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
namespace FSharp.Compiler.Diagnostics
44

5-
open System.Diagnostics.Tracing
65
open System
6+
open System.Diagnostics
7+
open System.Diagnostics.Tracing
8+
9+
module Activity =
10+
let activitySourceName = "fsc"
11+
let activitySource = new ActivitySource(activitySourceName)
712

813
type LogCompilerFunctionId =
914
| Service_ParseAndCheckFileInProject = 1

src/Compiler/Facilities/Logger.fsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
namespace FSharp.Compiler.Diagnostics
44

55
open System
6+
open System.Diagnostics
7+
8+
module Activity =
9+
val activitySourceName: string
10+
val activitySource: ActivitySource
611

712
type internal LogCompilerFunctionId =
813
| Service_ParseAndCheckFileInProject = 1

src/fsc/fscProject/fsc.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<PropertyGroup >
66
<TargetFrameworks Condition="'$(ProtoTargetFramework)' != ''">$(ProtoTargetFramework)</TargetFrameworks>
7-
<TargetFrameworks Condition="'$(ProtoTargetFramework)' == ''">net472;net6.0</TargetFrameworks>
7+
<TargetFrameworks Condition="'$(ProtoTargetFramework)' == ''">net6.0;net472;</TargetFrameworks>
88
<TargetFrameworks Condition="'$(OS)' == 'Unix'">net6.0</TargetFrameworks>
99
<PlatformTarget Condition="'$(TargetFramework)' == 'net472'">x86</PlatformTarget>
1010
</PropertyGroup>

src/fsc/fscmain.fs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ open Internal.Utilities.Library.Extras
1313
open FSharp.Compiler.AbstractIL
1414
open FSharp.Compiler.AbstractIL.ILBinaryReader
1515
open FSharp.Compiler.CompilerConfig
16+
open FSharp.Compiler.Diagnostics.Activity
1617
open FSharp.Compiler.Driver
1718
open FSharp.Compiler.DiagnosticsLogger
1819
open FSharp.Compiler.CodeAnalysis
@@ -26,18 +27,20 @@ open OpenTelemetry.Trace
2627
do ()
2728

2829
[<EntryPoint>]
29-
let main (argv) =
30+
let main(argv) =
3031

31-
use tracerProvider =
32+
// eventually this would need to only export to the OLTP collector, and even then only if configured. always-on is no good.
33+
// when this configuration becomes opt-in, we'll also need to safely check activities around every StartActivity call, because those could
34+
// be null
35+
use tracerProvider =
3236
Sdk.CreateTracerProviderBuilder()
33-
.AddSource("fsc")
37+
.AddSource(activitySourceName)
3438
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(serviceName ="fsc", serviceVersion = "42.42.42.42"))
3539
.AddConsoleExporter()
3640
.Build();
37-
use activitySource = new ActivitySource("fsc")
38-
use mainActivity = activitySource.StartActivity("main")
39-
40-
let forceCleanup() =
41+
use mainActivity = activitySource.StartActivity("main")
42+
43+
let forceCleanup() =
4144
mainActivity.Dispose()
4245
activitySource.Dispose()
4346
tracerProvider.Dispose()

0 commit comments

Comments
 (0)