-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create/update .net and node.js observability docs (#533)
* chore: create/update .net and node.js observability docs * fix broken link
- Loading branch information
Showing
5 changed files
with
145 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
sidebar_position: 1 | ||
sidebar_label: Cache Cheat Sheet | ||
sidebar_class_name: sidebar-item-dotnet | ||
title: Cheat sheet for .NET SDK | ||
description: Get started really quickly coding using the .NET SDK with Momento Cache | ||
--- | ||
|
||
import { SdkExampleCodeBlock } from "@site/src/components/SdkExampleCodeBlock"; | ||
// This import is necessary even though it looks like it's un-used; The inject-example-code-snippet | ||
// plugin will transform instances of SdkExampleCodeBlock to SdkExampleCodeBlockImpl | ||
import { SdkExampleCodeBlockImpl } from "@site/src/components/SdkExampleCodeBlockImpl"; | ||
|
||
# Cheat sheet for .NET with Momento Cache | ||
|
||
If you need to get going quickly with .NET and Momento Cache, this page contains the basic API calls you'll need. [Check the .NET SDK examples](https://github.com/momentohq/client-sdk-dotnet/blob/main/examples) for complete, working examples including build configuration files. | ||
|
||
## Install the Momento client library | ||
|
||
Install the client library in an existing .NET project: | ||
|
||
```cli | ||
dotnet add package Momento.Sdk | ||
``` | ||
|
||
## Set up your API key | ||
|
||
You'll need a Momento API key to authenticate with Momento. You can get one from the [Momento Web Console](https://console.gomomento.com/caches). | ||
Once you have your API key, store it in an environment variable so that the Momento client can consume it: | ||
|
||
``` | ||
export MOMENTO_API_KEY=<your Momento API key here> | ||
``` | ||
|
||
**Note**: it is best practice to put the API key into something like AWS Secret Manager or GCP Secret Manager instead of an environment variable for enhanced security, but we are using one here for demo purposes. | ||
|
||
## Import libraries and create a CacheClient object | ||
[This example file](https://github.com/momentohq/client-sdk-dotnet/blob/main/examples/MomentoUsage/Program.cs) pulls in the necessary imports, reads the API key from an environment variable, and instantiates the CacheClient that is used to interact with a cache. | ||
|
||
## Create a new cache in Momento Cache | ||
Use this function to create a new cache in your account. | ||
|
||
<SdkExampleCodeBlock language={'csharp'} snippetId={'API_CreateCache'} /> | ||
|
||
## List the names of existing caches in your account | ||
A simple list of the names of caches for the account. | ||
|
||
<SdkExampleCodeBlock language={'csharp'} snippetId={'API_ListCaches'} /> | ||
|
||
## Write an item to a cache | ||
A simple example of doing a set operation. In the client.set call, the TTL is optional. If you did pass it in, this would override the default TTL value set with the client connection object. | ||
|
||
<SdkExampleCodeBlock language={'csharp'} snippetId={'API_Set'} /> | ||
|
||
## Read an item from a cache | ||
This is an example of a simple read operation to get an item from a cache. | ||
|
||
<SdkExampleCodeBlock language={'csharp'} snippetId={'API_Get'} /> | ||
|
||
## Running the code | ||
|
||
You can find complete, working examples in the [csharp SDK GitHub repo examples directory](https://github.com/momentohq/client-sdk-dotnet/blob/main/examples). | ||
|
||
:::info | ||
Beyond these basic API calls check out the [API reference page](/cache/develop/api-reference/index.mdx) for more information on the full assortment of Momento API calls. | ||
|
||
Check out this example code for [more advanced calls](https://github.com/momentohq/client-sdk-dotnet/blob/main/examples/MomentoApplication/Program.cs). | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
sidebar_position: 2 | ||
sidebar_label: Observability | ||
sidebar_class_name: sidebar-item-dotnet | ||
title: Observability for .NET SDK | ||
description: Instrument your Momento-enabled .NET code with Logs, Metrics, and Traces | ||
--- | ||
|
||
import { SdkExampleCodeBlock } from "@site/src/components/SdkExampleCodeBlock"; | ||
// This import is necessary even though it looks like it's un-used; The inject-example-code-snippet | ||
// plugin will transform instances of SdkExampleCodeBlock to SdkExampleCodeBlockImpl | ||
import { SdkExampleCodeBlockImpl } from "@site/src/components/SdkExampleCodeBlockImpl"; | ||
|
||
# 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](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line) 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](https://github.com/momentohq/client-sdk-dotnet/blob/main/src/Momento.Sdk/Config/Middleware/LoggingMiddleware.cs)). | ||
|
||
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`](https://github.com/momentohq/client-sdk-dotnet/blob/main/src/Momento.Sdk/Config/Middleware/ExperimentalMetricsLoggingMiddleware.cs): 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`](https://github.com/momentohq/client-sdk-dotnet/blob/main/src/Momento.Sdk/Config/Middleware/ExperimentalMetricsCsvMiddleware.cs): 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](https://github.com/momentohq/client-sdk-javascript/tree/main/examples/nodejs/lambda-examples/cloudwatch-metrics) 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](@site/static/img/cloudwatch-dashboard.png) | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters