Skip to content

Commit 31d2b63

Browse files
authored
Update dotnet code samples with F# (#2566)
1 parent a927821 commit 31d2b63

File tree

30 files changed

+359
-14
lines changed

30 files changed

+359
-14
lines changed

src/components/codeTabs.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const LANGUAGES = {
1212
json: "JSON",
1313
cpp: "C++",
1414
csharp: "C#",
15+
fsharp: "F#",
1516
es6: "JavaScript (ES6)",
1617
yml: "YAML",
1718
yaml: "YAML",

src/includes/before-breadcrumb/dotnet.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,17 @@ SentrySdk.Init(options =>
1010
: breadcrumb;
1111
});
1212
```
13+
14+
```fsharp
15+
open Sentry
16+
17+
SentrySdk.Init (fun options ->
18+
options.BeforeBreadcrumb <- (fun breadcrumb ->
19+
// Ignore breadcrumbs from Spammy logger
20+
if breadcrumb.Category = "Spammy.Logger" then
21+
null
22+
else
23+
breadcrumb
24+
)
25+
)
26+
```

src/includes/breadcrumbs-example/dotnet.mdx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22
using Sentry;
33

44
SentrySdk.AddBreadcrumb(
5-
message: "Authenticated user " + user.email,
5+
message: "Authenticated user " + user.Email,
66
category: "auth",
77
level: BreadcrumbLevel.Info);
88
```
9+
10+
```fsharp
11+
open Sentry
12+
13+
SentrySdk.AddBreadcrumb(
14+
"Authenticated user " + user.Email,
15+
"auth",
16+
null,
17+
null,
18+
BreadcrumbLevel.Info)
19+
```

src/includes/capture-error/dotnet.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ catch (Exception err)
1212
SentrySdk.CaptureException(err);
1313
}
1414
```
15+
16+
```fsharp
17+
try
18+
aFunctionThatMightFail()
19+
with ex ->
20+
SentrySdk.CaptureException(ex) |> ignore
21+
```

src/includes/capture-message/dotnet.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ using Sentry;
33

44
SentrySdk.CaptureMessage("Something went wrong");
55
```
6+
7+
```fsharp
8+
open Sentry
9+
10+
SentrySdk.CaptureMessage("Something went wrong")
11+
```

src/includes/configuration/before-send/dotnet.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ SentrySdk.Init(o =>
1313
};
1414
});
1515
```
16+
17+
```fsharp
18+
open Sentry
19+
20+
SentrySdk.Init (fun o ->
21+
o.BeforeSend <- fun (event ->
22+
// Modify the event here:
23+
event.ServerName <- null // Don't send server names.
24+
event
25+
)
26+
)
27+
```

src/includes/configuration/config-intro/dotnet.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ using (SentrySdk.Init(o =>
1414
// app code here
1515
}
1616
```
17+
18+
```fsharp
19+
open Sentry
20+
21+
use __ = SentrySdk.Init(fun o ->
22+
o.Dsn <- "___PUBLIC_DSN___"
23+
o.MaxBreadcrumbs <- 50
24+
o.Debug <- true
25+
())
26+
27+
// app code here
28+
```

src/includes/configuration/drain-example/dotnet.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ using (SentrySdk.Init(...))
88
}
99
```
1010

11+
```fsharp
12+
use __ = SentrySdk.Init((* ... *))
13+
// App code
14+
```
15+
1116
In case of an unhandled exception that will crash the app, the SDK automatically disposes itself.

src/includes/configure-scope/dotnet.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ SentrySdk.ConfigureScope(scope =>
1212
});
1313
```
1414

15+
```fsharp
16+
open Sentry
17+
18+
SentrySdk.ConfigureScope (fun scope ->
19+
scope.SetTag ("my-tag", "my value")
20+
scope.User <- User (
21+
Id = "42",
22+
Email = "john.doe@example.com"
23+
()))
24+
```
25+
1526
Or when an asynchronous call is required:
1627

1728
```csharp
@@ -20,3 +31,12 @@ await SentrySdk.ConfigureScopeAsync(async scope =>
2031
scope.User = await _context.Users.FindAsync(id);
2132
});
2233
```
34+
35+
```fsharp
36+
// Uses TaskBuilder.fs (https://www.nuget.org/packages/TaskBuilder.fs)
37+
SentrySdk.ConfigureScopeAsync (fun scope ->
38+
task {
39+
let! user = ctx.Users.FindAsync(id)
40+
scope.User <- user
41+
})
42+
```

src/includes/getting-started-config/dotnet.aspnetcore.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ public static IWebHost BuildWebHost(string[] args) =>
99
.UseSentry("___PUBLIC_DSN___");
1010
```
1111

12+
```fsharp
13+
let BuildWebHost args =
14+
WebHost.CreateDefaultBuilder(args)
15+
// Add the following line:
16+
.UseSentry("___PUBLIC_DSN___")
17+
```
18+
1219
ASP.NET Core 3.0:
1320

1421
```csharp
@@ -20,3 +27,12 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
2027
webBuilder.UseSentry("___PUBLIC_DSN___");
2128
});
2229
```
30+
31+
```fsharp
32+
let CreateHostBuilder args =
33+
Host.CreateDefaultBuilder(args)
34+
.ConfigureWebHostDefaults(fun webBuilder ->
35+
// Add the following line:
36+
webBuilder.UseSentry("___PUBLIC_DSN___") |> ignore
37+
)
38+
```

0 commit comments

Comments
 (0)