Skip to content

Commit 40068a0

Browse files
committed
Add provider to ProcessExit
1 parent d3db9f7 commit 40068a0

4 files changed

Lines changed: 33 additions & 28 deletions

File tree

Expecto.Tests/Expecto.Tests.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
<AssemblyName>Expecto.Tests</AssemblyName>
55
<OutputType>Exe</OutputType>
66
<TargetFramework>net6.0</TargetFramework>
7+
<GenerateProgramFile>false</GenerateProgramFile>
78
</PropertyGroup>
89
<ItemGroup>
910
<Compile Include="Prelude.fs" />
11+
<Compile Include="OpenTelemetry.fs" />
1012
<Compile Include="Tests.fs" />
1113
<Compile Include="SummaryTests.fs" />
1214
<Compile Include="FocusedTests.fs" />
1315
<Compile Include="FsCheckTests.fs" />
1416
<Compile Include="PerformanceTests.fs" />
1517
<Compile Include="Bug341.fs" />
16-
<Compile Include="OpenTelemetry.fs" />
1718
<Compile Include="Main.fs" />
1819
<None Include="paket.references" />
1920
<ProjectReference Include="..\Expecto.Hopac\Expecto.Hopac.fsproj" />

Expecto.Tests/OpenTelemetry.fs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ module OpenTelemetry =
160160
handleFailure span e
161161
)
162162

163-
164-
165163
let addOpenTelemetry_SpanPerTest (config: ExpectoConfig) (activitySource: ActivitySource) (rootTest: Test) : Test =
166164
rootTest
167165
|> Test.toTestCodeList
@@ -172,8 +170,3 @@ module OpenTelemetry =
172170
)
173171
|> Test.fromFlatTests config.joinWith.asString
174172

175-
176-
let addOpenTelemetry_SpanPerTest_WithProvider (config: ExpectoConfig) (activitySource: ActivitySource) (providerFactory : unit -> #IDisposable) (rootTest: Test) : Test =
177-
let provider = providerFactory()
178-
AppDomain.CurrentDomain.ProcessExit.Add(fun _ -> provider.Dispose())
179-
addOpenTelemetry_SpanPerTest config activitySource rootTest

Expecto.Tests/Tests.fs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@ open Expecto
1010
open Expecto.Impl
1111
open Expecto.Logging
1212
open System.Globalization
13+
open OpenTelemetry.Resources
14+
open OpenTelemetry.Trace
15+
open System.Diagnostics
16+
open OpenTelemetry
17+
18+
let serviceName = "Expecto.Tests"
19+
20+
let source = new ActivitySource(serviceName)
21+
22+
let resourceBuilder () =
23+
ResourceBuilder
24+
.CreateDefault()
25+
.AddService(serviceName = serviceName)
26+
27+
let traceProvider () =
28+
Sdk
29+
.CreateTracerProviderBuilder()
30+
.AddSource(serviceName)
31+
.SetResourceBuilder(resourceBuilder ())
32+
.AddOtlpExporter()
33+
.Build()
34+
do
35+
let provider = traceProvider()
36+
AppDomain.CurrentDomain.ProcessExit.Add(fun _ -> provider.Dispose())
37+
1338

1439
module Dummy =
1540

@@ -1830,6 +1855,7 @@ let cancel =
18301855
)
18311856
]
18321857

1858+
18331859
[<Tests>]
18341860
let theory =
18351861
testList "theory testing" [
@@ -1857,24 +1883,8 @@ let theory =
18571883
}
18581884
]
18591885
]
1886+
|> addOpenTelemetry_SpanPerTest ExpectoConfig.defaultConfig source
18601887

1861-
open OpenTelemetry.Resources
1862-
open OpenTelemetry.Trace
1863-
1864-
let serviceName = "Expecto.Tests"
1865-
1866-
let resourceBuilder () =
1867-
ResourceBuilder
1868-
.CreateDefault()
1869-
.AddService(serviceName = serviceName)
1870-
1871-
let traceProvider () =
1872-
Sdk
1873-
.CreateTracerProviderBuilder()
1874-
.AddSource(serviceName)
1875-
.SetResourceBuilder(resourceBuilder ())
1876-
.AddOtlpExporter()
1877-
.Build()
18781888

18791889

18801890
[<Tests>]
@@ -1889,6 +1899,5 @@ let fixtures =
18891899
}
18901900
]
18911901

1892-
let source = new ActivitySource(serviceName)
18931902
testList "MyTests" tests
1894-
|> addOpenTelemetry_SpanPerTest_WithProvider ExpectoConfig.defaultConfig (source) (fun () -> traceProvider ())
1903+
|> addOpenTelemetry_SpanPerTest ExpectoConfig.defaultConfig source

Expecto.Tests/paket.references

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
FsCheck
2-
OpenTelemetry.Exporter.OpenTelemetryProtocol
2+
OpenTelemetry.Exporter.OpenTelemetryProtocol
3+
YoloDev.Expecto.TestSdk
4+
Microsoft.NET.Test.Sdk

0 commit comments

Comments
 (0)