From 6d81fe4b59b0e79308a6eecea20a0116f9876af2 Mon Sep 17 00:00:00 2001 From: Cromefire_ Date: Thu, 30 Mar 2023 19:36:09 +0200 Subject: [PATCH] Added dependency injection to sample --- src/OpenTelemetry.Extensions.Hosting/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Extensions.Hosting/README.md b/src/OpenTelemetry.Extensions.Hosting/README.md index 2f8757b616c..9dd0ee96f08 100644 --- a/src/OpenTelemetry.Extensions.Hosting/README.md +++ b/src/OpenTelemetry.Extensions.Hosting/README.md @@ -93,10 +93,18 @@ To make use of it add it to the dependency injection and they you can use the ```csharp public class MyResourceDetector : IResourceDetector { + private readonly IWebHostEnvironment webHostEnvironment; + + public MyResourceDetector(IWebHostEnvironment webHostEnvironment) + { + this.webHostEnvironment = webHostEnvironment; + } + public Resource Detect() { return ResourceBuilder.CreateEmpty() - .AddService("your service name") + .AddService(serviceName: this.webHostEnvironment.ApplicationName) + .AddAttributes(new Dictionary { ["host.environment"] = this.webHostEnvironment.EnvironmentName }) .Build(); } }