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

quick hack to start the dashboard on Ionide startup if otel is requested #1988

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
99 changes: 99 additions & 0 deletions src/Components/OTel.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace Ionide.VSCode.FSharp

module OTel =
open Fable.Import.VSCode.Vscode
open Node.Api
open Node.Base

let private logger =
ConsoleAndOutputChannelLogger(Some "OTel", Level.DEBUG, None, Some Level.DEBUG)

let private settingsString = "FSharp.openTelemetry"
let mutable private isOTelEnabled = false

let mutable private hasDocker = false

let mutable private runningContainerId: string = null

type SpawnResult =
abstract pid: int
abstract output: string[][]
abstract stdout: string
abstract stderr: string
abstract status: int option
abstract signal: string option
abstract error: Error option

let private runCommand command (args: string[]) =
let options =
{| cwd = None
env = None
encoding = "utf8"
shell = true |}

let result =
childProcess.spawnSync (command, ResizeArray args, options) :?> SpawnResult

match result.error with
| Some err ->
logger.Error("Error running command %s: %s", command, err.message)
failwithf "%A" err
| None -> result

let private startContainer () =
let result =
runCommand
"docker"
[| "run"
"-d"
"--rm"
"-it"
"-p"
"18888:18888"
"-p"
"4317:18889"
"mcr.microsoft.com/dotnet/nightly/aspire-dashboard:8.0.0-preview.4" |]

logger.Info("Container started with result %j", result)
runningContainerId <- result.stdout
isOTelEnabled <- true

let enableOTelListener () =
isOTelEnabled <- true

if hasDocker then
startContainer ()
logger.Info("OpenTelemetry listener enabled")
()
else
logger.Warn("OpenTelemetry listener requires Docker to be installed") |> ignore

()

let stopContainer (containerId: string) =
runCommand "docker" [| "stop"; containerId |] |> ignore

let disableOTelListener () =
isOTelEnabled <- false

if hasDocker && not (System.String.IsNullOrEmpty runningContainerId) then
stopContainer runningContainerId |> ignore
logger.Info("OpenTelemetry listener disabled")
()

let detectDocker () =
logger.Info("detecting presence of docker")
hasDocker <- true

let activate (ctx: ExtensionContext) =
detectDocker ()

let settings = workspace.getConfiguration settingsString
let newEnablement = settings.get<bool> ("enabled")

logger.Info("Configuration value is %j", newEnablement)

match isOTelEnabled, newEnablement with
| true, (Some false | None) -> disableOTelListener ()
| false, Some true -> enableOTelListener ()
| _, _ -> ()
1 change: 1 addition & 0 deletions src/Ionide.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="Components/SolutionExplorer.fs" />
<Compile Include="Components/TestExplorer.fs" />
<Compile Include="Components/InlayHints.fs" />
<Compile Include="Components/OTel.fs" />
<Compile Include="fsharp.fs" />
</ItemGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
Expand Down
1 change: 1 addition & 0 deletions src/fsharp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ let activate (context: ExtensionContext) : JS.Promise<Api> =
tryActivate "testExplorer" TestExplorer.activate context
tryActivate "inlayhints" InlayHints.activate context
tryActivate "languageservice" activateLanguageServiceRestart context
tryActivate "otel" OTel.activate context

let buildProject project =
promise {
Expand Down
Loading