Skip to content

Commit

Permalink
Adds basic OTel Metric support to fsautocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed May 5, 2024
1 parent dd9381d commit cfd9b9a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ nuget Ionide.LanguageServerProtocol >= 0.4.23
nuget Microsoft.Extensions.Caching.Memory
nuget OpenTelemetry.Api >= 1.3.2
nuget OpenTelemetry.Exporter.OpenTelemetryProtocol >= 1.3.2 # 1.4 bumps to 7.0 versions of System.Diagnostics libs, so can't use it
nuget OpenTelemetry.Instrumentation.Runtime
nuget LinkDotNet.StringBuilder 1.18.0
nuget CommunityToolkit.HighPerformance
nuget System.Security.Cryptography.Pkcs 6.0.4
Expand Down
2 changes: 2 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ NUGET
Grpc (>= 2.44 < 3.0) - restriction: || (&& (== net6.0) (>= net462)) (&& (== net6.0) (< netstandard2.1)) (&& (== net7.0) (>= net462)) (&& (== net7.0) (< netstandard2.1)) (&& (== net8.0) (>= net462)) (&& (== net8.0) (< netstandard2.1)) (== netstandard2.0) (&& (== netstandard2.1) (>= net462))
Grpc.Net.Client (>= 2.43 < 3.0) - restriction: || (== net6.0) (== net7.0) (== net8.0) (&& (== netstandard2.0) (>= netstandard2.1)) (== netstandard2.1)
OpenTelemetry (>= 1.3.2)
OpenTelemetry.Instrumentation.Runtime (1.0)
OpenTelemetry.Api (>= 1.3 < 2.0)
Perfolizer (0.2.1)
System.Memory (>= 4.5.3)
runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.2)
Expand Down
25 changes: 20 additions & 5 deletions src/FsAutoComplete/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ open FsAutoComplete.Lsp
open OpenTelemetry
open OpenTelemetry.Resources
open OpenTelemetry.Trace
open OpenTelemetry.Metrics

module Parser =
open FsAutoComplete.Core
open System.Diagnostics

let mutable tracerProvider = Unchecked.defaultof<_>
let mutable meterProvider = Unchecked.defaultof<_>

[<Struct>]
type Pos = { Line: int; Column: int }
Expand Down Expand Up @@ -194,19 +196,32 @@ module Parser =
let configureOTel =
Invocation.InvocationMiddleware(fun ctx next ->



if ctx.ParseResult.GetValueForOption otelTracingOption then

let serviceName = FsAutoComplete.Utils.Tracing.serviceName
let version = FsAutoComplete.Utils.Version.info().Version

let resourceBuilder =
ResourceBuilder
.CreateDefault()
.AddService(serviceName = serviceName, serviceVersion = version)


meterProvider <-
Sdk
.CreateMeterProviderBuilder()
.AddMeter()
.AddRuntimeInstrumentation()
.SetResourceBuilder(resourceBuilder)
.AddOtlpExporter()
.Build()
tracerProvider <-
Sdk
.CreateTracerProviderBuilder()
.AddSource(serviceName, Tracing.fscServiceName)
.SetResourceBuilder(
ResourceBuilder
.CreateDefault()
.AddService(serviceName = serviceName, serviceVersion = version)
)
.SetResourceBuilder(resourceBuilder)
.AddOtlpExporter()
.Build()

Expand Down
1 change: 1 addition & 0 deletions src/FsAutoComplete/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ System.CommandLine
FSharp.Data.Adaptive
Microsoft.Extensions.Caching.Memory
OpenTelemetry.Exporter.OpenTelemetryProtocol
OpenTelemetry.Instrumentation.Runtime
Microsoft.CodeAnalysis
LinkDotNet.StringBuilder
CommunityToolkit.HighPerformance
Expand Down

0 comments on commit cfd9b9a

Please sign in to comment.