Skip to content

Commit 311a1f0

Browse files
committed
Draft of IHostBuilder tabs
1 parent 2e313f7 commit 311a1f0

File tree

2 files changed

+83
-21
lines changed

2 files changed

+83
-21
lines changed

articles/azure-functions/dotnet-isolated-process-guide.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,15 +1381,6 @@ Keep these considerations in mind when using Functions with preview versions of
13811381
[Microsoft.Azure.Functions.Worker]: https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker/
13821382
[Microsoft.Azure.Functions.Worker.Sdk]: https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Sdk/
13831383
1384-
[Aspire.Hosting.Azure.Functions]: https://www.nuget.org/packages/Aspire.Hosting.Azure.Functions
1385-
1386-
[Storage Account Contributor]: ../role-based-access-control/built-in-roles.md#storage-account-contributor
1387-
[Storage Blob Data Contributor]: ../role-based-access-control/built-in-roles.md#storage-blob-data-contributor
1388-
[Storage Queue Data Contributor]: ../role-based-access-control/built-in-roles.md#storage-queue-data-contributor
1389-
[Storage Table Data Contributor]: ../role-based-access-control/built-in-roles.md#storage-table-data-contributor
1390-
[Azure Event Hubs Data Owner]: ../role-based-access-control/built-in-roles.md#azure-event-hubs-data-owner
1391-
[Azure Service Bus Data Owner]: ../role-based-access-control/built-in-roles.md#azure-service-bus-data-owner
1392-
13931384
[HostBuilder]: /dotnet/api/microsoft.extensions.hosting.hostbuilder
13941385
[IHostApplicationBuilder]: /dotnet/api/microsoft.extensions.hosting.ihostapplicationbuilder
13951386
[IHost]: /dotnet/api/microsoft.extensions.hosting.ihost

articles/azure-functions/opentelemetry-howto.md

Lines changed: 83 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ With the Functions host configured to use OpenTelemetry, you should also update
7979

8080
The way that you instrument your application to use OpenTelemetry depends on your target OpenTelemetry endpoint:
8181
::: zone pivot="programming-language-csharp"
82+
Examples in this article assume your app is using `IHostApplicationBuilder`, which is avaible in version 2.x and later version of [Microsoft.Azure.Functions.Worker](/dotnet/api/microsoft.extensions.hosting.ihostapplicationbuilder). For more information, see [Version 2.x](dotnet-isolated-process-guide.md#version-2x) in the C# isolated worker model guide.
83+
8284
1. Run these commands to install the required assemblies in your app:
8385

8486
### [Application Insights](#tab/app-insights)
@@ -100,37 +102,106 @@ The way that you instrument your application to use OpenTelemetry depends on you
100102
101103
1. In your Program.cs project file, add this `using` statement:
102104
103-
### [Application Insights](#tab/app-insights)
105+
### [IHostApplicationBuilder](#tab/ihostapplicationbuilder/app-insights)
104106
105107
```csharp
106108
using Azure.Monitor.OpenTelemetry.Exporter;
107109
```
108-
### [OTLP Exporter](#tab/otlp-export)
110+
111+
### [IHostBuilder](#tab/ihostbuilder/app-insights)
112+
113+
```csharp
114+
using Azure.Monitor.OpenTelemetry.Exporter;
115+
using OpenTelemetry.Trace;
116+
using OpenTelemetry.Metrics;
117+
using OpenTelemetry.Logs;
118+
```
119+
120+
### [IHostApplicationBuilder](#tab/ihostapplicationbuilder/otlp-export)
109121
110122
```csharp
111123
using OpenTelemetry;
112124
```
125+
126+
### [IHostBuilder](#tab/ihostbuilder/otlp-export)
127+
128+
```csharp
129+
using OpenTelemetry.Trace;
130+
using OpenTelemetry.Metrics;
131+
using OpenTelemetry.Logs;
132+
```
133+
113134
---
114135
115-
1. In the `ConfigureServices` delegate, add this service configuration:
136+
1. The way that you configure OpenTelemetry depends if your project startup uses `IHostBuilder` or `IHostApplicationBuilder`, which was introduced in v2.x of the .NET isolated worker model extension.
116137
117-
### [Application Insights](#tab/app-insights)
138+
### [IHostApplicationBuilder](#tab/ihostapplicationbuilder/app-insights)
139+
140+
In *program.cs*, add this line of code after `ConfigureFunctionsWebApplication`:
118141
119142
```csharp
120-
services.AddOpenTelemetry()
121-
.UseAzureMonitorExporter()
122-
.UseFunctionsWorkerDefaults();
143+
builder.Services.AddOpenTelemetry()
144+
.UseAzureMonitorExporter();
123145
```
124-
### [OTLP Exporter](#tab/otlp-export)
146+
147+
### [IHostBuilder](#tab/ihostbuilder/app-insights)
148+
149+
In *program.cs*, add this `ConfigureServices` call in your `HostBuilder` pipeline:
150+
151+
```csharp
152+
.ConfigureServices(s =>
153+
{
154+
s.AddOpenTelemetry()
155+
.WithTracing(builder =>
156+
{
157+
builder.AddAzureMonitorTraceExporter();
158+
})
159+
.WithMetrics(builder =>
160+
{
161+
builder.AddAzureMonitorMetricExporter();
162+
})
163+
.WithLogging(builder =>
164+
{
165+
builder.AddAzureMonitorLogExporter();
166+
});
167+
})
168+
```
169+
170+
### [IHostApplicationBuilder](#tab/ihostapplicationbuilder/otlp-export)
171+
172+
In *program.cs*, add this line of code after `ConfigureFunctionsWebApplication`:
125173
126174
```csharp
127-
services.AddOpenTelemetry()
128-
.UseOtlpExporter()
129-
.UseFunctionsWorkerDefaults();
175+
builder.Services.AddOpenTelemetry()
176+
.UseOtlpExporter();
130177
```
178+
179+
### [IHostBuilder](#tab/ihostbuilder/otlp-export)
180+
181+
In *program.cs*, add this `ConfigureServices` call in your `HostBuilder` pipeline:
182+
183+
```csharp
184+
.ConfigureServices(s =>
185+
{
186+
s.AddOpenTelemetry()
187+
.WithTracing(builder =>
188+
{
189+
builder.AddOtlpExporter();
190+
})
191+
.WithMetrics(builder =>
192+
{
193+
builder.AddOtlpExporter();
194+
})
195+
.WithLogging(builder =>
196+
{
197+
builder.AddOtlpExporter();
198+
});
199+
})
200+
```
201+
131202
---
132203
133-
To export to both OpenTelemetry endpoints, call both `UseAzureMonitor` and `UseOtlpExporter`.
204+
You can export to both OpenTelemetry endpoints.
134205
::: zone-end
135206
::: zone pivot="programming-language-java"
136207
1. Add the required libraries to your app. The way you add libraries depends on whether you deploy using Maven or Kotlin and if you want to also send data to Application Insights.

0 commit comments

Comments
 (0)