Module telemetry

Module telemetry 

Source
Available on crate features logging or metrics or telemetry or tracing only.
Expand description

Service telemetry.

Rustfoundry provides telemetry functionality for:

  • logging
  • distributed tracing (backed by Jaeger)
  • metrics (backed by Prometheus)
  • memory profiling (backed by jemalloc)
  • monitoring tokio runtimes

The library strives to minimize the bootstrap code required to set up basic telemetry for a service and provide ergonomic API for telemetry-related operations.

§Initialization

In production code telemetry needs to be initialized on the service start up (usually at the begining of the main function) with the init function for it to be collected by the external sinks.

If syscall sandboxing is also being used (see crate::security for more details), telemetry must be initialized prior to syscall sandboxing, since it uses syscalls during initialization that it will not use later.

§Telemetry context

Rustfoundry’ telemetry is designed to not interfere with the production code, so you usually don’t need to carry log handles or tracing spans around. However, it is contextual, allowing different code branches to have different telemetry contexts. For example, in an HTTP service, you may want separate logs for each HTTP request. Contextual log fields are implicitly added to log records and apply only to log records produced for each particular request.

The TelemetryContext structure reflects this concept and contains information about the log and tracing span used in the current code scope. The context doesn’t need to be explicitly created, and if the service doesn’t need separate logs or traces for different code paths, it is a process-wide singleton.

However, in some cases, it may be desirable to have branching of telemetry information. In such cases, new telemetry contexts can be created using the TelemetryContext::with_forked_trace and TelemetryContext::with_forked_log methods. These contexts need to be manually propagated to the destination code branches using methods like TelemetryContext::scope and TelemetryContext::apply.

§Testing

Telemetry is an important part of the functionality for any production-grade services and Rustfoundry provides API for telemetry testing: special testing context can be created with TelemetryContext::test method and the library provides a special with_test_telemetry macro to enable telemetry testing in #[test] and #[tokio::test].

Modules§

loglogging
Logging-related functionality.
metricsmetrics
Metrics-related functionality.
settings
Telemetry settings.
tokio_runtime_metricstokio-runtime-metrics and tokio_unstable and rustfoundry_unstable
Toolkit for monitoring tokio runtimes using the rustfoundry metrics api.
tracingtracing
Distributed tracing-related functionality.

Structs§

MemoryProfilerLinux and memory-profiling
A safe interface for jemalloc’s memory profiling functionality.
TelemetryConfig
Telemetry configuration that is passed to init.
TelemetryContext
Implicit context for logging and tracing.
TelemetryDriver
A future that drives async telemetry functionality and that is returned by crate::telemetry::init.
TelemetryScope
A handle for the scope in which certain TelemetryContext is active.
TelemetryServerRoutetelemetry-server
A telemetry server route descriptor.
TestTelemetryContexttesting
A test telemetry context.
WithTelemetryContext
Wrapper for a future that provides it with TelemetryContext.
WithTelemetryContextLocal
The same as WithTelemetryContext, but for futures that are !Send.

Functions§

init
Initializes service telemetry.

Type Aliases§

TelemetryRouteHandlertelemetry-server
Telemetry route handler.
TelemetryRouteHandlerFuturetelemetry-server
Future returned by TelemetryServerRoute::handler.

Attribute Macros§

with_test_telemetrytesting
A macro that enables telemetry testing in #[test] and #[tokio::test].