Struct opentelemetry_sdk::Resource

source ·
pub struct Resource { /* private fields */ }
Expand description

An immutable representation of the entity producing telemetry as attributes. Utilizes Arc for efficient sharing and cloning.

Implementations§

source§

impl Resource

source

pub fn empty() -> Self

Creates an empty resource. This is the basic constructor that initializes a resource with no attributes and no schema URL.

source

pub fn new<T: IntoIterator<Item = KeyValue>>(kvs: T) -> Self

Create a new Resource from key value pairs.

Values are de-duplicated by key, and the first key-value pair with a non-empty string value will be retained

source

pub fn from_schema_url<KV, S>(kvs: KV, schema_url: S) -> Self
where KV: IntoIterator<Item = KeyValue>, S: Into<Cow<'static, str>>,

Create a new Resource from a key value pairs and schema url.

Values are de-duplicated by key, and the first key-value pair with a non-empty string value will be retained.

schema_url must be a valid URL using HTTP or HTTPS protocol.

source

pub fn from_detectors( timeout: Duration, detectors: Vec<Box<dyn ResourceDetector>>, ) -> Self

Create a new Resource from resource detectors.

timeout will be applied to each detector.

source

pub fn merge<T: Deref<Target = Self>>(&self, other: T) -> Self

Create a new Resource by combining two resources.

§Key value pairs

Keys from the other resource have priority over keys from this resource, even if the updated value is empty.

§Schema url

If both of the resource are not empty. Schema url is determined by the following rules, in order:

  1. If this resource has a schema url, it will be used.
  2. If this resource does not have a schema url, and the other resource has a schema url, it will be used.
  3. If both resources have a schema url and it’s the same, it will be used.
  4. If both resources have a schema url and it’s different, the schema url will be empty.
  5. If both resources do not have a schema url, the schema url will be empty.
source

pub fn schema_url(&self) -> Option<&str>

Return the schema url of the resource. If the resource does not have a schema url, return None.

source

pub fn len(&self) -> usize

Returns the number of attributes for this resource

source

pub fn is_empty(&self) -> bool

Returns true if the resource contains no attributes.

source

pub fn iter(&self) -> Iter<'_>

Gets an iterator over the attributes of this resource.

source

pub fn get(&self, key: Key) -> Option<Value>

Retrieve the value from resource associate with given key.

Trait Implementations§

source§

impl Clone for Resource

source§

fn clone(&self) -> Resource

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Resource

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Resource

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a> IntoIterator for &'a Resource

§

type Item = (&'a Key, &'a Value)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq for Resource

source§

fn eq(&self, other: &Resource) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Resource

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more