[][src]Trait envoy_sdk::extension::access_logger::AccessLogger

pub trait AccessLogger {
    fn name() -> &'static str
    where
        Self: Sized
; fn on_configure(
        &mut self,
        _config: ByteString,
        _ops: &dyn ConfigureOps
    ) -> Result<ConfigStatus> { ... }
fn on_log(&mut self, _ops: &dyn LogOps) -> Result<()> { ... }
fn on_drain(&mut self) -> Result<DrainStatus> { ... }
fn on_http_call_response(
        &mut self,
        _request_id: HttpClientRequestHandle,
        _num_headers: usize,
        _body_size: usize,
        _num_trailers: usize,
        _http_client_ops: &dyn HttpClientResponseOps
    ) -> Result<()> { ... } }

An interface of the Envoy Access Logger extension.

In contrast to HttpFilter and NetworkFilter that only operate on a single HTTP stream and TCP connection respectively, Access Logger operates on multiple HTTP streams or TCP connections.

Examples

Basic AccessLogger:

use envoy::extension::{AccessLogger, Result};
use envoy::extension::access_logger::LogOps;
use envoy::host::{ByteString, log};

/// My very own `AccessLogger`.
struct MyAccessLogger;

impl AccessLogger for MyAccessLogger {
    fn name() -> &'static str { "my_access_logger" }

    fn on_log(&mut self, ops: &dyn LogOps) -> Result<()> {
        let upstream_address = ops.stream_info().upstream().address()?
            .unwrap_or_else(|| "<unknown>".into());
        log::info!("upstream.address : {}", upstream_address);
        Ok(())
    }    
}

NOTE

This trait MUST NOT panic!

If a logger invocation cannot proceed normally, it should return Result::Err(x). In that case, Envoy SDK will be able to handle the error gracefully.

For comparison, if the extension chooses to panic, this will, at best, affect all ongoing HTTP requests / TCP connections handled by that extension, and, at worst, will crash Envoy entirely (as of July 2020).

Required methods

fn name() -> &'static str where
    Self: Sized

Returns a name the extension should be referred to in Envoy configuration.

Loading content...

Provided methods

fn on_configure(
    &mut self,
    _config: ByteString,
    _ops: &dyn ConfigureOps
) -> Result<ConfigStatus>

Called when Access Logger is being (re-)configured.

Arguments

  • _config - configuration.
  • _ops - a trait object through which Access Logger can access its configuration.

Return value

ConfigStatus telling Envoy whether configuration has been successfully applied.

fn on_log(&mut self, _ops: &dyn LogOps) -> Result<()>

Called when HTTP request or TCP connection is complete.

Arguments

  • ops - a trait object through which Access Logger can access data of the HTTP stream or TCP connection that is being logged.

fn on_drain(&mut self) -> Result<DrainStatus>

Called when Access Logger is about to be destroyed.

Return value

DrainStatus telling Envoy whether Access Logger has already been drained and can be now removed safely.

fn on_http_call_response(
    &mut self,
    _request_id: HttpClientRequestHandle,
    _num_headers: usize,
    _body_size: usize,
    _num_trailers: usize,
    _http_client_ops: &dyn HttpClientResponseOps
) -> Result<()>

Called when the async HTTP request made through Envoy HTTP Client API is complete.

Arguments

  • request_id - opaque identifier of the request that is now complete.
  • num_headers - number of headers in the response.
  • body_size - size of the response body.
  • num_trailers - number of tarilers in the response.
  • http_client_ops - a trait object through which Access Logger can access data of the response received by HttpClient, including headers, body and trailers.
Loading content...

Implementors

Loading content...