-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve docs on Resources to encourage its usage #5185
Changes from all commits
9637eed
9169f9a
7bcbc8b
1b7b261
55cf6fe
85f165a
b1b581f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -577,14 +577,27 @@ is to use a resource indicating this | |
[Service](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md#service) | ||
and [Telemetry | ||
SDK](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md#telemetry-sdk). | ||
The `ConfigureResource` method on `MeterProviderBuilder` can be used to set a | ||
configure the resource on the provider. When the provider is built, it | ||
automatically builds the final `Resource` from the configured `ResourceBuilder`. | ||
There can only be a single `Resource` associated with a | ||
provider. It is not possible to change the resource builder *after* the provider | ||
is built, by calling the `Build()` method on the `MeterProviderBuilder`. | ||
The `ConfigureResource` method on `MeterProviderBuilder` can be used to | ||
configure the resource on the provider. `ConfigureResource` accepts an `Action` | ||
to configure the `ResourceBuilder`. Multiple calls to `ConfigureResource` can be | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Rephrasing suggestion: "It's safe to call |
||
made. When the provider is built, it builds the final `Resource` combining all | ||
the `ConfigureResource` calls. There can only be a single `Resource` associated | ||
with a provider. It is not possible to change the resource builder *after* the | ||
provider is built, by calling the `Build()` method on the | ||
`MeterProviderBuilder`. | ||
|
||
`ResourceBuilder` offers various methods to construct resource comprising of | ||
multiple attributes from various sources. | ||
attributes from various sources. For example, `AddService()` adds | ||
[Service](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md#service) | ||
resource. `AddAttributes` can be used to add any additional attributes to the | ||
`Resource`. It also allows adding `ResourceDetector`s. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to add a link for the term ResourceDectectors to this doc: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#detecting-resource-information-from-the-environment |
||
|
||
It is recommended to model attributes that are static throughout the lifetime of | ||
the process as Resources, instead of adding them as attributes(tags) on each | ||
measurement. | ||
|
||
Follow [this](../../trace/extending-the-sdk/README.md#resource-detector) document | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh you already have a link to ResourceDetector information here. This should be moved above right after the text: "It also allows adding |
||
to learn about writing custom resource detectors. | ||
|
||
The snippet below shows configuring the `Resource` associated with the provider. | ||
|
||
|
@@ -594,7 +607,12 @@ using OpenTelemetry.Metrics; | |
using OpenTelemetry.Resources; | ||
|
||
using var meterProvider = Sdk.CreateMeterProviderBuilder() | ||
.ConfigureResource(r => r.AddService("MyServiceName")) | ||
.ConfigureResource(r => r.AddAttributes(new List<KeyValuePair<string, object>> | ||
cijothomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
new KeyValuePair<string, object>("static-attribute1", "v1"), | ||
new KeyValuePair<string, object>("static-attribute2", "v2"), | ||
})) | ||
.ConfigureResource(resourceBuilder => resourceBuilder.AddService("service-name")) | ||
.Build(); | ||
``` | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to use a meaningful key instead of generic names. Something like MachineId, ProcessId, Region etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, will steal something from opentelemetry.io example in a subsequent PR.