Skip to content
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

OpenTelemetry proof of concept #1060

Merged
merged 18 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Title>FsAutoComplete</Title>
<Product>FsAutoComplete</Product>
<PackageLicenseExpression Condition=" '$(PackAsTool)' != 'true' ">Apache-2.0</PackageLicenseExpression>
<NoWarn>3186</NoWarn><!-- circumvent an error with the fake dependencymanager for paket: https://github.com/dotnet/fsharp/issues/8678 -->
<NoWarn>3186,0042</NoWarn><!-- circumvent an error with the fake dependencymanager for paket: https://github.com/dotnet/fsharp/issues/8678 -->
baronfel marked this conversation as resolved.
Show resolved Hide resolved
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ChangelogFile>$(MSBuildThisFileDirectory)CHANGELOG.md</ChangelogFile>
</PropertyGroup>
Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,41 @@ This repository is prepared to use Gitpod for a web-based VSCode-style IDE. Clic
* push this commit and tag to main
* the CI pipeline will publish a release from the tag.


## OpenTelemetry

FsAutocomplete is using [System.Diagnostics.Activity](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/distributed-tracing-instrumentation-walkthroughs) to create traces.

To export traces, run [Jaeger](https://www.jaegertracing.io/)

```bash
docker run -d --name jaeger \
-e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
-e COLLECTOR_OTLP_ENABLED=true \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p 16686:16686 \
-p 4317:4317 \
-p 4318:4318 \
-p 14250:14250 \
-p 14268:14268 \
-p 14269:14269 \
-p 9411:9411 \
jaegertracing/all-in-one:latest
```
Then configure your [environment](https://opentelemetry.io/docs/concepts/sdk-configuration/otlp-exporter-configuration/)

```bash
OTEL_EXPORTER_OTLP_ENDPOINT = "http://localhost:4317"
```
Start FsAutocomplete (either by `code .` or `dotnet fsautocomplete`)

Do some actions like opening documents, saving, getting tooltips, etc.

Then open `http://localhost:16686/` to inspect traces.
baronfel marked this conversation as resolved.
Show resolved Hide resolved


## Communication protocol

FsAutoComplete supports [LSP](https://microsoft.github.io/language-server-protocol/) as a communication protocol.
Expand Down
5 changes: 4 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ source https://api.nuget.org/v3/index.json
#source: ./libs
storage: none

github TheAngryByrd/FsLibLog:f81cba440bf0476bb4e2262b57a067a0d6ab78a7 src/FsLibLog/FsLibLog.fs

github TheAngryByrd/FsLibLog:64f118ae8df2f2944ef69758052cb3b148b87e79 src/FsLibLog/FsLibLog.fs
github TheAngryByrd/FsOpenTelemetry src/FsOpenTelemetry/FsOpenTelemetry.fs
baronfel marked this conversation as resolved.
Show resolved Hide resolved

nuget Fantomas.Client
nuget FSharp.Compiler.Service
Expand Down Expand Up @@ -52,6 +54,7 @@ nuget AltCover
nuget GitHubActionsTestLogger
nuget Ionide.LanguageServerProtocol
nuget Microsoft.Extensions.Caching.Memory
nuget OpenTelemetry.Exporter.OpenTelemetryProtocol

group Build
source https://api.nuget.org/v3/index.json
Expand Down
98 changes: 82 additions & 16 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ NUGET
FSharp.Core (>= 6.0.1) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net5.0))
McMaster.NETCore.Plugins (>= 1.4) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net5.0))
FSharp.Compiler.Service (43.7.200)
FSharp.Core (7.0)
FSharp.Core (7.0.200)
baronfel marked this conversation as resolved.
Show resolved Hide resolved
System.Buffers (>= 4.5.1)
System.Collections.Immutable (>= 6.0)
System.Diagnostics.DiagnosticSource (>= 6.0)
System.Memory (>= 4.5.5)
System.Reflection.Emit (>= 4.7)
System.Reflection.Metadata (>= 6.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0)
FSharp.Control.AsyncSeq (3.2.1)
FSharp.Core (>= 4.7.2)
Microsoft.Bcl.AsyncInterfaces (>= 5.0)
FSharp.Control.Reactive (5.0.5) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net5.0))
FSharp.Control.Reactive (5.0.5) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
FSharp.Core (>= 4.7.2)
System.Reactive (>= 5.0 < 6.0)
FSharp.Core (7.0) - content: none
FSharp.Core (7.0.200) - content: none
FSharp.Data.Adaptive (1.2.13)
FSharp.Core (>= 4.7)
System.Reflection.Emit.Lightweight (>= 4.6)
Expand Down Expand Up @@ -76,6 +77,21 @@ NUGET
FSharp.Core (>= 4.7.2)
GitHubActionsTestLogger (2.0.1)
Microsoft.TestPlatform.ObjectModel (>= 17.2)
Google.Protobuf (3.22)
System.Memory (>= 4.5.3) - restriction: || (&& (== net6.0) (>= net45)) (&& (== net6.0) (< net5.0)) (&& (== net6.0) (< netstandard2.0)) (&& (== net7.0) (>= net45)) (&& (== net7.0) (< net5.0)) (&& (== net7.0) (< netstandard2.0)) (== netstandard2.0)
System.Runtime.CompilerServices.Unsafe (>= 4.5.2) - restriction: || (&& (== net6.0) (< net5.0)) (&& (== net7.0) (< net5.0)) (== netstandard2.0)
Grpc (2.46.6) - restriction: || (&& (== net6.0) (>= net462)) (&& (== net6.0) (< netstandard2.1)) (&& (== net7.0) (>= net462)) (&& (== net7.0) (< netstandard2.1)) (== netstandard2.0)
Grpc.Core (>= 2.46.6)
Grpc.Core (2.46.6) - restriction: || (&& (== net6.0) (>= net45)) (&& (== net6.0) (>= net462)) (&& (== net6.0) (< netstandard2.1)) (&& (== net7.0) (>= net45)) (&& (== net7.0) (>= net462)) (&& (== net7.0) (< netstandard2.1)) (== netstandard2.0)
Grpc.Core.Api (>= 2.46.6)
System.Memory (>= 4.5.3)
Grpc.Core.Api (2.51)
System.Memory (>= 4.5.3)
Grpc.Net.Client (2.51) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= netstandard2.1))
Grpc.Net.Common (>= 2.51)
Microsoft.Extensions.Logging.Abstractions (>= 3.0.3)
Grpc.Net.Common (2.51) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= netstandard2.1))
Grpc.Core.Api (>= 2.51)
ICSharpCode.Decompiler (7.2.1.6856)
Microsoft.Win32.Registry (>= 5.0)
System.Collections.Immutable (>= 5.0)
Expand All @@ -85,25 +101,25 @@ NUGET
FSharp.Core (>= 6.0)
Newtonsoft.Json (>= 13.0.1)
StreamJsonRpc (>= 2.10.44)
Ionide.ProjInfo (0.61)
Ionide.ProjInfo (0.61.2)
FSharp.Core (>= 6.0.5) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.Sln (>= 0.61) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.Sln (>= 0.61.2) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Microsoft.Build (>= 17.2) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Microsoft.Build.Framework (>= 17.2) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
SemanticVersioning (>= 2.0.2) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.FCS (0.61)
FSharp.Compiler.Service (>= 41.0.5 < 42.0) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.FCS (0.61.2)
FSharp.Compiler.Service (>= 41.0.5) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
FSharp.Core (>= 6.0.5) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo (>= 0.61) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.ProjectSystem (0.61)
FSharp.Compiler.Service (>= 41.0.5 < 42.0) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo (>= 0.61.2) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.ProjectSystem (0.61.2)
FSharp.Compiler.Service (>= 41.0.5) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
FSharp.Control.Reactive (>= 5.0.5) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
FSharp.Core (>= 6.0.5) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo (>= 0.61) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.FCS (>= 0.61) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.Sln (>= 0.61) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo (>= 0.61.2) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.FCS (>= 0.61.2) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.Sln (>= 0.61.2) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Newtonsoft.Json (>= 13.0.1) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.Sln (0.61)
Ionide.ProjInfo.Sln (0.61.2)
McMaster.NETCore.Plugins (1.4) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net5.0))
Microsoft.DotNet.PlatformAbstractions (>= 3.1.6) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= netcoreapp2.1))
Microsoft.Extensions.DependencyModel (>= 5.0) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= netcoreapp2.1))
Expand Down Expand Up @@ -165,6 +181,18 @@ NUGET
Microsoft.Extensions.Logging.Abstractions (>= 6.0)
Microsoft.Extensions.Options (>= 6.0)
Microsoft.Extensions.Primitives (>= 6.0)
Microsoft.Extensions.Configuration (6.0.1)
Microsoft.Extensions.Configuration.Abstractions (>= 6.0)
Microsoft.Extensions.Primitives (>= 6.0)
Microsoft.Extensions.Configuration.Abstractions (6.0)
Microsoft.Extensions.Primitives (>= 6.0)
Microsoft.Extensions.Configuration.Binder (6.0)
Microsoft.Extensions.Configuration.Abstractions (>= 6.0)
Microsoft.Extensions.DependencyInjection (6.0.1)
Microsoft.Bcl.AsyncInterfaces (>= 6.0) - restriction: || (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netstandard2.1)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netstandard2.1)) (== netstandard2.0)
Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0)
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netstandard2.1)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netstandard2.1)) (== netstandard2.0)
Microsoft.Extensions.DependencyInjection.Abstractions (6.0)
Microsoft.Bcl.AsyncInterfaces (>= 6.0) - restriction: || (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netstandard2.1)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netstandard2.1)) (== netstandard2.0)
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netstandard2.1)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netstandard2.1)) (== netstandard2.0)
Expand All @@ -174,13 +202,35 @@ NUGET
System.Runtime.CompilerServices.Unsafe (>= 6.0)
System.Text.Encodings.Web (>= 6.0)
System.Text.Json (>= 6.0)
Microsoft.Extensions.Logging (6.0)
Microsoft.Bcl.AsyncInterfaces (>= 6.0) - restriction: || (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netstandard2.1)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netstandard2.1)) (== netstandard2.0)
Microsoft.Extensions.DependencyInjection (>= 6.0)
Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0)
Microsoft.Extensions.Logging.Abstractions (>= 6.0)
Microsoft.Extensions.Options (>= 6.0)
System.Diagnostics.DiagnosticSource (>= 6.0)
Microsoft.Extensions.Logging.Abstractions (6.0.2)
System.Buffers (>= 4.5.1) - restriction: || (&& (== net6.0) (>= net461)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
System.Memory (>= 4.5.4) - restriction: || (&& (== net6.0) (>= net461)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< net6.0)) (== netstandard2.0)
Microsoft.Extensions.Logging.Configuration (6.0)
Microsoft.Extensions.Configuration (>= 6.0)
Microsoft.Extensions.Configuration.Abstractions (>= 6.0)
Microsoft.Extensions.Configuration.Binder (>= 6.0)
Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0)
Microsoft.Extensions.Logging (>= 6.0)
Microsoft.Extensions.Logging.Abstractions (>= 6.0)
Microsoft.Extensions.Options (>= 6.0)
Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0)
Microsoft.Extensions.Options (6.0)
Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0)
Microsoft.Extensions.Primitives (>= 6.0)
System.ComponentModel.Annotations (>= 5.0) - restriction: || (&& (== net6.0) (< netstandard2.1)) (&& (== net7.0) (< netstandard2.1)) (== netstandard2.0)
Microsoft.Extensions.Options.ConfigurationExtensions (6.0)
Microsoft.Extensions.Configuration.Abstractions (>= 6.0)
Microsoft.Extensions.Configuration.Binder (>= 6.0)
Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0)
Microsoft.Extensions.Options (>= 6.0)
Microsoft.Extensions.Primitives (>= 6.0)
Microsoft.Extensions.Primitives (6.0)
System.Memory (>= 4.5.4) - restriction: || (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netcoreapp3.1)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp3.1)) (== netstandard2.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0)
Expand Down Expand Up @@ -233,6 +283,20 @@ NUGET
System.Runtime.CompilerServices.Unsafe (>= 5.0)
Newtonsoft.Json (13.0.2)
NuGet.Frameworks (6.3) - copy_local: false
OpenTelemetry (1.3.2)
Microsoft.Extensions.Logging (>= 3.1)
Microsoft.Extensions.Logging.Configuration (>= 3.1)
OpenTelemetry.Api (>= 1.3.2)
System.Collections.Immutable (>= 1.4)
System.Reflection.Emit.Lightweight (>= 4.7)
OpenTelemetry.Api (1.3.2)
System.Diagnostics.DiagnosticSource (>= 6.0 < 8.0)
System.Reflection.Emit.Lightweight (>= 4.7)
OpenTelemetry.Exporter.OpenTelemetryProtocol (1.3.2)
Google.Protobuf (>= 3.19.4 < 4.0)
Grpc (>= 2.44 < 3.0) - restriction: || (&& (== net6.0) (>= net462)) (&& (== net6.0) (< netstandard2.1)) (&& (== net7.0) (>= net462)) (&& (== net7.0) (< netstandard2.1)) (== netstandard2.0)
Grpc.Net.Client (>= 2.43 < 3.0) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= netstandard2.1))
OpenTelemetry (>= 1.3.2)
SemanticVersioning (2.0.2)
Serilog (2.11)
Serilog.Sinks.Async (1.5)
Expand Down Expand Up @@ -279,7 +343,7 @@ NUGET
System.Numerics.Vectors (>= 4.4) - restriction: || (&& (== net6.0) (< netcoreapp2.0)) (&& (== net7.0) (< netcoreapp2.0)) (== netstandard2.0)
System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (&& (== net6.0) (>= monotouch)) (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netcoreapp2.0)) (&& (== net6.0) (< netcoreapp2.1)) (&& (== net6.0) (< netstandard1.1)) (&& (== net6.0) (< netstandard2.0)) (&& (== net6.0) (>= uap10.1)) (&& (== net6.0) (>= xamarinios)) (&& (== net6.0) (>= xamarinmac)) (&& (== net6.0) (>= xamarintvos)) (&& (== net6.0) (>= xamarinwatchos)) (&& (== net7.0) (>= monotouch)) (&& (== net7.0) (>= net461)) (&& (== net7.0) (< netcoreapp2.0)) (&& (== net7.0) (< netcoreapp2.1)) (&& (== net7.0) (< netstandard1.1)) (&& (== net7.0) (< netstandard2.0)) (&& (== net7.0) (>= uap10.1)) (&& (== net7.0) (>= xamarinios)) (&& (== net7.0) (>= xamarinmac)) (&& (== net7.0) (>= xamarintvos)) (&& (== net7.0) (>= xamarinwatchos)) (== netstandard2.0)
System.Numerics.Vectors (4.5) - restriction: || (&& (== net6.0) (< netcoreapp2.0)) (&& (== net7.0) (< netcoreapp2.0)) (== netstandard2.0)
System.Reactive (5.0) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net5.0))
System.Reactive (5.0) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= net6.0))
System.Reflection.Emit (4.7)
System.Reflection.Emit.ILGeneration (>= 4.7) - restriction: || (&& (== net6.0) (< netcoreapp2.0) (< netstandard2.1)) (&& (== net6.0) (< netstandard1.1)) (&& (== net6.0) (< netstandard2.0)) (&& (== net6.0) (>= uap10.1)) (&& (== net7.0) (< netcoreapp2.0) (< netstandard2.1)) (&& (== net7.0) (< netstandard1.1)) (&& (== net7.0) (< netstandard2.0)) (&& (== net7.0) (>= uap10.1)) (== netstandard2.0)
System.Reflection.Emit.ILGeneration (4.7) - restriction: || (&& (== net6.0) (< netcoreapp2.0) (< netstandard2.1)) (&& (== net6.0) (< netstandard1.1)) (&& (== net6.0) (< netstandard2.0)) (&& (== net6.0) (>= uap10.1)) (&& (== net7.0) (< netcoreapp2.0) (< netstandard2.1)) (&& (== net7.0) (< netstandard1.1)) (&& (== net7.0) (< netstandard2.0)) (&& (== net7.0) (>= uap10.1)) (== netstandard2.0)
Expand Down Expand Up @@ -327,7 +391,9 @@ NUGET
System.Collections.Immutable (>= 6.0) - restriction: || (== net6.0) (== net7.0) (&& (== netstandard2.0) (>= netcoreapp3.1))
GITHUB
remote: TheAngryByrd/FsLibLog
src/FsLibLog/FsLibLog.fs (f81cba440bf0476bb4e2262b57a067a0d6ab78a7)
src/FsLibLog/FsLibLog.fs (64f118ae8df2f2944ef69758052cb3b148b87e79)
remote: TheAngryByrd/FsOpenTelemetry
src/FsOpenTelemetry/FsOpenTelemetry.fs (fb24e8d4dc8ad14187b9b4631854fc8f17fb244d)
GROUP Build
STORAGE: NONE
RESTRICTION: || (== net6.0) (== net7.0)
Expand Down
74 changes: 74 additions & 0 deletions src/FsAutoComplete.Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ open FSharp.Compiler.CodeAnalysis
open FSharp.UMX
open FSharp.Compiler.Symbols


/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
let dispose (d: #IDisposable) = d.Dispose()

/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.</summary>
/// <returns>A task that represents the asynchronous dispose operation.</returns>
let disposeAsync (d: #IAsyncDisposable) = d.DisposeAsync()

module Map =
/// Combine two maps of identical types by starting with the first map and overlaying the second one.
/// Because map updates shadow, any keys in the second map will have priority.
Expand Down Expand Up @@ -148,6 +156,7 @@ let projectOptionsToParseOptions (checkOptions: FSharpProjectOptions) =
{ FSharpParsingOptions.Default with
SourceFiles = files }


[<RequireQualifiedAccess>]
module Option =

Expand Down Expand Up @@ -822,3 +831,68 @@ type FSharpSymbol with
| :? FSharpStaticParameter as s -> s.DeclarationLocation
| :? FSharpParameter as p -> p.DeclarationLocation
| _ -> failwith $"cannot fetch DefinitionRange for unknown FSharpSymbol subtype {x.GetType().FullName}"

module Tracing =

open System.Diagnostics
open FsOpenTelemetry
open StreamJsonRpc

module SemanticConventions =

module FCS =
[<Literal>]
let fileName = "fileName"

[<Literal>]
let project = "project"

[<Literal>]
let qualifiedNameOfFile = "qualifiedNameOfFile"

[<Literal>]
let userOpName = "userOpName"

[<Literal>]
let fsac_sourceCodePath = "fsac.sourceCodePath"

[<Literal>]
let projectFilePath = "fsac.projectFilePath"

[<Literal>]
let serviceName = "FsAutoComplete"

[<Literal>]
let fscServiceName = "fsc"

let fsacActivitySource = new ActivitySource(serviceName, Version.info().Version)

type StreamJsonRpcTracingStrategy(activitySource: ActivitySource) =
interface IActivityTracingStrategy with
member this.ApplyInboundActivity(request: Protocol.JsonRpcRequest) : IDisposable =

let activity = activitySource.StartActivity(request.Method)

activity
.SetTagSafe("rpc.system", "jsonrpc")
.SetTagSafe("rpc.jsonrpc.argumentNames", String.Join(',', request.ArgumentNames))
.SetTagSafe("rpc.jsonrpc.is_notification", request.IsNotification)
.SetTagSafe("rpc.jsonrpc.is_response_expected", request.IsResponseExpected)
.SetTagSafe("rpc.jsonrpc.version", request.Version)
.SetTagSafe("rpc.jsonrpc.request_id", request.RequestId)
.SetTagSafe("rpc.method", request.Method)
|> ignore

activity.TraceStateString <- request.TraceState

if request.TraceParent <> null then
activity.SetParentId(request.TraceParent) |> ignore

activity

member this.ApplyOutboundActivity(request: Protocol.JsonRpcRequest) : unit =
if Activity.Current <> null && Activity.Current.IdFormat = ActivityIdFormat.W3C then
request.TraceParent <- Activity.Current.Id
request.TraceState <- Activity.Current.TraceStateString

()
Loading