Skip to content

Commit 2fb94e2

Browse files
committed
Show simplified setup of tracing/metrics for CLI app and Aspire
1 parent 7e53398 commit 2fb94e2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,21 @@ using var tracer = Sdk
377377
.Build();
378378
```
379379

380+
For integration from a plain CLI app with Aspire (or whenever an OLTP endpoint is provided as an
381+
environment variable), you can simplify it as:
382+
383+
```csharp
384+
var builder = Host.CreateApplicationBuilder(args);
385+
386+
if (!string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]))
387+
{
388+
builder.Services.AddOpenTelemetry()
389+
.ConfigureResource(x => x.AddService("MyApp"))
390+
.WithTracing(x => x.AddSource("Merq").AddOtlpExporter())
391+
.WithMetrics(x => x.AddMeter("Merq").AddOtlpExporter());
392+
}
393+
```
394+
380395
Collecting traces via [dotnet-trace](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-trace):
381396
382397
```shell

0 commit comments

Comments
 (0)