From f83ff26a995367c555926f4ad9c305b884803d26 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Mon, 15 Apr 2024 09:49:29 -0400 Subject: [PATCH] Add OTel to tests --- test/FsAutoComplete.Tests.Lsp/Program.fs | 26 ++++++++++++++++++- .../FsAutoComplete.Tests.Lsp/paket.references | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/test/FsAutoComplete.Tests.Lsp/Program.fs b/test/FsAutoComplete.Tests.Lsp/Program.fs index d3643369b..a1ec4694f 100644 --- a/test/FsAutoComplete.Tests.Lsp/Program.fs +++ b/test/FsAutoComplete.Tests.Lsp/Program.fs @@ -121,9 +121,29 @@ let tests = testList "FSAC" [ SnapshotTests.snapshotTests loaders toolsPath ] +open OpenTelemetry +open OpenTelemetry.Resources +open OpenTelemetry.Trace +open OpenTelemetry.Logs +open OpenTelemetry.Metrics +open System.Diagnostics +open FsAutoComplete.Telemetry [] let main args = + let serviceName = "FsAutoComplete.Tests.Lsp" + use traceProvider = + let version = FsAutoComplete.Utils.Version.info().Version + Sdk + .CreateTracerProviderBuilder() + .AddSource(FsAutoComplete.Utils.Tracing.serviceName, Tracing.fscServiceName, serviceName) + .SetResourceBuilder( + ResourceBuilder + .CreateDefault() + .AddService(serviceName = serviceName, serviceVersion = version) + ) + .AddOtlpExporter() + .Build() let outputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}" @@ -225,12 +245,16 @@ let main args = let fixedUpArgs = args |> Array.except argsToRemove let cts = new CancellationTokenSource(testTimeout) + use activitySource = new ActivitySource(serviceName) let cliArgs = [ CLIArguments.Printer(Expecto.Impl.TestPrinters.summaryWithLocationPrinter defaultConfig.printer) CLIArguments.Verbosity Expecto.Logging.LogLevel.Info CLIArguments.Parallel + CLIArguments.ActivitySource activitySource ] - + // let trace = traceProvider.GetTracer("FsAutoComplete.Tests.Lsp") + // use span = trace.StartActiveSpan("runTests", SpanKind.Internal) + use span = activitySource.StartActivity("runTests") runTestsWithCLIArgsAndCancel cts.Token cliArgs fixedUpArgs tests diff --git a/test/FsAutoComplete.Tests.Lsp/paket.references b/test/FsAutoComplete.Tests.Lsp/paket.references index d01b7b2dc..adb2e8e05 100644 --- a/test/FsAutoComplete.Tests.Lsp/paket.references +++ b/test/FsAutoComplete.Tests.Lsp/paket.references @@ -13,6 +13,7 @@ Serilog Destructurama.FSharp Serilog.Sinks.Async Serilog.Sinks.Console +OpenTelemetry.Exporter.OpenTelemetryProtocol Microsoft.Build copy_local: false Microsoft.Build.Framework copy_local: false