Skip to content

Commit 0918bc1

Browse files
committed
Better OTel and use Pull Diagnostics
1 parent e65df5d commit 0918bc1

File tree

14 files changed

+617
-166
lines changed

14 files changed

+617
-166
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: 31 additions & 17 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

@@ -108,6 +111,8 @@ type FSharpCompilerServiceChecker
108111
?transparentCompilerCacheSizes = cacheSize
109112
)
110113

114+
let thisType = typeof<FSharpCompilerServiceChecker>
115+
111116
let entityCache = EntityCache()
112117

113118
// FCS can't seem to handle parallel project restores for script files
@@ -337,15 +342,20 @@ type FSharpCompilerServiceChecker
337342
}
338343

339344
member self.GetProjectSnapshotsFromScript(file: string<LocalPath>, source, tfm: FSIRefs.TFM) =
340-
async {
341-
try
342-
do! scriptLocker.WaitAsync() |> Async.AwaitTask
345+
asyncEx {
346+
let tags =
347+
seq {
348+
yield "file", box file
349+
yield "tfm", tfm
350+
}
351+
352+
use _trace = Tracing.fsacActivitySource.StartActivityForType(thisType, tags = tags)
353+
use! _l = scriptLocker.LockAsync()
354+
355+
match tfm with
356+
| FSIRefs.TFM.NetFx -> return! self.GetNetFxScriptSnapshot(file, source)
357+
| FSIRefs.TFM.NetCore -> return! self.GetNetCoreScriptSnapshot(file, source)
343358

344-
match tfm with
345-
| FSIRefs.TFM.NetFx -> return! self.GetNetFxScriptSnapshot(file, source)
346-
| FSIRefs.TFM.NetCore -> return! self.GetNetCoreScriptSnapshot(file, source)
347-
finally
348-
scriptLocker.Release() |> ignore<int>
349359
}
350360

351361

@@ -418,15 +428,19 @@ type FSharpCompilerServiceChecker
418428
}
419429

420430
member self.GetProjectOptionsFromScript(file: string<LocalPath>, source, tfm) =
421-
async {
422-
try
423-
do! scriptLocker.WaitAsync() |> Async.AwaitTask
424-
425-
match tfm with
426-
| FSIRefs.TFM.NetFx -> return! self.GetNetFxScriptOptions(file, source)
427-
| FSIRefs.TFM.NetCore -> return! self.GetNetCoreScriptOptions(file, source)
428-
finally
429-
scriptLocker.Release() |> ignore<int>
431+
asyncEx {
432+
let tags =
433+
seq {
434+
yield "file", box file
435+
yield "tfm", box tfm
436+
}
437+
438+
use _trace = Tracing.fsacActivitySource.StartActivityForType(thisType, tags = tags)
439+
use! _l = scriptLocker.LockAsync()
440+
441+
match tfm with
442+
| FSIRefs.TFM.NetFx -> return! self.GetNetFxScriptOptions(file, source)
443+
| FSIRefs.TFM.NetCore -> return! self.GetNetCoreScriptOptions(file, source)
430444
}
431445

432446

src/FsAutoComplete.Logging/FsOpenTelemetry.fs

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

575575
let tags =
576576
ActivityTagsCollection(
577-
[ yield KeyValuePair(SemanticConventions.General.Exceptions.exception_escaped, box escaped)
577+
seq {
578+
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_escaped, box escaped)
578579
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_type, box errorType)
579580

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

583-
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_message, box errorMessage) ]
584+
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_message, box errorMessage)
585+
}
584586
)
585587

586588
ActivityEvent(SemanticConventions.General.Exceptions.exception_, tags = tags)
@@ -602,11 +604,12 @@ type ActivityExtensions =
602604

603605
let tags =
604606
ActivityTagsCollection(
605-
[ yield KeyValuePair(SemanticConventions.General.Exceptions.exception_escaped, box escaped)
607+
seq {
608+
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_escaped, box escaped)
606609
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_type, box exceptionType)
607610
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_stacktrace, box exceptionStackTrace)
608611
if not <| String.IsNullOrEmpty(exceptionMessage) then
609-
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_message, box exceptionMessage) ]
612+
yield KeyValuePair(SemanticConventions.General.Exceptions.exception_message, box exceptionMessage) }
610613
)
611614

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

src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ module CallHierarchyHelpers =
166166
}
167167

168168
open CallHierarchyHelpers
169+
// type DiagnosticType =
170+
// | FSharp of FSharp.Compiler.Diagnostics.FSharpDiagnostic
171+
// | Analyzer of FSharp.Analyzers.SDK.Message
172+
// | UnusedOpen
169173

170174
type AdaptiveFSharpLspServer
171175
(
@@ -2500,7 +2504,38 @@ type AdaptiveFSharpLspServer
25002504

25012505
override x.TextDocumentDeclaration p = x.logUnimplementedRequest p
25022506

2503-
override x.TextDocumentDiagnostic p = x.logUnimplementedRequest p
2507+
override x.TextDocumentDiagnostic p =
2508+
asyncResult {
2509+
let tags = [ "DocumentDiagnosticParams", box p ]
2510+
use trace = fsacActivitySource.StartActivityForType(thisType, tags = tags)
2511+
2512+
try
2513+
logger.info (
2514+
Log.setMessage "TextDocumentDiagnostic Request: {params}"
2515+
>> Log.addContextDestructured "params" p
2516+
)
2517+
2518+
let filePath = p.TextDocument.GetFilePath() |> Utils.normalizePath
2519+
2520+
let! diags = state.GetDiagnostics filePath |> AsyncResult.ofStringErr
2521+
2522+
return
2523+
DocumentDiagnosticReport.C1(
2524+
{ Kind = "full"
2525+
ResultId = None
2526+
Items = diags
2527+
RelatedDocuments = None }
2528+
)
2529+
2530+
with e ->
2531+
trace |> Tracing.recordException e
2532+
2533+
let logCfg =
2534+
Log.setMessage "TextDocumentDiagnostic Request Errored {p}"
2535+
>> Log.addContextDestructured "p" p
2536+
2537+
return! returnException e logCfg
2538+
}
25042539

25052540
override x.TextDocumentLinkedEditingRange p = x.logUnimplementedRequest p
25062541

0 commit comments

Comments
 (0)