Logs customization doc: SetResourceBuilder (#3043)
This commit is contained in:
parent
d1c34ab235
commit
b6169aae9b
|
|
@ -17,6 +17,7 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using OpenTelemetry.Logs;
|
||||
using OpenTelemetry.Resources;
|
||||
|
||||
public class Program
|
||||
{
|
||||
|
|
@ -26,6 +27,9 @@ public class Program
|
|||
{
|
||||
builder.AddOpenTelemetry(options =>
|
||||
{
|
||||
options.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(
|
||||
serviceName: "MyService",
|
||||
serviceVersion: "1.0.0"));
|
||||
options.AddConsoleExporter();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -30,7 +30,40 @@ TODO
|
|||
|
||||
### SetResourceBuilder
|
||||
|
||||
TODO
|
||||
[Resource](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md)
|
||||
is the immutable representation of the entity producing the telemetry.
|
||||
If no `Resource` is explicitly configured, the default is to use a resource
|
||||
indicating this [Telemetry
|
||||
SDK](https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions#telemetry-sdk).
|
||||
The `SetResourceBuilder` method on `OpenTelemetryLoggerOptions` can be used to
|
||||
set a single `ResourceBuilder`. If `SetResourceBuilder` is called multiple
|
||||
times, only the last is kept. It is not possible to change the resource builder
|
||||
*after* creating the `LoggerFactory`.
|
||||
|
||||
The snippet below shows configuring a custom `ResourceBuilder` to the provider.
|
||||
|
||||
```csharp
|
||||
var loggerFactory = LoggerFactory.Create(builder =>
|
||||
{
|
||||
builder.AddOpenTelemetry(options =>
|
||||
{
|
||||
options.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(
|
||||
serviceName: "MyService",
|
||||
serviceVersion: "1.0.0"
|
||||
));
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
See [Program.cs](Program.cs) for complete example.
|
||||
|
||||
It is also possible to configure the `Resource` by using following
|
||||
environmental variables:
|
||||
|
||||
| Environment variable | Description |
|
||||
| -------------------------- | -------------------------------------------------- |
|
||||
| `OTEL_RESOURCE_ATTRIBUTES` | Key-value pairs to be used as resource attributes. See the [Resource SDK specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable) for more details. |
|
||||
| `OTEL_SERVICE_NAME` | Sets the value of the `service.name` resource attribute. If `service.name` is also provided in `OTEL_RESOURCE_ATTRIBUTES`, then `OTEL_SERVICE_NAME` takes precedence. |
|
||||
|
||||
## Filtering LogLevels
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue