opentelemetry.sdk.resources package¶
This package implements OpenTelemetry Resources:
A Resource is an immutable representation of the entity producing telemetry. For example, a process producing telemetry that is running in a container on Kubernetes has a Pod name, it is in a namespace and possibly is part of a Deployment which also has a name. All three of these attributes can be included in the Resource.
Resource objects are created with Resource.create
, which accepts attributes
(key-values). Resources should NOT be created via constructor, and working with
Resource
objects should only be done via the Resource API methods. Resource
attributes can also be passed at process invocation in the
OTEL_RESOURCE_ATTRIBUTES
environment variable. You should register
your resource with the opentelemetry.sdk.trace.TracerProvider
by passing
them into their constructors. The Resource
passed to a provider is available
to the exporter, which can send on this information as it sees fit.
trace.set_tracer_provider(
TracerProvider(
resource=Resource.create({
"service.name": "shoppingcart",
"service.instance.id": "instance-12",
}),
),
)
print(trace.get_tracer_provider().resource.attributes)
{'telemetry.sdk.language': 'python',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': '0.13.dev0',
'service.name': 'shoppingcart',
'service.instance.id': 'instance-12'}
Note that the OpenTelemetry project documents certain “standard attributes”
that have prescribed semantic meanings, for example service.name
in the
above example.
-
class
opentelemetry.sdk.resources.
Resource
(attributes, schema_url=None)[source]¶ Bases:
object
A Resource is an immutable representation of the entity producing telemetry as Attributes.
-
property
attributes
¶
-
merge
(other)[source]¶ Merges this resource and an updating resource into a new
Resource
.If a key exists on both the old and updating resource, the value of the updating resource will override the old resource value.
The updating resource’s
schema_url
will be used only if the oldschema_url
is empty. Attempting to merge two resources with different, non-empty values forschema_url
will result in an error and return the old resource.
-
property
-
opentelemetry.sdk.resources.
get_aggregated_resources
(detectors, initial_resource=None, timeout=5)[source]¶ Retrieves resources from detectors in the order that they were passed
- Parameters
detectors (
List
[ResourceDetector
]) – List of resources in order of priorityinitial_resource (
Optional
[Resource
]) – Static resource. This has highest prioritytimeout – Number of seconds to wait for each detector to return
- Return type
- Returns