Skip to content

Latest commit

 

History

History
224 lines (153 loc) · 19.3 KB

File metadata and controls

224 lines (153 loc) · 19.3 KB

Monitoring

Monitoring is the ability to gather data and insights on the execution of an application. Users will also be able to inspect the gathered data and determine potential actions to take depending on the data collected.

The Telemetry feature allows users to collect and visualize data of the AWS Advanced NodeJS Wrapper execution at a global level and at a plugin level. You can use this feature to monitor the performance of the wrapper as a whole or within specific plugins with your configurations, and determine whether the wrapper's performance meets your expectations.

Terminology

The AWS Advanced NodeJS Wrapper provides telemetry data through two different forms: Traces and Metrics.

Traces

Traces give an overview of what is happening in a specific section of the execution of an application. A trace is composed of a hierarchical sequence of segments, each of which contain basic information about the execution (e.g. duration), and whether that section was executed successfully.

In the AWS Advanced NodeJS Wrapper, a trace will be generated for every call made to the wrapper. Depending on whether the user application already has a trace open, it may be nested in the open trace or dropped. And then, for each enabled plugin, another segment will be created only for the plugin execution, linked to the call segment.

Traces from the AWS Advanced NodeJS Wrapper are submitted to AWS X-Ray.

Metrics

Metrics are numeric data that was measured and collected through the execution of an application. Metrics can give insight on how many times an action (e.g. failover) has happened, and for actions that may happen multiple times, their success or failure rate (failover, cache hits, etc.), amongst other related information.

The AWS Advanced NodeJS Wrapper will submit metrics data to Amazon CloudWatch.

The list of available metrics for the AWS Advanced NodeJS Wrapper and its plugins is available in the List of Metrics section of this page.

Setting up the AWS Distro for OpenTelemetry Collector (ADOT Collector)

Prerequisites

Before enabling the Telemetry feature, a few setup steps are required to ensure the monitoring data is properly emitted.

  1. Install the telemetry packages for the backend you intend to use. The wrapper does not install them for you, and it pins no version beyond @opentelemetry/api and aws-xray-sdk.

Warning

The wrapper declares @opentelemetry/api and aws-xray-sdk as optional peer dependencies and reads whatever provider your application registers. If the packages for your chosen backend are missing, the wrapper fails on the first connection with A tracing backend could not be found.

For OTLP traces and metrics:

npm install @opentelemetry/api @opentelemetry/sdk-node \
  @opentelemetry/sdk-metrics \
  @opentelemetry/exporter-trace-otlp-grpc @opentelemetry/exporter-metrics-otlp-grpc

For XRAY traces:

npm install aws-xray-sdk

XRAY applies to traces only. If you also want metrics, add the OTLP packages above, since telemetryMetricsBackend has no X-Ray option.

The wrapper imports only @opentelemetry/api on the OTLP path and only aws-xray-sdk on the XRAY path. The remaining packages register the provider and carry the data out. Without a registered provider the wrapper records against a no-op tracer and exports nothing. Drop @opentelemetry/sdk-metrics and @opentelemetry/exporter-metrics-otlp-grpc if you only want traces, or @opentelemetry/exporter-trace-otlp-grpc if you only want metrics.

Note

The example below is written against the 0.22x line of the OpenTelemetry experimental packages, which is what this wrapper is tested against. It also works on 0.300.0, which restructured the SDK and requires Node 22.15.0 or later.

  1. In order to visualize the telemetry data in the AWS Console, make sure you have an IAM user or role with permissions to AWS X-Ray and Amazon CloudWatch.

  2. Download the AWS Distro for OpenTelemetry Collector and set it up. The AWS Distro for OpenTelemetry Collector is responsible for receiving telemetry data from the application using the AWS Advanced NodeJS Wrapper and forwarding it to AWS. Both connections happen via HTTP, therefore URLs and ports need to be correctly configured for the collector.

Warning

The AWS Distro for OpenTelemetry Collector can be set up either locally or remotely. It is up to the user to decide where is best to set it up. If you decide to host it remotely, ensure that the application has the necessary permissions or allowlists to connect to the Collector.

Warning

The collector is an external application that is not part of the wrapper itself. Without a collector, the wrapper will collect monitoring data from its execution but that data will not be sent anywhere for visualization.

Using Telemetry

Telemetry for the AWS Advanced NodeJS Wrapper is a monitoring strategy that overlooks all plugins enabled in plugins and is not a plugin in itself. Changes are not required in the plugins parameter to enable Telemetry.

In order to enable Telemetry in the AWS Advanced NodeJS Wrapper, you need to:

  1. Set the enableTelemetry connection property to true.

  2. Set up the recorders that will export the telemetry data from the code to the ADOT Collector.

To set up the recorders, instantiate NodeSDK and configure the forwarding endpoints in your application code prior to using the wrapper.

The code sample below shows one way to instantiate trace and metrics recording for telemetryTracesBackend: "OTLP" with telemetryMetricsBackend: "OTLP". This configuration only needs to be done once before you create any client.

import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-grpc";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-grpc";
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
import { NodeSDK } from "@opentelemetry/sdk-node";

const sdk = new NodeSDK({
  serviceName: "aws-advanced-nodejs-wrapper",
  traceExporter: new OTLPTraceExporter({ url: "http://localhost:4317" }),
  metricReaders: [
    new PeriodicExportingMetricReader({
      exporter: new OTLPMetricExporter({ url: "http://localhost:4317" }),
      exportIntervalMillis: 1000
    })
  ]
});

// Registers the tracer and meter providers that the wrapper records against.
sdk.start();

// Flush any buffered telemetry before the process exits.
process.on("SIGTERM", () => {
  sdk
    .shutdown()
    .then(() => console.log("Tracing and metrics terminated"))
    .catch((error) => console.log("Error terminating tracing and metrics", error))
    .finally(() => process.exit(0));
});

NodeSDK fills in a context manager and a resource of its own, so nothing else is required. Three further options change how traces are identified and propagated. None is needed for the wrapper's telemetry:

Option Add it to
instrumentations Trace your application's own HTTP or AWS SDK calls alongside the wrapper's
textMapPropagator Carry trace context between services in the X-Amzn-Trace-Id header
idGenerator Embed the trace start time in the trace ID, the way X-Ray's own IDs do

X-Ray accepts the random trace IDs OpenTelemetry generates by default, so idGenerator is not needed to get traces into the console. Without it, the timestamp X-Ray reads from the first four bytes of a trace ID is random and decodes to an arbitrary date.

To send traces to X-Ray instead, set telemetryTracesBackend: "XRAY" and drop traceExporter from the configuration above. The wrapper opens its own X-Ray segments through aws-xray-sdk, so no OpenTelemetry tracing setup is involved. Metrics have no X-Ray backend, so leave telemetryMetricsBackend as "OTLP" and keep the metricReaders block.

Sample applications for both setups are in the examples folder:

Sample Traces Metrics
telemetry_metrics_otlp_example.ts OTLP OTLP
telemetry_tracing_xray_example.ts XRAY OTLP

Telemetry Parameters

In addition to the parameter that enables Telemetry, you can pass the following parameters to the AWS Advanced NodeJS Wrapper to configure how telemetry data will be forwarded.

Parameter Value Required Description Default Value
enableTelemetry boolean No Telemetry will be enabled when this property is set to true, otherwise no telemetry data will be gathered during the execution of the wrapper. false
telemetryTracesBackend string No Determines to which backend the gathered tracing data will be forwarded to. Possible values include: NONE, XRAY, and OTLP.
NONE indicates that the application will collect tracing data but this data will not be forwarded anywhere.
XRAY indicates that the traces will be collected by the AWS XRay Daemon.
OTLP indicates that the traces will be collected by the AWS OTEL Collector.
NONE
telemetryMetricsBackend string No Determines to which backend the gathered metrics data will be forwarded to. Possible values include: NONE and OTLP.
NONE indicates that the application will collect metrics data but this data will not be forwarded anywhere.
OTLP indicates that the metrics will be collected by the AWS OTEL Collector.
NONE
telemetrySubmitToplevel boolean No By default the wrapper will look for open traces in the users application prior to record telemetry data. If there is a current open trace, the traces created will be attached to that open trace. If not, all telemetry traces created will be top level. Setting the parameter to false means that every call to the wrapper will generate a trace with no direct parent trace attached to it. If there is already an open trace being recorded by the application, no wrapper traces will be created. See the Nested tracing strategies section for more information. false

Nested tracing strategies using Amazon XRay

As you could see in the Telemetry Parameters section, the AWS Advanced NodeJS Wrapper allows users to determine which strategy for nested traces to use when using Telemetry.

Traces are hierarchical entities and it might be that the user application already has an open trace in a given sequence of code that connects to the AWS Advanced NodeJS Wrapper. In this case, the Telemetry feature allows users to determine which strategy to use for the Telemetry traces generated when using the wrapper.

A top level trace is a trace that has no link to any other parent trace, and is directly accessible from the list of submitted traces within XRay. In the following pictures, the top level traces of an application are displayed in AWS X-Ray.

When a trace is hierarchically linked to a parent trace, we say that this trace is nested. An example of nested traces are the individual plugin traces for a given call. All the individual plugin traces are linked to a parent trace for the call. Those nested traces are illustrated in the image below.

Applications that interact with the AWS Advanced NodeJS Wrapper may or may not have already opened telemetry traces on their own. In this case, it is up to the user to determine how they want to mix both application and wrapper traces.

This can be done using the AWS Advanced NodeJS Wrapper's telemetrySubmitToplevel property. This property allows users to choose to submit the wrapper traces always as top level traces or to submit them nested to the application traces. The default value is set to false, which means the wrapper traces to always be nested into their application traces. That will happen unless there are no open application traces when the wrapper is running. In that case no wrapper traces will be collected or submitted. When the property is set to true, all the wrapper traces would be submitted top level traces. If the application has already open traces, it will not be possible for the wrapper traces to be top level and the wrapper traces therefore will not be submitted.

List of Metrics

The AWS Advanced NodeJS Wrapper also submits a set of metrics to Amazon CloudWatch when the wrapper is used. These metrics are predefined, and they help give insight on what is happening inside the plugins when the plugins are used.

Metrics can be one of 3 types: counters, gauges or histograms.

Note

Every metric below belongs to a plugin, and it appears only when that plugin is enabled. Once it appears it reports on every export interval, carrying 0 until the event it counts happens. So a run with no plugins beyond the defaults publishes no plugin metrics at all, while a run with the iam plugin publishes iam.fetchTokenCount continuously and it stays 0 until a token is actually fetched. If a metric you expect is missing, check that its plugin is in plugins. If it is present but always 0, its event has not occurred.

EFM plugin

Metric name Metric type Description
efm.connections.aborted Counter Number of times a connection was aborted after being defined as unhealthy by an EFM monitoring task
efm.hostUnhealthy.count.[INSTANCE] Counter Number of times a specific instance has been defined as unhealthy

Secrets Manager plugin

Metric name Metric type Description
secretsManager.fetchCredentials.count Counter Number of times credentials were fetched from Secrets Manager

IAM plugin

Metric name Metric type Description
iam.fetchToken.count Counter Number of times tokens were fetched from IAM

Failover plugin

Metric name Metric type Description
writerFailover.triggered.count Counter Number of times writer failover was triggered
writerFailover.completed.success.count Counter Number of times writer failover was completed and succeeded
writerFailover.completed.failed.count Counter Number of times writer failover was completed and failed
readerFailover.triggered.count Counter Number of times reader failover was triggered
readerFailover.completed.success.count Counter Number of times reader failover was completed and succeeded
readerFailover.completed.failed.count Counter Number of times reader failover was completed and failed

Stale DNS plugin

Metric name Metric type Description
staleDNS.stale.detected Counter Number of times DNS was detected stale

Federated Authentication plugin

Metric name Metric type Description
federatedAuth.fetchToken.count Counter Number of times tokens were fetched from IAM

OKTA plugin

Metric name Metric type Description
oktaAuth.fetchToken.count Counter Number of times tokens were fetched from IAM