Skip to main content

OpenTelemetryPlugin

Struct OpenTelemetryPlugin 

Source
pub struct OpenTelemetryPlugin { /* private fields */ }
Expand description

OpenTelemetry tracing plugin.

Sets up OTLP trace export via tracing-opentelemetry. All tracing spans in the application are exported as OpenTelemetry traces.

Depends on TracingPlugin which owns the subscriber.

§Lifecycle

  • build() — builds the OTLP exporter and tracer, and pushes the OTel layer into TracingLayersApi.
  • cleanup() — shuts down the tracer provider, flushing pending spans.

§Example

use polaris_core_plugins::OpenTelemetryPlugin;

OpenTelemetryPlugin::new("http://localhost:4318/v1/traces")
    .with_service_name("my-agent")
    .with_env_filter("polaris=debug,hyper=warn")
    .with_resource_attribute("deployment.environment.name", "production")
    .with_export_header("x-api-key", api_key);

Implementations§

Source§

impl OpenTelemetryPlugin

Source

pub fn new(endpoint: impl Into<String>) -> OpenTelemetryPlugin

Creates a new plugin targeting the given OTLP HTTP endpoint.

§Arguments
  • endpoint - OTLP HTTP endpoint
Source

pub fn with_service_name(self, name: impl Into<String>) -> OpenTelemetryPlugin

Sets the service name reported in traces.

Source

pub fn with_env_filter(self, filter: impl Into<String>) -> OpenTelemetryPlugin

Sets a custom environment filter for OTel span export.

Format: target=level,target=level,...

Source

pub fn with_resource_attribute( self, key: impl Into<String>, value: impl Into<String>, ) -> OpenTelemetryPlugin

Adds an OTel resource attribute to the trace provider.

Resource attributes identify the entity producing telemetry (e.g., deployment environment, service version, host).

use polaris_core_plugins::OpenTelemetryPlugin;

OpenTelemetryPlugin::new("http://localhost:4318/v1/traces")
    .with_resource_attribute("deployment.environment.name", "production")
    .with_resource_attribute("service.version", "1.2.0");
Source

pub fn with_export_header( self, key: impl Into<String>, value: impl Into<String>, ) -> OpenTelemetryPlugin

Adds an HTTP header to OTLP export requests.

use polaris_core_plugins::OpenTelemetryPlugin;

OpenTelemetryPlugin::new("https://api.honeycomb.io/v1/traces")
    .with_export_header("x-api-key", api_key);

Trait Implementations§

Source§

impl Plugin for OpenTelemetryPlugin

Source§

const ID: &'static str = "polaris::otel"

Stable, unique identifier for this plugin type.
Source§

const VERSION: Version

Semantic version of this plugin.
Source§

fn build(&self, server: &mut Server)

Configures the server. Called once when the plugin is added. Read more
Source§

async fn ready(&self, _server: &mut Server)

Called after all plugins have been built and the server is ready to run. Read more
Source§

async fn cleanup(&self, _server: &mut Server)

Called when the server is shutting down. Read more
Source§

fn dependencies(&self) -> Vec<PluginId>

Declares plugins that must be added before this one. Read more
Source§

fn update(&self, _server: &mut Server, _schedule: ScheduleId)

Called when a schedule this plugin registered for is triggered. Read more
Source§

fn tick_schedules(&self) -> Vec<ScheduleId>

Declares which schedules this plugin wants to receive updates on. Read more

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<P> Plugins for P
where P: Plugin,

Source§

fn add_to_server(self, server: &mut Server)

Adds these plugins to the server.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Resource for T
where T: Send + Sync + 'static,

Source§

fn type_name(&self) -> &'static str

Returns the type name for debugging purposes.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ServiceExt for T

Source§

fn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>
where Self: Sized,

Available on crate feature propagate-header only.
Propagate a header from the request to the response. Read more
Source§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

Available on crate feature trace only.
High level tracing that classifies responses using HTTP status codes. Read more
Source§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

Available on crate feature trace only.
High level tracing that classifies responses using gRPC headers. Read more
Source§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Available on crate feature follow-redirect only.
Follow redirect resposes using the Standard policy. Read more
Source§

fn set_request_id<M>( self, header_name: HeaderName, make_request_id: M, ) -> SetRequestId<Self, M>
where Self: Sized, M: MakeRequestId,

Available on crate feature request-id only.
Add request id header and extension. Read more
Source§

fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>
where Self: Sized, M: MakeRequestId,

Available on crate feature request-id only.
Add request id header and extension, using x-request-id as the header name. Read more
Source§

fn propagate_request_id( self, header_name: HeaderName, ) -> PropagateRequestId<Self>
where Self: Sized,

Available on crate feature request-id only.
Propgate request ids from requests to responses. Read more
Source§

fn propagate_x_request_id(self) -> PropagateRequestId<Self>
where Self: Sized,

Available on crate feature request-id only.
Propgate request ids from requests to responses, using x-request-id as the header name. Read more
Source§

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

Source§

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>,

Source§

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
Source§

impl<T> Output for T
where T: Send + Sync + 'static,