Skip to content

Commit 83864a5

Browse files
authored
Azure Functions (Isolated Worker/Out-of-Process) support (#2346)
1 parent 476f1c9 commit 83864a5

24 files changed

+604
-15
lines changed

CHANGELOG.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
### Features
66

7-
- Remove authority from URLs sent to Sentry ([#2365](https://github.com/getsentry/sentry-dotnet/pull/2365))
7+
- Azure Functions (Isolated Worker/Out-of-Process) support ([#2346](https://github.com/getsentry/sentry-dotnet/pull/2346))
8+
- Initial `beta.1` release. Please give it a try and let us know how it goes!
9+
- Documentation is TBD. For now, see `/samples/Sentry.Samples.AzureFunctions.Worker`.
10+
811
- Add `Hint` support ([#2351](https://github.com/getsentry/sentry-dotnet/pull/2351))
912
- Currently, this allows you to manipulate attachments in the various "before" event delegates.
1013
- Hints can also be used in event and transaction processors by implementing `ISentryEventProcessorWithHint` or `ISentryTransactionProcessorWithHint`, instead of `ISentryEventProcessor` or `ISentryTransactionProcessor`.
@@ -13,14 +16,16 @@
1316
- Allow setting the active span on the scope ([#2364](https://github.com/getsentry/sentry-dotnet/pull/2364))
1417
- Note: Obsoletes the `Scope.GetSpan` method in favor of a `Scope.Span` property (which now has a setter as well).
1518

19+
- Remove authority from URLs sent to Sentry ([#2365](https://github.com/getsentry/sentry-dotnet/pull/2365))
1620
- Add tag filters to `SentryOptions` ([#2367](https://github.com/getsentry/sentry-dotnet/pull/2367))
1721

1822
### Fixes
1923

2024
- Fix `EnableTracing` option conflict with `TracesSampleRate` ([#2368](https://github.com/getsentry/sentry-dotnet/pull/2368))
21-
- NOTE: This is a potentially breaking change, as the `TracesSampleRate` property has been made nullable.
22-
Though extremely uncommon, if you are _retrieving_ the `TracesSampleRate` property for some reason, you will need to account for nulls.
23-
However, there is no change to the behavior or _typical_ usage of either of these properties.
25+
- NOTE: This is a potentially breaking change, as the `TracesSampleRate` property has been made nullable.
26+
Though extremely uncommon, if you are _retrieving_ the `TracesSampleRate` property for some reason, you will need to account for nulls.
27+
However, there is no change to the behavior or _typical_ usage of either of these properties.
28+
2429
- CachedTransport gracefully handles malformed envelopes during processing ([#2371](https://github.com/getsentry/sentry-dotnet/pull/2371))
2530

2631
### Dependencies

Sentry.sln

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Profiling.Tests", "t
154154
EndProject
155155
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Samples.Console.Profiling", "samples\Sentry.Samples.Console.Profiling\Sentry.Samples.Console.Profiling.csproj", "{0F84C0BB-FDD4-43A9-B594-923EB10C8E3F}"
156156
EndProject
157+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AzureFunctions.Worker", "src\Sentry.AzureFunctions.Worker\Sentry.AzureFunctions.Worker.csproj", "{203C4556-16DE-46CE-9FAF-C93D8B30D04A}"
158+
EndProject
159+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.AzureFunctions.Worker", "samples\Sentry.Samples.AzureFunctions.Worker\Sentry.Samples.AzureFunctions.Worker.csproj", "{243B75FF-1501-4DB7-B933-EE43D960EB90}"
160+
EndProject
161+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AzureFunctions.Worker.Tests", "test\Sentry.AzureFunctions.Worker.Tests\Sentry.AzureFunctions.Worker.Tests.csproj", "{8639DB06-1F74-4890-8974-613305C1B6C5}"
162+
EndProject
157163
Global
158164
GlobalSection(SolutionConfigurationPlatforms) = preSolution
159165
Debug|Any CPU = Debug|Any CPU
@@ -356,6 +362,18 @@ Global
356362
{0F84C0BB-FDD4-43A9-B594-923EB10C8E3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
357363
{0F84C0BB-FDD4-43A9-B594-923EB10C8E3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
358364
{0F84C0BB-FDD4-43A9-B594-923EB10C8E3F}.Release|Any CPU.Build.0 = Release|Any CPU
365+
{203C4556-16DE-46CE-9FAF-C93D8B30D04A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
366+
{203C4556-16DE-46CE-9FAF-C93D8B30D04A}.Debug|Any CPU.Build.0 = Debug|Any CPU
367+
{203C4556-16DE-46CE-9FAF-C93D8B30D04A}.Release|Any CPU.ActiveCfg = Release|Any CPU
368+
{203C4556-16DE-46CE-9FAF-C93D8B30D04A}.Release|Any CPU.Build.0 = Release|Any CPU
369+
{243B75FF-1501-4DB7-B933-EE43D960EB90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
370+
{243B75FF-1501-4DB7-B933-EE43D960EB90}.Debug|Any CPU.Build.0 = Debug|Any CPU
371+
{243B75FF-1501-4DB7-B933-EE43D960EB90}.Release|Any CPU.ActiveCfg = Release|Any CPU
372+
{243B75FF-1501-4DB7-B933-EE43D960EB90}.Release|Any CPU.Build.0 = Release|Any CPU
373+
{8639DB06-1F74-4890-8974-613305C1B6C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
374+
{8639DB06-1F74-4890-8974-613305C1B6C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
375+
{8639DB06-1F74-4890-8974-613305C1B6C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
376+
{8639DB06-1F74-4890-8974-613305C1B6C5}.Release|Any CPU.Build.0 = Release|Any CPU
359377
EndGlobalSection
360378
GlobalSection(SolutionProperties) = preSolution
361379
HideSolutionNode = FALSE
@@ -413,6 +431,9 @@ Global
413431
{BD6CEF44-E05E-4C22-8D2F-0558A93DD2D6} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
414432
{2E750A7C-561D-4959-B967-042755139D84} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
415433
{0F84C0BB-FDD4-43A9-B594-923EB10C8E3F} = {77454495-55EE-4B40-A089-71B9E8F82E89}
434+
{203C4556-16DE-46CE-9FAF-C93D8B30D04A} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
435+
{243B75FF-1501-4DB7-B933-EE43D960EB90} = {77454495-55EE-4B40-A089-71B9E8F82E89}
436+
{8639DB06-1F74-4890-8974-613305C1B6C5} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
416437
EndGlobalSection
417438
GlobalSection(ExtensibilityGlobals) = postSolution
418439
SolutionGuid = {0C652B1A-DF72-4EE5-A98B-194FE2C054F6}

SentryAzureFunctions.slnf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"solution": {
3+
"path": "Sentry.sln",
4+
"projects": [
5+
"samples\\Sentry.Samples.AzureFunctions.Worker\\Sentry.Samples.AzureFunctions.Worker.csproj",
6+
"samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj",
7+
"src\\Sentry.AzureFunctions.Worker\\Sentry.AzureFunctions.Worker.csproj",
8+
"src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj",
9+
"src\\Sentry\\Sentry.csproj",
10+
"test\\Sentry.AzureFunctions.Worker.Tests\\Sentry.AzureFunctions.Worker.Tests.csproj",
11+
"test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj",
12+
"test\\Sentry.Testing\\Sentry.Testing.csproj",
13+
"test\\Sentry.Tests\\Sentry.Tests.csproj"
14+
]
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Sentry.Samples.AzureFunctions.Worker;
2+
3+
internal static class BadApple
4+
{
5+
public static void HttpScenario()
6+
{
7+
throw new Exception("Throwing from HTTP trigger");
8+
}
9+
10+
public static void TimerScenario()
11+
{
12+
throw new Exception("Throwing from Timer trigger");
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.Extensions.Hosting;
2+
using Sentry.AzureFunctions.Worker;
3+
4+
var host = new HostBuilder()
5+
.ConfigureFunctionsWorkerDefaults((host, builder) =>
6+
{
7+
builder.UseSentry(host, options =>
8+
{
9+
options.EnableTracing = true;
10+
// options.Debug = true;
11+
});
12+
})
13+
.Build();
14+
15+
await host.RunAsync();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Net;
2+
using Microsoft.Azure.Functions.Worker;
3+
using Microsoft.Azure.Functions.Worker.Http;
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace Sentry.Samples.AzureFunctions.Worker;
7+
8+
public class SampleHttpTrigger
9+
{
10+
[Function(nameof(SampleHttpTrigger))]
11+
public async Task<HttpResponseData> RunAsync([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, FunctionContext executionContext)
12+
{
13+
var logger = executionContext.GetLogger<SampleHttpTrigger>();
14+
logger.LogInformation("C# HTTP trigger function processed a request");
15+
16+
var response = req.CreateResponse(HttpStatusCode.OK);
17+
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
18+
19+
BadApple.HttpScenario();
20+
21+
await response.WriteStringAsync("Welcome to Azure Functions!");
22+
23+
return response;
24+
25+
}
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Microsoft.Azure.Functions.Worker;
2+
using Microsoft.Extensions.Logging;
3+
4+
namespace Sentry.Samples.AzureFunctions.Worker;
5+
6+
public class SampleTimerTrigger
7+
{
8+
[Function(nameof(SampleTimerTrigger))]
9+
public void Run([TimerTrigger("0 */5 * * * *"/*, RunOnStartup = true*/)] MyInfo myTimer, FunctionContext context)
10+
{
11+
var logger = context.GetLogger("SampleTimerTrigger");
12+
13+
logger.LogInformation("C# Timer trigger function executed at: {Now}", DateTime.Now);
14+
logger.LogInformation("Next timer schedule at: {NextSchedule}", myTimer.ScheduleStatus.Next);
15+
16+
BadApple.TimerScenario();
17+
}
18+
}
19+
20+
public class MyInfo
21+
{
22+
public MyScheduleStatus ScheduleStatus { get; set; }
23+
24+
public bool IsPastDue { get; set; }
25+
}
26+
27+
public class MyScheduleStatus
28+
{
29+
public DateTime Last { get; set; }
30+
31+
public DateTime Next { get; set; }
32+
33+
public DateTime LastUpdated { get; set; }
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
5+
<OutputType>Exe</OutputType>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.13.0" />
10+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
11+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.2.0" />
12+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.10.0" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="host.json" CopyToOutputDirectory="PreserveNewest" />
17+
<None Update="local.settings.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<!-- TODO: Replace with a package reference -->
26+
<ProjectReference Include="..\..\src\Sentry.AzureFunctions.Worker\Sentry.AzureFunctions.Worker.csproj" />
27+
</ItemGroup>
28+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "2.0",
3+
"logging": {
4+
"applicationInsights": {
5+
"samplingSettings": {
6+
"isEnabled": true,
7+
"excludedTypes": "Request"
8+
}
9+
}
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"IsEncrypted": false,
3+
"Values": {
4+
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
5+
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
6+
}
7+
}

0 commit comments

Comments
 (0)