Skip to main content

Observability with Momento in .NET

Logging

Our goal for all of the Momento SDKs is to make sure that developers can direct Momento log output to the same destination that they are using for the rest of their application logs; therefore, we aim to be compatible with all of the popular logging frameworks for a given programming language.

The .NET SDK uses the ILoggerFactory and ILogger interfaces so that logs can be written to the desired destination by configuring the appropriate logging providers.

As long as your preferred logger implements the ILogger interface, you can pass the logger into your Momento configuration objects. You can also use your preferred logger in any custom middleware implementation you write (example here).

Once configured, you should see log messages in your logging environment that look like this:

[1685649962168] INFO (CacheClient/4386 on mycomputer.local): Creating Momento CacheClient
[1685649962168] INFO (ControlClient/4386 on mycomputer.local): Creating cache: test-cache

Metrics

Metrics are measurements that provide quantitative information about system performance and behavior. They are numerical values captured and recorded over regular intervals, providing statistical data to aid in understanding the trends and patterns in a system.

For Momento, specifically, you might want to capture client-side metrics on the number of requests made, their duration, request or response size, or failure rates.

The most straightforward way to emit these metrics is to use one of the ExperimentalMetricsMiddleware classes. These classes emit metrics in JSON format:

(Momento: _ExperimentalMetricsLoggingMiddleware):
{
"momento": {
"numActiveRequestsAtStart": 1,
"numActiveRequestsAtFinish": 1,
"requestType": "_GetRequest",
"status": 0,
"startTime": 1697663118489,
"requestBodyTime": 1697663118489,
"endTime": 1697663118492,
"duration": 3,
"requestSize": 32,
"responseSize": 2,
"connectionID": "0"
}
}

The metrics format is currently considered experimental; in a future release, once the format is considered stable, this class will be renamed to remove the Experimental prefix. The two middleware classes available are:

  • ExperimentalMetricsLoggingMiddleware: will emit metrics to your chosen logger. WARNING: depending on your request volume, this middleware will produce a high volume of log output. If you are writing logs directly to local disk, be aware of disk usage and make sure you have log rotation / compression enabled via a tool such as logrotate.
  • ExperimentalMetricsCsvMiddleware: will emit metrics to a CSV file. WARNING: enabling this middleware may have minor performance implications, so enable with caution. Depending on your request volume, the CSV file size may grow quickly, and neither sampling nor file compression / rotation are included at this time.

Log files and CSVs can be analyzed or shared with Momento to diagnose performance issues. You may also direct your logs to an AWS CloudWatch Log Group and create a CloudWatch dashboard to monitor your Momento requests; an example of launching a Momento metrics dashboard and optional example application is available in the Node.js SDK. The example Node.js Lambda and Fargate applications utilize the ExperimentalMetricsLoggingMiddleware class and CloudWatch metric filters to populate a dashboard like the one shown below, but you can deploy just the CloudWatch dashboard and populate the graphs with your own .NET application.

An image of a CloudWatch dashboard with nine graphs populated by Momento metrics