diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md index 8b8f60c6d62..ccdc6d93d1c 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md @@ -67,7 +67,16 @@ and environment variables. The `OtlpExporterOptions` type setters take precedence over the environment variables. This can be achieved by providing an `Action` delegate to the -`AddOtlpExporter()` method. +`AddOtlpExporter()` method or using `AddOptions()`. + +If additional services from the dependency injection are required, they can be +configured like this: + +```csharp +services.AddOptions().Configure((opts, svc) => { + // ... +}); +``` TODO: Show metrics specific configuration (i.e MetricReaderOptions). diff --git a/src/OpenTelemetry.Extensions.Hosting/README.md b/src/OpenTelemetry.Extensions.Hosting/README.md index 4c2d480a0ec..9dd0ee96f08 100644 --- a/src/OpenTelemetry.Extensions.Hosting/README.md +++ b/src/OpenTelemetry.Extensions.Hosting/README.md @@ -83,6 +83,41 @@ app.Run(); A fully functional example can be found [here](https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/examples/AspNetCore). +### Resources + +To dynamically add resources at startup from the dependency injection you can +provide an `IResourceDetector`. +To make use of it add it to the dependency injection and they you can use the +`ISerivceProvider` add it to OpenTelemetry: + +```csharp +public class MyResourceDetector : IResourceDetector +{ + private readonly IWebHostEnvironment webHostEnvironment; + + public MyResourceDetector(IWebHostEnvironment webHostEnvironment) + { + this.webHostEnvironment = webHostEnvironment; + } + + public Resource Detect() + { + return ResourceBuilder.CreateEmpty() + .AddService(serviceName: this.webHostEnvironment.ApplicationName) + .AddAttributes(new Dictionary { ["host.environment"] = this.webHostEnvironment.EnvironmentName }) + .Build(); + } +} + +services.AddSingleton(); + +services.AddOpenTelemetry() + .ConfigureResource(builder => + builder.AddDetector(sp => sp.GetRequiredService())) + .WithTracing(builder => builder.AddConsoleExporter()) + .WithMetrics(builder => builder.AddConsoleExporter()); +``` + ## Migrating from pre-release versions of OpenTelemetry.Extensions.Hosting Pre-release versions (all versions prior to 1.4.0) of