Skip to content

Commit 6d3a406

Browse files
committed
Better OTel and use Pull Diagnostics
1 parent c8546f6 commit 6d3a406

File tree

14 files changed

+615
-184
lines changed

14 files changed

+615
-184
lines changed

docker-compose.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
seq:
3+
profiles:
4+
- seq
5+
image: datalust/seq
6+
ports:
7+
- 5341:80 # http and collection
8+
environment:
9+
- ACCEPT_EULA=Y
10+
# http://localhost:5341
11+
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:5341/ingest/otlp/v1/logs
12+
# OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
13+
# OTEL_EXPORTER_OTLP_HEADERS="X-Seq-ApiKey=your_api_key"
14+
jaeger:
15+
profiles:
16+
- jaeger
17+
image: jaegertracing/all-in-one
18+
ports:
19+
- 6831:6831/udp
20+
- 6832:6832/udp
21+
- 5778:5778
22+
- 16686:16686
23+
- 4317:4317
24+
- 4318:4318
25+
- 14250:14250
26+
- 14268:14268
27+
- 14269:14269
28+
- 9411:9411
29+
environment:
30+
- COLLECTOR_ZIPKIN_HTTP_PORT=9411
31+
- COLLECTOR_OTLP_ENABLED=true
32+
# http://localhost:16686/
33+
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317

src/FsAutoComplete.Core/CompilerServiceInterface.fs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace FsAutoComplete
22

3+
open FsAutoComplete.Utils.Tracing
4+
open FsAutoComplete.Telemetry
35
open System.IO
46
open FSharp.Compiler.CodeAnalysis
57
open Utils
@@ -14,6 +16,7 @@ open System
1416
open FsToolkit.ErrorHandling
1517
open FSharp.Compiler.CodeAnalysis.ProjectSnapshot
1618
open System.Threading
19+
open IcedTasks
1720

1821
type Version = int
1922

@@ -95,6 +98,8 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize, parallelRefe
9598
useTransparentCompiler = useTransparentCompiler
9699
)
97100

101+
let thisType = typeof<FSharpCompilerServiceChecker>
102+
98103
let entityCache = EntityCache()
99104

100105
// FCS can't seem to handle parallel project restores for script files
@@ -323,15 +328,18 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize, parallelRefe
323328
}
324329

325330
member self.GetProjectSnapshotsFromScript(file: string<LocalPath>, source, tfm: FSIRefs.TFM) =
326-
async {
327-
try
328-
do! scriptLocker.WaitAsync() |> Async.AwaitTask
331+
asyncEx {
332+
let tags = seq {
333+
yield "file", box file
334+
yield "tfm", tfm
335+
}
336+
use _trace = Tracing.fsacActivitySource.StartActivityForType(thisType, tags = tags)
337+
use! _l = scriptLocker.LockAsync()
329338

330339
match tfm with
331340
| FSIRefs.TFM.NetFx -> return! self.GetNetFxScriptSnapshot(file, source)
332341
| FSIRefs.TFM.NetCore -> return! self.GetNetCoreScriptSnapshot(file, source)
333-
finally
334-
scriptLocker.Release() |> ignore<int>
342+
335343
}
336344

337345

@@ -404,15 +412,17 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize, parallelRefe
404412
}
405413

406414
member self.GetProjectOptionsFromScript(file: string<LocalPath>, source, tfm) =
407-
async {
408-
try
409-
do! scriptLocker.WaitAsync() |> Async.AwaitTask
415+
asyncEx {
416+
let tags = seq {
417+
yield "file", box file
418+
yield "tfm", box tfm
419+
}
420+
use _trace = Tracing.fsacActivitySource.StartActivityForType(thisType, tags = tags)
421+
use! _l = scriptLocker.LockAsync()
410422

411423
match tfm with
412424
| FSIRefs.TFM.NetFx -> return! self.GetNetFxScriptOptions(file, source)
413425
| FSIRefs.TFM.NetCore -> return! self.GetNetCoreScriptOptions(file, source)
414-
finally
415-
scriptLocker.Release() |> ignore<int>
416426
}
417427

418428

@@ -504,7 +514,9 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize, parallelRefe
504514
.SetSize(1)
505515
.SetSlidingExpiration(TimeSpan.FromMinutes(5.))
506516

507-
return lastCheckResults.Set(filePath, r, ops)
517+
let rw = WeakReference<ParseAndCheckResults>(r)
518+
lastCheckResults.Set(filePath, rw, ops) |> ignore
519+
return r
508520
else
509521
return r
510522
with ex ->
@@ -582,8 +594,11 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize, parallelRefe
582594

583595
checkerLogger.info (Log.setMessage "{opName}" >> Log.addContextDestructured "opName" opName)
584596

585-
match lastCheckResults.TryGetValue<ParseAndCheckResults>(file) with
586-
| (true, v) -> Some v
597+
match lastCheckResults.TryGetValue<WeakReference<ParseAndCheckResults>>(file) with
598+
| (true, v) ->
599+
match v.TryGetTarget() with
600+
| (true, v) -> Some v
601+
| _ -> None
587602
| _ -> None
588603

589604
member _.TryGetRecentCheckResultsForFile(file: string<LocalPath>, snapshot: FSharpProjectSnapshot) =

src/FsAutoComplete.Logging/FsOpenTelemetry.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,15 @@ type ActivityExtensions =
576576

577577
let tags =
578578
ActivityTagsCollection(
579-
[ yield KeyValuePair(SemanticConventions.General.Exceptions.exception_escaped, box escaped)
579+
seq {
580+
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_escaped, box escaped)
580581
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_type, box errorType)
581582

582583
if Option.isSome stacktrace then
583584
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_stacktrace, box stacktrace.Value)
584585

585-
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_message, box errorMessage) ]
586+
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_message, box errorMessage)
587+
}
586588
)
587589

588590
ActivityEvent(SemanticConventions.General.Exceptions.exception_, tags = tags)
@@ -604,11 +606,12 @@ type ActivityExtensions =
604606

605607
let tags =
606608
ActivityTagsCollection(
607-
[ yield KeyValuePair(SemanticConventions.General.Exceptions.exception_escaped, box escaped)
609+
seq {
610+
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_escaped, box escaped)
608611
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_type, box exceptionType)
609612
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_stacktrace, box exceptionStackTrace)
610613
if not <| String.IsNullOrEmpty(exceptionMessage) then
611-
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_message, box exceptionMessage) ]
614+
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_message, box exceptionMessage) }
612615
)
613616

614617
ActivityEvent(SemanticConventions.General.Exceptions.exception_, tags = tags)

src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ module ArrayHelpers =
4848

4949
open ArrayHelpers
5050

51+
// type DiagnosticType =
52+
// | FSharp of FSharp.Compiler.Diagnostics.FSharpDiagnostic
53+
// | Analyzer of FSharp.Analyzers.SDK.Message
54+
// | UnusedOpen
55+
5156
type AdaptiveFSharpLspServer
5257
(
5358
workspaceLoader: IWorkspaceLoader,
@@ -2248,7 +2253,29 @@ type AdaptiveFSharpLspServer
22482253

22492254
override x.TextDocumentDeclaration p = x.logUnimplementedRequest p
22502255

2251-
override x.TextDocumentDiagnostic p = x.logUnimplementedRequest p
2256+
override x.TextDocumentDiagnostic p = asyncResult {
2257+
let tags = [ "DocumentDiagnosticParams", box p ]
2258+
use trace = fsacActivitySource.StartActivityForType(thisType, tags = tags)
2259+
try
2260+
logger.info (
2261+
Log.setMessage "TextDocumentDiagnostic Request: {params}"
2262+
>> Log.addContextDestructured "params" p
2263+
)
2264+
let filePath = p.TextDocument.GetFilePath() |> Utils.normalizePath
2265+
2266+
let! diags = state.GetDiagnostics filePath |> AsyncResult.ofStringErr
2267+
2268+
return DocumentDiagnosticReport.C1 ({ Kind = "full"; ResultId = None; Items = diags; RelatedDocuments = None })
2269+
2270+
with e ->
2271+
trace |> Tracing.recordException e
2272+
2273+
let logCfg =
2274+
Log.setMessage "TextDocumentDiagnostic Request Errored {p}"
2275+
>> Log.addContextDestructured "p" p
2276+
2277+
return! returnException e logCfg
2278+
}
22522279

22532280
override x.TextDocumentLinkedEditingRange p = x.logUnimplementedRequest p
22542281

0 commit comments

Comments
 (0)