Skip to content

Commit

Permalink
adds JsonRpc tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Feb 21, 2023
1 parent 94281c3 commit ac2d097
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/FsAutoComplete.Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ module Tracing =

open System.Diagnostics
open FsOpenTelemetry
open StreamJsonRpc

module SemanticConventions =
[<Literal>]
Expand All @@ -845,3 +846,29 @@ module Tracing =
let serviceName = "FsAutoComplete"

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

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

let a = activitySource.StartActivity(request.Method)
a
.SetTagSafe("rpc.system", "jsonrpc")
.SetTagSafe("rpc.jsonrpc.argumentNames", String.Join(',', request.ArgumentNames))
.SetTagSafe("rpc.jsonrpc.isNotification", request.IsNotification)
.SetTagSafe("rpc.jsonrpc.IsResponseExpected", request.IsResponseExpected)
.SetTagSafe("rpc.jsonrpc.version", request.Version)
.SetTagSafe("rpc.jsonrpc.request_id", request.RequestId)
.SetTagSafe("rpc.method", request.Method)
|> ignore

a.TraceStateString <- request.TraceState
if request.TraceParent <> null then
a.SetParentId(request.TraceParent) |> ignore
a

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
()
5 changes: 3 additions & 2 deletions src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4426,12 +4426,13 @@ module AdaptiveFSharpLspServer =
None
| _ -> None

{ new JsonRpc(handler) with
let strategy = StreamJsonRpcTracingStrategy(Tracing.fsacActivitySource)

{ new JsonRpc(handler, ActivityTracingStrategy = strategy) with
member this.IsFatalException(ex: Exception) =
match ex with
| HandleableException -> false
| _ -> true }

let startCore toolsPath workspaceLoaderFactory =
use input = Console.OpenStandardInput()
use output = Console.OpenStandardOutput()
Expand Down

0 comments on commit ac2d097

Please sign in to comment.