[][src]Trait opentelemetry::api::CorrelationContextExt

pub trait CorrelationContextExt {
    fn current_with_correlations<T: IntoIterator<Item = KeyValue>>(
        correlations: T
    ) -> Self;
fn with_correlations<T: IntoIterator<Item = KeyValue>>(
        &self,
        correlations: T
    ) -> Self;
fn with_cleared_correlations(&self) -> Self;
fn correlation_context(&self) -> &CorrelationContext; }

Methods for soring and retrieving correlation data in a context.

Required methods

fn current_with_correlations<T: IntoIterator<Item = KeyValue>>(
    correlations: T
) -> Self

Returns a clone of the current context with the included name / value pairs.

Examples

use opentelemetry::api::{Context, CorrelationContextExt, KeyValue, Value};

let cx = Context::current_with_correlations(vec![KeyValue::new("my-name", "my-value")]);

assert_eq!(
    cx.correlation_context().get("my-name"),
    Some(&Value::String("my-value".to_string())),
)

fn with_correlations<T: IntoIterator<Item = KeyValue>>(
    &self,
    correlations: T
) -> Self

Returns a clone of the given context with the included name / value pairs.

Examples

use opentelemetry::api::{Context, CorrelationContextExt, KeyValue, Value};

let some_context = Context::current();
let cx = some_context.with_correlations(vec![KeyValue::new("my-name", "my-value")]);

assert_eq!(
    cx.correlation_context().get("my-name"),
    Some(&Value::String("my-value".to_string())),
)

fn with_cleared_correlations(&self) -> Self

Returns a clone of the given context with the included name / value pairs.

Examples

use opentelemetry::api::{Context, CorrelationContextExt, KeyValue, Value};

let cx = Context::current().with_cleared_correlations();

assert_eq!(cx.correlation_context().len(), 0);

fn correlation_context(&self) -> &CorrelationContext

Returns a reference to this context's correlation context, or the default empty correlation context if none has been set.

Loading content...

Implementors

impl CorrelationContextExt for Context[src]

Loading content...