Skip to content

Commit

Permalink
Added dependency injection to sample
Browse files Browse the repository at this point in the history
  • Loading branch information
cromefire committed Mar 30, 2023
1 parent 11a81a3 commit 6d81fe4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/OpenTelemetry.Extensions.Hosting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object> { ["host.environment"] = this.webHostEnvironment.EnvironmentName })
.Build();
}
}
Expand Down

0 comments on commit 6d81fe4

Please sign in to comment.