Skip to content

Commit

Permalink
Add OTel to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Apr 15, 2024
1 parent b846ac3 commit f83ff26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

[<EntryPoint>]
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}"

Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions test/FsAutoComplete.Tests.Lsp/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f83ff26

Please sign in to comment.