UNPKG

enhanced-adot-node-autoinstrumentation

Version:

This package provides Amazon Web Services distribution of the OpenTelemetry Node Instrumentation, which allows for auto-instrumentation of NodeJS applications.

60 lines 2.8 kB
"use strict"; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.AwsSpanMetricsProcessorBuilder = void 0; const aws_metric_attribute_generator_1 = require("./aws-metric-attribute-generator"); const aws_span_metrics_processor_1 = require("./aws-span-metrics-processor"); // Metric instrument configuration constants const ERROR = 'Error'; const FAULT = 'Fault'; const LATENCY = 'Latency'; const LATENCY_UNITS = 'Milliseconds'; /** A builder for {@link AwsSpanMetricsProcessor} */ class AwsSpanMetricsProcessorBuilder { constructor(meterProvider, resource, meterProviderForceFlusher) { // Optional builder elements this.generator = AwsSpanMetricsProcessorBuilder.DEFAULT_GENERATOR; this.scopeName = AwsSpanMetricsProcessorBuilder.DEFAULT_SCOPE_NAME; this.meterProvider = meterProvider; this.resource = resource; this.forceFlushFunction = meterProviderForceFlusher; } static create(meterProvider, resource, meterProviderForceFlusher) { return new AwsSpanMetricsProcessorBuilder(meterProvider, resource, meterProviderForceFlusher); } /** * Sets the generator used to generate attributes used in metrics produced by span metrics * processor. If unset, defaults to {@link DEFAULT_GENERATOR}. Must not be null. */ setGenerator(generator) { if (generator == null) { throw new Error('generator must not be null/undefined'); } this.generator = generator; return this; } /** * Sets the scope name used in the creation of metrics by the span metrics processor. If unset, * defaults to {@link DEFAULT_SCOPE_NAME}. Must not be null. */ setScopeName(scopeName) { this.scopeName = scopeName; return this; } build() { const meter = this.meterProvider.getMeter(this.scopeName); const errorHistogram = meter.createHistogram(ERROR); const faultHistogram = meter.createHistogram(FAULT); const metricOptions = { unit: LATENCY_UNITS, }; const latencyHistogram = meter.createHistogram(LATENCY, metricOptions); return aws_span_metrics_processor_1.AwsSpanMetricsProcessor.create(errorHistogram, faultHistogram, latencyHistogram, this.generator, this.resource, this.forceFlushFunction); } } exports.AwsSpanMetricsProcessorBuilder = AwsSpanMetricsProcessorBuilder; // Defaults AwsSpanMetricsProcessorBuilder.DEFAULT_GENERATOR = new aws_metric_attribute_generator_1.AwsMetricAttributeGenerator(); AwsSpanMetricsProcessorBuilder.DEFAULT_SCOPE_NAME = 'AwsSpanMetricsProcessor'; //# sourceMappingURL=aws-span-metrics-processor-builder.js.map