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

Adds basic OTel Metric support to fsautocomplete #1283

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
26 changes: 21 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,33 @@ 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
Loading