Skip to content

Commit 5658f02

Browse files
committed
Merge remote-tracking branch 'baronfel/activities' into otel
2 parents a7b6681 + 4618764 commit 5658f02

File tree

10 files changed

+72
-8
lines changed

10 files changed

+72
-8
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 />

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<SystemConsoleVersion>4.3.0</SystemConsoleVersion>
8888
<SystemDataSqlClientPackageVersion>4.3.0</SystemDataSqlClientPackageVersion>
8989
<SystemDesignVersion>4.0.0</SystemDesignVersion>
90+
<SystemDiagnosticsDiagnosticSourceVersion>5.0.1</SystemDiagnosticsDiagnosticSourceVersion>
9091
<SystemDiagnosticsProcessVersion>4.3.0</SystemDiagnosticsProcessVersion>
9192
<SystemDiagnosticsTraceSourceVersion>4.3.0</SystemDiagnosticsTraceSourceVersion>
9293
<MicrosoftDiaSymReaderPortablePdbVersion>1.6.0</MicrosoftDiaSymReaderPortablePdbVersion>

src/Compiler/Driver/ParseAndCheckInputs.fs

Lines changed: 6 additions & 1 deletion
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
@@ -1290,7 +1292,9 @@ let CheckOneInput
12901292
}
12911293

12921294
/// Typecheck a single file (or interactive entry into F# Interactive)
1293-
let TypeCheckOneInputEntry (ctok, checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt) tcState inp =
1295+
let TypeCheckOneInputEntry (ctok, checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt) tcState (inp: ParsedInput) =
1296+
use tcOneInputActivity = activitySource.StartActivity("CheckOneInput")
1297+
tcOneInputActivity.AddTag("inputName", inp.FileName) |> ignore<_>
12941298
// 'use' ensures that the warning handler is restored at the end
12951299
use unwindEL =
12961300
PushDiagnosticsLoggerPhaseUntilUnwind(fun oldLogger ->
@@ -1339,6 +1343,7 @@ let CheckClosedInputSetFinish (declaredImpls: CheckedImplFile list, tcState) =
13391343
tcState, declaredImpls, ccuContents
13401344

13411345
let CheckClosedInputSet (ctok, checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, inputs) =
1346+
use tcActivity = activitySource.StartActivity("CheckClosedInputSet")
13421347
// tcEnvAtEndOfLastFile is the environment required by fsi.exe when incrementally adding definitions
13431348
let results, tcState =
13441349
(tcState, inputs)

src/Compiler/Driver/fsc.fs

Lines changed: 21 additions & 3 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))
@@ -474,6 +477,8 @@ let main1
474477
diagnosticsLoggerProvider: DiagnosticsLoggerProvider,
475478
disposables: DisposablesTracker
476479
) =
480+
481+
use mainActivity = new Activity("main")
477482

478483
// See Bug 735819
479484
let lcidFromCodePage =
@@ -529,6 +534,7 @@ let main1
529534

530535
// Process command line, flags and collect filenames
531536
let sourceFiles =
537+
use parseActivity = activitySource.StartActivity("determine_source_files")
532538

533539
// The ParseCompilerOptions function calls imperative function to process "real" args
534540
// Rather than start processing, just collect names, then process them.
@@ -562,6 +568,8 @@ let main1
562568

563569
// If there's a problem building TcConfig, abort
564570
let tcConfig =
571+
use createConfigActivity = activitySource.StartActivity("create_tc_config")
572+
565573
try
566574
TcConfig.Create(tcConfigB, validate = false)
567575
with e ->
@@ -586,10 +594,12 @@ let main1
586594
let foundationalTcConfigP = TcConfigProvider.Constant tcConfig
587595

588596
let sysRes, otherRes, knownUnresolved =
597+
use splitResolutionsActivity = activitySource.StartActivity("split_resolutions")
589598
TcAssemblyResolutions.SplitNonFoundationalResolutions(tcConfig)
590599

591600
// Import basic assemblies
592601
let tcGlobals, frameworkTcImports =
602+
use frameworkImportsActivity = activitySource.StartActivity("import_framework_references")
593603
TcImports.BuildFrameworkTcImports(foundationalTcConfigP, sysRes, otherRes)
594604
|> NodeCode.RunImmediateWithoutCancellation
595605

@@ -642,6 +652,7 @@ let main1
642652
ReportTime tcConfig "Import non-system references"
643653

644654
let tcImports =
655+
use nonFrameworkImportsActivity = activitySource.StartActivity("import_non_framework_references")
645656
TcImports.BuildNonFrameworkTcImports(tcConfigP, frameworkTcImports, otherRes, knownUnresolved, dependencyProvider)
646657
|> NodeCode.RunImmediateWithoutCancellation
647658

@@ -660,6 +671,7 @@ let main1
660671
use unwindParsePhase = PushThreadBuildPhaseUntilUnwind BuildPhase.TypeCheck
661672

662673
let tcEnv0, openDecls0 =
674+
use initialTcEnvActivity = activitySource.StartActivity("get_initial_tc_env")
663675
GetInitialTcEnv(assemblyName, rangeStartup, tcConfig, tcImports, tcGlobals)
664676

665677
// Type check the inputs
@@ -719,7 +731,9 @@ let main1OfAst
719731
disposables: DisposablesTracker,
720732
inputs: ParsedInput list
721733
) =
722-
734+
735+
use main1AstActivity = activitySource.StartActivity("main1_of_ast")
736+
723737
let tryGetMetadataSnapshot = (fun _ -> None)
724738

725739
let directoryBuildingFrom = Directory.GetCurrentDirectory()
@@ -904,6 +918,8 @@ let main2
904918
exiter: Exiter,
905919
ilSourceDocs))
906920
=
921+
use main2Activity = activitySource.StartActivity("main2")
922+
907923

908924
if tcConfig.typeCheckOnly then
909925
exiter.Exit 0
@@ -1012,7 +1028,7 @@ let main3
10121028
exiter: Exiter,
10131029
ilSourceDocs))
10141030
=
1015-
1031+
use main3Activity = activitySource.StartActivity("main3")
10161032
// Encode the signature data
10171033
ReportTime tcConfig "Encode Interface Data"
10181034
let exportRemapping = MakeExportRemapping generatedCcu generatedCcu.Contents
@@ -1108,6 +1124,7 @@ let main4
11081124
exiter: Exiter,
11091125
ilSourceDocs))
11101126
=
1127+
use main4Activity = activitySource.StartActivity("main4")
11111128

11121129
match tcImportsCapture with
11131130
| None -> ()
@@ -1211,6 +1228,7 @@ let main5
12111228
exiter: Exiter,
12121229
ilSourceDocs))
12131230
=
1231+
use main5Activity = activitySource.StartActivity("main5")
12141232

12151233
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind BuildPhase.Output
12161234

@@ -1243,6 +1261,7 @@ let main6
12431261
exiter: Exiter,
12441262
ilSourceDocs))
12451263
=
1264+
use main6Activity = activitySource.StartActivity("main6")
12461265

12471266
ReportTime tcConfig "Write .NET Binary"
12481267

@@ -1379,7 +1398,6 @@ let CompileFromCommandLineArguments
13791398
with _ ->
13801399
()
13811400
}
1382-
13831401
main1 (
13841402
ctok,
13851403
argv,

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 -->
@@ -496,6 +496,7 @@
496496
<ItemGroup>
497497
<PackageReference Include="System.Runtime.Loader" Version="$(SystemRuntimeLoaderVersion)" />
498498
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
499+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemdiagnosticsDiagnosticSourceVersion)" />
499500
<PackageReference Include="System.Diagnostics.Process" Version="$(SystemDiagnosticsProcessVersion)" />
500501
<PackageReference Include="System.Diagnostics.TraceSource" Version="$(SystemDiagnosticsTraceSourceVersion)" />
501502
<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/fsc.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@
3737

3838
<ItemGroup>
3939
<PackageReference Include="System.Console" Version="$(SystemConsoleVersion)" />
40+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourceVersion)" />
4041
<PackageReference Include="System.Linq.Expressions" Version="$(SystemLinqExpressionsVersion)" />
4142
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
4243
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafeVersion)" />
4344
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
4445
<PackageReference Include="System.Runtime.Loader" Version="$(SystemRuntimeLoaderVersion)" />
4546
<PackageReference Include="System.Security.Principal" Version="$(SystemSecurityPrincipalVersion)" />
47+
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.1.0" />
48+
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.1.0" />
49+
4650
</ItemGroup>
4751

4852
</Project>

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: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,38 @@ 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
1920
open FSharp.Compiler.Text
21+
open System.Diagnostics
22+
open OpenTelemetry
23+
open OpenTelemetry.Resources
24+
open OpenTelemetry.Trace
2025

2126
[<Dependency("FSharp.Compiler.Service", LoadHint.Always)>]
2227
do ()
2328

2429
[<EntryPoint>]
25-
let main (argv) =
30+
let main(argv) =
31+
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 =
36+
Sdk.CreateTracerProviderBuilder()
37+
.AddSource(activitySourceName)
38+
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(serviceName ="fsc", serviceVersion = "42.42.42.42"))
39+
.AddOtlpExporter()
40+
.AddZipkinExporter()
41+
.Build();
42+
use mainActivity = activitySource.StartActivity("main")
43+
44+
let forceCleanup() =
45+
mainActivity.Dispose()
46+
activitySource.Dispose()
47+
tracerProvider.Dispose()
2648

2749
let compilerName =
2850
// the 64 bit desktop version of the compiler is name fscAnyCpu.exe, all others are fsc.exe
@@ -67,6 +89,7 @@ let main (argv) =
6789
let stats = ILBinaryReader.GetStatistics()
6890

6991
AppDomain.CurrentDomain.ProcessExit.Add(fun _ ->
92+
forceCleanup()
7093
printfn
7194
"STATS: #ByteArrayFile = %d, #MemoryMappedFileOpen = %d, #MemoryMappedFileClosed = %d, #RawMemoryFile = %d, #WeakByteArrayFile = %d"
7295
stats.byteFileCount
@@ -81,6 +104,7 @@ let main (argv) =
81104
let quitProcessExiter =
82105
{ new Exiter with
83106
member _.Exit(n) =
107+
forceCleanup()
84108
try
85109
exit n
86110
with _ ->

0 commit comments

Comments
 (0)