@prairielearn/opentelemetry 1.11.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.mocharc.cjs ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ require: ['tsx'],
3
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @prairielearn/opentelemetry
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 4f30b7e: Publish as native ESM
8
+
9
+ ### Minor Changes
10
+
11
+ - c51f3aa: Upgrade all JavaScript dependencies; ensure packages loaded with ESM are instrumented
12
+
13
+ ## 1.11.3
14
+
15
+ ### Patch Changes
16
+
17
+ - 290f60f: Refine configuration types
18
+
3
19
  ## 1.11.2
4
20
 
5
21
  ### Patch Changes
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ // The packages below were determined by inspecting the implementation of each
2
+ // instrumentation package and finding which packages/files they're patching.
3
+ const PRELOAD_PACKAGES = [
4
+ // @opentelemetry/instrumentation-aws
5
+ '@aws-sdk/middleware-stack/dist/cjs/MiddlewareStack.js',
6
+ '@aws-sdk/middleware-stack/dist-cjs/MiddlewareStack.js',
7
+ '@aws-sdk/middleware-stack',
8
+ '@aws-sdk/smithy-client',
9
+ 'aws-sdk/lib/core.js',
10
+ 'aws-sdk',
11
+ // @opentelemetry/instrumentation-connect
12
+ 'connect',
13
+ // @opentelemetry/instrumentation-dns
14
+ 'dns',
15
+ 'dns/promises',
16
+ // @opentelemetry/instrumentation-express
17
+ 'express',
18
+ // @opentelemetry/instrumentation-http
19
+ 'http',
20
+ 'https',
21
+ // @opentelemetry/instrumentation-ioredis
22
+ 'ioredis',
23
+ // @opentelemetry/instrumentation-postgres
24
+ 'pg',
25
+ 'pg-pool',
26
+ // @opentelemetry/instrumentation-redis
27
+ 'redis',
28
+ ];
29
+ for (const pkg of PRELOAD_PACKAGES) {
30
+ try {
31
+ // TODO: switch to using `createRequire` once this is native ESM.
32
+ require(pkg);
33
+ }
34
+ catch (e) {
35
+ // Ignore; package is likely not installed.
36
+ }
37
+ }
38
+ export {};
39
+ //# sourceMappingURL=commonjs-preloads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commonjs-preloads.js","sourceRoot":"","sources":["../src/commonjs-preloads.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,MAAM,gBAAgB,GAAG;IACvB,qCAAqC;IACrC,uDAAuD;IACvD,uDAAuD;IACvD,2BAA2B;IAC3B,wBAAwB;IACxB,qBAAqB;IACrB,SAAS;IACT,yCAAyC;IACzC,SAAS;IACT,qCAAqC;IACrC,KAAK;IACL,cAAc;IACd,yCAAyC;IACzC,SAAS;IACT,sCAAsC;IACtC,MAAM;IACN,OAAO;IACP,yCAAyC;IACzC,SAAS;IACT,0CAA0C;IAC1C,IAAI;IACJ,SAAS;IACT,uCAAuC;IACvC,OAAO;CACR,CAAC;AAEF,KAAK,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACnC,IAAI,CAAC;QACH,iEAAiE;QACjE,OAAO,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,2CAA2C;IAC7C,CAAC;AACH,CAAC","sourcesContent":["// The packages below were determined by inspecting the implementation of each\n// instrumentation package and finding which packages/files they're patching.\nconst PRELOAD_PACKAGES = [\n // @opentelemetry/instrumentation-aws\n '@aws-sdk/middleware-stack/dist/cjs/MiddlewareStack.js',\n '@aws-sdk/middleware-stack/dist-cjs/MiddlewareStack.js',\n '@aws-sdk/middleware-stack',\n '@aws-sdk/smithy-client',\n 'aws-sdk/lib/core.js',\n 'aws-sdk',\n // @opentelemetry/instrumentation-connect\n 'connect',\n // @opentelemetry/instrumentation-dns\n 'dns',\n 'dns/promises',\n // @opentelemetry/instrumentation-express\n 'express',\n // @opentelemetry/instrumentation-http\n 'http',\n 'https',\n // @opentelemetry/instrumentation-ioredis\n 'ioredis',\n // @opentelemetry/instrumentation-postgres\n 'pg',\n 'pg-pool',\n // @opentelemetry/instrumentation-redis\n 'redis',\n];\n\nfor (const pkg of PRELOAD_PACKAGES) {\n try {\n // TODO: switch to using `createRequire` once this is native ESM.\n require(pkg);\n } catch (e) {\n // Ignore; package is likely not installed.\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export { trace, metrics, context, SpanStatusCode, ValueType, TraceFlags, Meter, Counter, Histogram, UpDownCounter, ObservableCounter, ObservableUpDownCounter, ObservableGauge, ObservableResult, } from '@opentelemetry/api';
1
+ export { trace, metrics, context, SpanStatusCode, ValueType, TraceFlags, type Meter, type Counter, type Histogram, type UpDownCounter, type ObservableCounter, type ObservableUpDownCounter, type ObservableGauge, type ObservableResult, } from '@opentelemetry/api';
2
2
  export { suppressTracing } from '@opentelemetry/core';
3
- export { init, shutdown, disableInstrumentations } from './init';
4
- export { instrumented } from './tracing';
5
- export { instrumentedWithMetrics, getCounter, getUpDownCounter, getHistogram, getObservableCounter, getObservableUpDownCounter, getObservableGauge, createObservableValueGauges, createObservableValueGaugesOptions, } from './metrics';
3
+ export { init, shutdown, disableInstrumentations } from './init.js';
4
+ export { instrumented } from './tracing.js';
5
+ export { instrumentedWithMetrics, getCounter, getUpDownCounter, getHistogram, getObservableCounter, getObservableUpDownCounter, getObservableGauge, createObservableValueGauges, type CreateObservableValueGaugesOptions, } from './metrics.js';
6
+ import './commonjs-preloads.js';
package/dist/index.js CHANGED
@@ -1,28 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createObservableValueGauges = exports.getObservableGauge = exports.getObservableUpDownCounter = exports.getObservableCounter = exports.getHistogram = exports.getUpDownCounter = exports.getCounter = exports.instrumentedWithMetrics = exports.instrumented = exports.disableInstrumentations = exports.shutdown = exports.init = exports.suppressTracing = exports.TraceFlags = exports.ValueType = exports.SpanStatusCode = exports.context = exports.metrics = exports.trace = void 0;
4
- var api_1 = require("@opentelemetry/api");
5
- Object.defineProperty(exports, "trace", { enumerable: true, get: function () { return api_1.trace; } });
6
- Object.defineProperty(exports, "metrics", { enumerable: true, get: function () { return api_1.metrics; } });
7
- Object.defineProperty(exports, "context", { enumerable: true, get: function () { return api_1.context; } });
8
- Object.defineProperty(exports, "SpanStatusCode", { enumerable: true, get: function () { return api_1.SpanStatusCode; } });
9
- Object.defineProperty(exports, "ValueType", { enumerable: true, get: function () { return api_1.ValueType; } });
10
- Object.defineProperty(exports, "TraceFlags", { enumerable: true, get: function () { return api_1.TraceFlags; } });
11
- var core_1 = require("@opentelemetry/core");
12
- Object.defineProperty(exports, "suppressTracing", { enumerable: true, get: function () { return core_1.suppressTracing; } });
13
- var init_1 = require("./init");
14
- Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_1.init; } });
15
- Object.defineProperty(exports, "shutdown", { enumerable: true, get: function () { return init_1.shutdown; } });
16
- Object.defineProperty(exports, "disableInstrumentations", { enumerable: true, get: function () { return init_1.disableInstrumentations; } });
17
- var tracing_1 = require("./tracing");
18
- Object.defineProperty(exports, "instrumented", { enumerable: true, get: function () { return tracing_1.instrumented; } });
19
- var metrics_1 = require("./metrics");
20
- Object.defineProperty(exports, "instrumentedWithMetrics", { enumerable: true, get: function () { return metrics_1.instrumentedWithMetrics; } });
21
- Object.defineProperty(exports, "getCounter", { enumerable: true, get: function () { return metrics_1.getCounter; } });
22
- Object.defineProperty(exports, "getUpDownCounter", { enumerable: true, get: function () { return metrics_1.getUpDownCounter; } });
23
- Object.defineProperty(exports, "getHistogram", { enumerable: true, get: function () { return metrics_1.getHistogram; } });
24
- Object.defineProperty(exports, "getObservableCounter", { enumerable: true, get: function () { return metrics_1.getObservableCounter; } });
25
- Object.defineProperty(exports, "getObservableUpDownCounter", { enumerable: true, get: function () { return metrics_1.getObservableUpDownCounter; } });
26
- Object.defineProperty(exports, "getObservableGauge", { enumerable: true, get: function () { return metrics_1.getObservableGauge; } });
27
- Object.defineProperty(exports, "createObservableValueGauges", { enumerable: true, get: function () { return metrics_1.createObservableValueGauges; } });
1
+ export { trace, metrics, context, SpanStatusCode, ValueType, TraceFlags, } from '@opentelemetry/api';
2
+ export { suppressTracing } from '@opentelemetry/core';
3
+ export { init, shutdown, disableInstrumentations } from './init.js';
4
+ export { instrumented } from './tracing.js';
5
+ export { instrumentedWithMetrics, getCounter, getUpDownCounter, getHistogram, getObservableCounter, getObservableUpDownCounter, getObservableGauge, createObservableValueGauges, } from './metrics.js';
6
+ // Extremely stupid workaround for the fact that the OpenTelemetry instrumentations
7
+ // don't currently have robust support for ESM. This hack ensures that instrumented
8
+ // packages are loaded for the first time via CJS, which the OpenTelemetry
9
+ // instrumentation can intercept and patch. Subsequent imports can be ESM, but that
10
+ // doesn't matter because the instrumentation has already been applied.
11
+ //
12
+ // OpenTelemetry introduced experimental support for ESM in
13
+ // https://github.com/open-telemetry/opentelemetry-js/pull/3698. This requires
14
+ // the usage of `--experimental-loader` to load the instrumentations, which
15
+ // we currently want to avoid.
16
+ import './commonjs-preloads.js';
28
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0CAe4B;AAd1B,4FAAA,KAAK,OAAA;AACL,8FAAA,OAAO,OAAA;AACP,8FAAA,OAAO,OAAA;AACP,qGAAA,cAAc,OAAA;AACd,gGAAA,SAAS,OAAA;AACT,iGAAA,UAAU,OAAA;AAUZ,4CAAsD;AAA7C,uGAAA,eAAe,OAAA;AAExB,+BAAiE;AAAxD,4FAAA,IAAI,OAAA;AAAE,gGAAA,QAAQ,OAAA;AAAE,+GAAA,uBAAuB,OAAA;AAChD,qCAAyC;AAAhC,uGAAA,YAAY,OAAA;AACrB,qCAUmB;AATjB,kHAAA,uBAAuB,OAAA;AACvB,qGAAA,UAAU,OAAA;AACV,2GAAA,gBAAgB,OAAA;AAChB,uGAAA,YAAY,OAAA;AACZ,+GAAA,oBAAoB,OAAA;AACpB,qHAAA,0BAA0B,OAAA;AAC1B,6GAAA,kBAAkB,OAAA;AAClB,sHAAA,2BAA2B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,OAAO,EACP,cAAc,EACd,SAAS,EACT,UAAU,GASX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,uBAAuB,EACvB,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,EACpB,0BAA0B,EAC1B,kBAAkB,EAClB,2BAA2B,GAE5B,MAAM,cAAc,CAAC;AAEtB,mFAAmF;AACnF,mFAAmF;AACnF,0EAA0E;AAC1E,mFAAmF;AACnF,uEAAuE;AACvE,EAAE;AACF,2DAA2D;AAC3D,8EAA8E;AAC9E,2EAA2E;AAC3E,8BAA8B;AAC9B,OAAO,wBAAwB,CAAC","sourcesContent":["export {\n trace,\n metrics,\n context,\n SpanStatusCode,\n ValueType,\n TraceFlags,\n type Meter,\n type Counter,\n type Histogram,\n type UpDownCounter,\n type ObservableCounter,\n type ObservableUpDownCounter,\n type ObservableGauge,\n type ObservableResult,\n} from '@opentelemetry/api';\nexport { suppressTracing } from '@opentelemetry/core';\n\nexport { init, shutdown, disableInstrumentations } from './init.js';\nexport { instrumented } from './tracing.js';\nexport {\n instrumentedWithMetrics,\n getCounter,\n getUpDownCounter,\n getHistogram,\n getObservableCounter,\n getObservableUpDownCounter,\n getObservableGauge,\n createObservableValueGauges,\n type CreateObservableValueGaugesOptions,\n} from './metrics.js';\n\n// Extremely stupid workaround for the fact that the OpenTelemetry instrumentations\n// don't currently have robust support for ESM. This hack ensures that instrumented\n// packages are loaded for the first time via CJS, which the OpenTelemetry\n// instrumentation can intercept and patch. Subsequent imports can be ESM, but that\n// doesn't matter because the instrumentation has already been applied.\n//\n// OpenTelemetry introduced experimental support for ESM in\n// https://github.com/open-telemetry/opentelemetry-js/pull/3698. This requires\n// the usage of `--experimental-loader` to load the instrumentations, which\n// we currently want to avoid.\nimport './commonjs-preloads.js';\n"]}
package/dist/init.d.ts CHANGED
@@ -1,20 +1,21 @@
1
1
  import { PushMetricExporter } from '@opentelemetry/sdk-metrics';
2
2
  import { SpanExporter, SpanProcessor } from '@opentelemetry/sdk-trace-base';
3
- export interface OpenTelemetryConfigEnabled {
4
- openTelemetryEnabled: true;
5
- openTelemetryExporter?: 'console' | 'honeycomb' | 'jaeger' | SpanExporter;
6
- openTelemetryMetricExporter?: 'console' | 'honeycomb' | PushMetricExporter;
3
+ interface OpenTelemetryConfigEnabled {
4
+ openTelemetryEnabled: boolean;
5
+ openTelemetryExporter?: 'console' | 'honeycomb' | 'jaeger' | SpanExporter | null;
6
+ openTelemetryMetricExporter?: 'console' | 'honeycomb' | PushMetricExporter | null;
7
7
  openTelemetryMetricExportIntervalMillis?: number;
8
8
  openTelemetrySamplerType: 'always-on' | 'always-off' | 'trace-id-ratio';
9
9
  openTelemetrySampleRate?: number;
10
10
  openTelemetrySpanProcessor?: 'batch' | 'simple' | SpanProcessor;
11
- honeycombApiKey?: string;
12
- honeycombDataset?: string;
11
+ honeycombApiKey?: string | null;
12
+ honeycombDataset?: string | null;
13
13
  serviceName?: string;
14
14
  }
15
- export type OpenTelemetryConfig = OpenTelemetryConfigEnabled | {
15
+ interface OpenTelemetryConfigDisabled extends Partial<OpenTelemetryConfigEnabled> {
16
16
  openTelemetryEnabled: false;
17
- };
17
+ }
18
+ export type OpenTelemetryConfig = OpenTelemetryConfigEnabled | OpenTelemetryConfigDisabled;
18
19
  /**
19
20
  * Should be called once we've loaded our config; this will allow us to set up
20
21
  * the correct metadata for the Honeycomb exporter. We don't actually have that
@@ -31,3 +32,4 @@ export declare function shutdown(): Promise<void>;
31
32
  * need to access the unwrapped modules.
32
33
  */
33
34
  export declare function disableInstrumentations(): void;
35
+ export {};
package/dist/init.js CHANGED
@@ -1,33 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.disableInstrumentations = exports.shutdown = exports.init = void 0;
4
- const grpc_js_1 = require("@grpc/grpc-js");
5
- const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
6
- const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
7
- const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
8
- const resources_1 = require("@opentelemetry/resources");
9
- const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
10
- const api_1 = require("@opentelemetry/api");
11
- const core_1 = require("@opentelemetry/core");
1
+ import { Metadata, credentials } from '@grpc/grpc-js';
2
+ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
3
+ import { PeriodicExportingMetricReader, MeterProvider, ConsoleMetricExporter, AggregationTemporality, } from '@opentelemetry/sdk-metrics';
4
+ import { SimpleSpanProcessor, BatchSpanProcessor, ParentBasedSampler, TraceIdRatioBasedSampler, AlwaysOnSampler, AlwaysOffSampler, ConsoleSpanExporter, } from '@opentelemetry/sdk-trace-base';
5
+ import { detectResourcesSync, processDetector, envDetector, Resource, } from '@opentelemetry/resources';
6
+ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
7
+ import { metrics } from '@opentelemetry/api';
8
+ import { hrTimeToMilliseconds } from '@opentelemetry/core';
12
9
  // Exporters go here.
13
- const exporter_trace_otlp_grpc_1 = require("@opentelemetry/exporter-trace-otlp-grpc");
14
- const exporter_metrics_otlp_grpc_1 = require("@opentelemetry/exporter-metrics-otlp-grpc");
10
+ import { OTLPTraceExporter as OTLPTraceExporterHttp } from '@opentelemetry/exporter-trace-otlp-http';
11
+ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
12
+ import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
15
13
  // Instrumentations go here.
16
- const instrumentation_aws_sdk_1 = require("@opentelemetry/instrumentation-aws-sdk");
17
- const instrumentation_connect_1 = require("@opentelemetry/instrumentation-connect");
18
- const instrumentation_dns_1 = require("@opentelemetry/instrumentation-dns");
19
- const instrumentation_express_1 = require("@opentelemetry/instrumentation-express");
20
- const instrumentation_http_1 = require("@opentelemetry/instrumentation-http");
21
- const instrumentation_pg_1 = require("@opentelemetry/instrumentation-pg");
22
- const instrumentation_redis_1 = require("@opentelemetry/instrumentation-redis");
14
+ import { AwsInstrumentation } from '@opentelemetry/instrumentation-aws-sdk';
15
+ import { ConnectInstrumentation } from '@opentelemetry/instrumentation-connect';
16
+ import { DnsInstrumentation } from '@opentelemetry/instrumentation-dns';
17
+ import { ExpressLayerType, ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
18
+ import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
19
+ import { IORedisInstrumentation } from '@opentelemetry/instrumentation-ioredis';
20
+ import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';
21
+ import { RedisInstrumentation } from '@opentelemetry/instrumentation-redis';
23
22
  // Resource detectors go here.
24
- const resource_detector_aws_1 = require("@opentelemetry/resource-detector-aws");
23
+ import { awsEc2Detector } from '@opentelemetry/resource-detector-aws';
25
24
  /**
26
25
  * Extends `BatchSpanProcessor` to give it the ability to filter out spans
27
26
  * before they're queued up to send. This enhances our sampling process so
28
27
  * that we can filter spans _after_ they've been emitted.
29
28
  */
30
- class FilterBatchSpanProcessor extends sdk_trace_base_1.BatchSpanProcessor {
29
+ class FilterBatchSpanProcessor extends BatchSpanProcessor {
31
30
  filter;
32
31
  constructor(exporter, filter) {
33
32
  super(exporter);
@@ -57,27 +56,31 @@ function filter(span) {
57
56
  // establishing a connection for the first time, which should happen only at
58
57
  // bootup, or if a connection errors out. Those are the cases we're
59
58
  // interested in, so we'll filter accordingly.
60
- return (0, core_1.hrTimeToMilliseconds)(span.duration) > 1;
59
+ return hrTimeToMilliseconds(span.duration) > 1;
61
60
  }
62
61
  // Always return true so that we default to including a span.
63
62
  return true;
64
63
  }
64
+ // When adding new instrumentation here, add the corresponding packages to
65
+ // `commonjs-preloads.ts` so that we can ensure that they're loaded via CJS
66
+ // before anything tries to load them via CJS. This is necessary because the
67
+ // instrumentations can't hook into the ESM loader.
65
68
  const instrumentations = [
66
- new instrumentation_aws_sdk_1.AwsInstrumentation(),
67
- new instrumentation_connect_1.ConnectInstrumentation(),
68
- new instrumentation_dns_1.DnsInstrumentation(),
69
- new instrumentation_express_1.ExpressInstrumentation({
69
+ new AwsInstrumentation(),
70
+ new ConnectInstrumentation(),
71
+ new DnsInstrumentation(),
72
+ new ExpressInstrumentation({
70
73
  // We use a lot of middleware; it makes the traces way too noisy. If we
71
74
  // want telemetry on a particular middleware, we should instrument it
72
75
  // manually.
73
- ignoreLayersType: [instrumentation_express_1.ExpressLayerType.MIDDLEWARE],
76
+ ignoreLayersType: [ExpressLayerType.MIDDLEWARE],
74
77
  ignoreLayers: [
75
78
  // These don't provide useful information to us.
76
79
  'router - /',
77
80
  'request handler - /*',
78
81
  ],
79
82
  }),
80
- new instrumentation_http_1.HttpInstrumentation({
83
+ new HttpInstrumentation({
81
84
  ignoreIncomingPaths: [
82
85
  // socket.io requests are generally just long-polling; they don't add
83
86
  // useful information for us.
@@ -87,8 +90,9 @@ const instrumentations = [
87
90
  /\/pl\/webhooks\/ping/,
88
91
  ],
89
92
  }),
90
- new instrumentation_pg_1.PgInstrumentation(),
91
- new instrumentation_redis_1.RedisInstrumentation(),
93
+ new IORedisInstrumentation(),
94
+ new PgInstrumentation(),
95
+ new RedisInstrumentation(),
92
96
  ];
93
97
  // Enable all instrumentations now, even though we haven't configured our
94
98
  // span processors or trace exporters yet. We'll set those up later.
@@ -101,7 +105,7 @@ function getHoneycombMetadata(config, datasetSuffix = '') {
101
105
  throw new Error('Missing Honeycomb API key');
102
106
  if (!config.honeycombDataset)
103
107
  throw new Error('Missing Honeycomb dataset');
104
- const metadata = new grpc_js_1.Metadata();
108
+ const metadata = new Metadata();
105
109
  metadata.set('x-honeycomb-team', config.honeycombApiKey);
106
110
  metadata.set('x-honeycomb-dataset', config.honeycombDataset + datasetSuffix);
107
111
  return metadata;
@@ -114,18 +118,16 @@ function getTraceExporter(config) {
114
118
  }
115
119
  switch (config.openTelemetryExporter) {
116
120
  case 'console':
117
- return new sdk_trace_base_1.ConsoleSpanExporter();
121
+ return new ConsoleSpanExporter();
118
122
  case 'honeycomb':
119
- return new exporter_trace_otlp_grpc_1.OTLPTraceExporter({
123
+ return new OTLPTraceExporter({
120
124
  url: 'grpc://api.honeycomb.io:443/',
121
- credentials: grpc_js_1.credentials.createSsl(),
125
+ credentials: credentials.createSsl(),
122
126
  metadata: getHoneycombMetadata(config),
123
127
  });
124
128
  break;
125
129
  case 'jaeger':
126
- return new exporter_trace_otlp_grpc_1.OTLPTraceExporter({
127
- url: process.env.OTEL_EXPORTER_JAEGER_ENDPOINT ?? 'grpc://localhost:4317/',
128
- });
130
+ return new OTLPTraceExporterHttp();
129
131
  default:
130
132
  throw new Error(`Unknown OpenTelemetry exporter: ${config.openTelemetryExporter}`);
131
133
  }
@@ -138,18 +140,18 @@ function getMetricExporter(config) {
138
140
  }
139
141
  switch (config.openTelemetryMetricExporter) {
140
142
  case 'console':
141
- return new sdk_metrics_1.ConsoleMetricExporter();
143
+ return new ConsoleMetricExporter();
142
144
  case 'honeycomb':
143
- return new exporter_metrics_otlp_grpc_1.OTLPMetricExporter({
145
+ return new OTLPMetricExporter({
144
146
  url: 'grpc://api.honeycomb.io:443/',
145
- credentials: grpc_js_1.credentials.createSsl(),
147
+ credentials: credentials.createSsl(),
146
148
  // Honeycomb recommends using a separate dataset for metrics, so we'll
147
149
  // adopt the convention of appending '-metrics' to the dataset name.
148
150
  metadata: getHoneycombMetadata(config, '-metrics'),
149
151
  // Delta temporality means that sums, histograms, etc. will reset each
150
152
  // time data is collected. This more closely matches how we want to
151
153
  // observe our metrics than the default cumulative temporality.
152
- temporalityPreference: sdk_metrics_1.AggregationTemporality.DELTA,
154
+ temporalityPreference: AggregationTemporality.DELTA,
153
155
  });
154
156
  default:
155
157
  throw new Error(`Unknown OpenTelemetry metric exporter: ${config.openTelemetryMetricExporter}`);
@@ -167,7 +169,7 @@ function getSpanProcessor(config) {
167
169
  return new FilterBatchSpanProcessor(traceExporter, filter);
168
170
  }
169
171
  case 'simple': {
170
- return new sdk_trace_base_1.SimpleSpanProcessor(traceExporter);
172
+ return new SimpleSpanProcessor(traceExporter);
171
173
  }
172
174
  default: {
173
175
  throw new Error(`Unknown OpenTelemetry span processor: ${config.openTelemetrySpanProcessor}`);
@@ -179,7 +181,7 @@ function getSpanProcessor(config) {
179
181
  * the correct metadata for the Honeycomb exporter. We don't actually have that
180
182
  * information available until we've loaded our config.
181
183
  */
182
- async function init(config) {
184
+ export async function init(config) {
183
185
  if (!config.openTelemetryEnabled) {
184
186
  // If not enabled, do nothing. We used to disable the instrumentations, but
185
187
  // per maintainers, that can actually be problematic. See the comments on
@@ -195,16 +197,16 @@ async function init(config) {
195
197
  let sampler;
196
198
  switch (config.openTelemetrySamplerType ?? 'always-on') {
197
199
  case 'always-on': {
198
- sampler = new sdk_trace_base_1.AlwaysOnSampler();
200
+ sampler = new AlwaysOnSampler();
199
201
  break;
200
202
  }
201
203
  case 'always-off': {
202
- sampler = new sdk_trace_base_1.AlwaysOffSampler();
204
+ sampler = new AlwaysOffSampler();
203
205
  break;
204
206
  }
205
207
  case 'trace-id-ratio': {
206
- sampler = new sdk_trace_base_1.ParentBasedSampler({
207
- root: new sdk_trace_base_1.TraceIdRatioBasedSampler(config.openTelemetrySampleRate),
208
+ sampler = new ParentBasedSampler({
209
+ root: new TraceIdRatioBasedSampler(config.openTelemetrySampleRate),
208
210
  });
209
211
  break;
210
212
  }
@@ -216,14 +218,14 @@ async function init(config) {
216
218
  // asynchronously. We need to initialize our instrumentations first; only
217
219
  // then can we actually start requiring all of our code that loads our config
218
220
  // and ultimately tells us how to configure OpenTelemetry.
219
- let resource = (0, resources_1.detectResourcesSync)({
220
- detectors: [resource_detector_aws_1.awsEc2Detector, resources_1.processDetector, resources_1.envDetector],
221
+ let resource = detectResourcesSync({
222
+ detectors: [awsEc2Detector, processDetector, envDetector],
221
223
  });
222
224
  if (config.serviceName) {
223
- resource = resource.merge(new resources_1.Resource({ [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: config.serviceName }));
225
+ resource = resource.merge(new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: config.serviceName }));
224
226
  }
225
227
  // Set up tracing instrumentation.
226
- const nodeTracerProvider = new sdk_trace_node_1.NodeTracerProvider({
228
+ const nodeTracerProvider = new NodeTracerProvider({
227
229
  sampler,
228
230
  resource,
229
231
  });
@@ -236,36 +238,33 @@ async function init(config) {
236
238
  tracerProvider = nodeTracerProvider;
237
239
  // Set up metrics instrumentation if it's enabled.
238
240
  if (metricExporter) {
239
- const meterProvider = new sdk_metrics_1.MeterProvider({
241
+ const meterProvider = new MeterProvider({
240
242
  resource,
241
243
  readers: [
242
- new sdk_metrics_1.PeriodicExportingMetricReader({
244
+ new PeriodicExportingMetricReader({
243
245
  exporter: metricExporter,
244
246
  exportIntervalMillis: config.openTelemetryMetricExportIntervalMillis ?? 30_000,
245
247
  }),
246
248
  ],
247
249
  });
248
- api_1.metrics.setGlobalMeterProvider(meterProvider);
250
+ metrics.setGlobalMeterProvider(meterProvider);
249
251
  }
250
252
  }
251
- exports.init = init;
252
253
  /**
253
254
  * Gracefully shuts down the OpenTelemetry instrumentation. Should be called
254
255
  * when a `SIGTERM` signal is handled.
255
256
  */
256
- async function shutdown() {
257
+ export async function shutdown() {
257
258
  if (tracerProvider) {
258
259
  await tracerProvider.shutdown();
259
260
  tracerProvider = null;
260
261
  }
261
262
  }
262
- exports.shutdown = shutdown;
263
263
  /**
264
264
  * Disables all OpenTelemetry instrumentations. This is useful for tests that
265
265
  * need to access the unwrapped modules.
266
266
  */
267
- function disableInstrumentations() {
267
+ export function disableInstrumentations() {
268
268
  instrumentations.forEach((i) => i.disable());
269
269
  }
270
- exports.disableInstrumentations = disableInstrumentations;
271
270
  //# sourceMappingURL=init.js.map
package/dist/init.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAEtD,kEAAmE;AACnE,4DAMoC;AACpC,kEAYuC;AACvC,wDAKkC;AAClC,8EAAiF;AACjF,4CAA6C;AAC7C,8CAA2D;AAE3D,qBAAqB;AACrB,sFAA4E;AAC5E,0FAA+E;AAE/E,4BAA4B;AAC5B,oFAA4E;AAC5E,oFAAgF;AAChF,4EAAwE;AACxE,oFAAkG;AAClG,8EAA0E;AAC1E,0EAAsE;AACtE,gFAA4E;AAE5E,8BAA8B;AAC9B,gFAAsE;AAEtE;;;;GAIG;AACH,MAAM,wBAAyB,SAAQ,mCAAkB;IAC/C,MAAM,CAAkC;IAEhD,YAAY,QAAsB,EAAE,MAAuC;QACzE,KAAK,CAAC,QAAQ,CAAC,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAkB;QACtB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,OAAO;QAE/B,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;CACF;AAED;;;;GAIG;AACH,SAAS,MAAM,CAAC,IAAkB;IAChC,IAAI,IAAI,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;QACpC,6EAA6E;QAC7E,2EAA2E;QAC3E,mEAAmE;QACnE,4EAA4E;QAC5E,mEAAmE;QACnE,8CAA8C;QAC9C,OAAO,IAAA,2BAAoB,EAAC,IAAI,CAAC,QAAQ,CAAC,GAAG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,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { Metadata, credentials } from '@grpc/grpc-js';\n\nimport { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';\nimport {\n PeriodicExportingMetricReader,\n MeterProvider,\n PushMetricExporter,\n ConsoleMetricExporter,\n AggregationTemporality,\n} from '@opentelemetry/sdk-metrics';\nimport {\n SpanExporter,\n ReadableSpan,\n SpanProcessor,\n SimpleSpanProcessor,\n BatchSpanProcessor,\n ParentBasedSampler,\n TraceIdRatioBasedSampler,\n AlwaysOnSampler,\n AlwaysOffSampler,\n Sampler,\n ConsoleSpanExporter,\n} from '@opentelemetry/sdk-trace-base';\nimport {\n detectResourcesSync,\n processDetector,\n envDetector,\n Resource,\n} from '@opentelemetry/resources';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { metrics } from '@opentelemetry/api';\nimport { hrTimeToMilliseconds } from '@opentelemetry/core';\n\n// Exporters go here.\nimport { OTLPTraceExporter as OTLPTraceExporterHttp } from '@opentelemetry/exporter-trace-otlp-http';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';\nimport { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';\n\n// Instrumentations go here.\nimport { AwsInstrumentation } from '@opentelemetry/instrumentation-aws-sdk';\nimport { ConnectInstrumentation } from '@opentelemetry/instrumentation-connect';\nimport { DnsInstrumentation } from '@opentelemetry/instrumentation-dns';\nimport { ExpressLayerType, ExpressInstrumentation } from '@opentelemetry/instrumentation-express';\nimport { HttpInstrumentation } from '@opentelemetry/instrumentation-http';\nimport { IORedisInstrumentation } from '@opentelemetry/instrumentation-ioredis';\nimport { PgInstrumentation } from '@opentelemetry/instrumentation-pg';\nimport { RedisInstrumentation } from '@opentelemetry/instrumentation-redis';\n\n// Resource detectors go here.\nimport { awsEc2Detector } from '@opentelemetry/resource-detector-aws';\n\n/**\n * Extends `BatchSpanProcessor` to give it the ability to filter out spans\n * before they're queued up to send. This enhances our sampling process so\n * that we can filter spans _after_ they've been emitted.\n */\nclass FilterBatchSpanProcessor extends BatchSpanProcessor {\n private filter: (span: ReadableSpan) => boolean;\n\n constructor(exporter: SpanExporter, filter: (span: ReadableSpan) => boolean) {\n super(exporter);\n this.filter = filter;\n }\n\n /**\n * This is invoked after a span is \"finalized\". `super.onEnd` will queue up\n * the span to be exported, but if we don't call that, we can just drop the\n * span and the parent will be none the wiser!\n */\n onEnd(span: ReadableSpan) {\n if (!this.filter(span)) return;\n\n super.onEnd(span);\n }\n}\n\n/**\n * This will be used with our {@link FilterBatchSpanProcessor} to filter out\n * events that we're not interested in. This helps reduce our event volume\n * but still gives us fine-grained control over which events we keep.\n */\nfunction filter(span: ReadableSpan) {\n if (span.name === 'pg-pool.connect') {\n // Looking at historical data, this generally happens in under a millisecond,\n // precisely because we maintain a pool of long-lived connections. The only\n // time obtaining a client should take longer than that is if we're\n // establishing a connection for the first time, which should happen only at\n // bootup, or if a connection errors out. Those are the cases we're\n // interested in, so we'll filter accordingly.\n return hrTimeToMilliseconds(span.duration) > 1;\n }\n\n // Always return true so that we default to including a span.\n return true;\n}\n\n// When adding new instrumentation here, add the corresponding packages to\n// `commonjs-preloads.ts` so that we can ensure that they're loaded via CJS\n// before anything tries to load them via CJS. This is necessary because the\n// instrumentations can't hook into the ESM loader.\nconst instrumentations = [\n new AwsInstrumentation(),\n new ConnectInstrumentation(),\n new DnsInstrumentation(),\n new ExpressInstrumentation({\n // We use a lot of middleware; it makes the traces way too noisy. If we\n // want telemetry on a particular middleware, we should instrument it\n // manually.\n ignoreLayersType: [ExpressLayerType.MIDDLEWARE],\n ignoreLayers: [\n // These don't provide useful information to us.\n 'router - /',\n 'request handler - /*',\n ],\n }),\n new HttpInstrumentation({\n ignoreIncomingPaths: [\n // socket.io requests are generally just long-polling; they don't add\n // useful information for us.\n /\\/socket.io\\//,\n // We get several of these per second; they just chew through our event quota.\n // They don't really do anything interesting anyways.\n /\\/pl\\/webhooks\\/ping/,\n ],\n }),\n new IORedisInstrumentation(),\n new PgInstrumentation(),\n new RedisInstrumentation(),\n];\n\n// Enable all instrumentations now, even though we haven't configured our\n// span processors or trace exporters yet. We'll set those up later.\ninstrumentations.forEach((i) => {\n i.enable();\n});\n\nlet tracerProvider: NodeTracerProvider | null;\n\ninterface OpenTelemetryConfigEnabled {\n openTelemetryEnabled: boolean;\n openTelemetryExporter?: 'console' | 'honeycomb' | 'jaeger' | SpanExporter | null;\n openTelemetryMetricExporter?: 'console' | 'honeycomb' | PushMetricExporter | null;\n openTelemetryMetricExportIntervalMillis?: number;\n openTelemetrySamplerType: 'always-on' | 'always-off' | 'trace-id-ratio';\n openTelemetrySampleRate?: number;\n openTelemetrySpanProcessor?: 'batch' | 'simple' | SpanProcessor;\n honeycombApiKey?: string | null;\n honeycombDataset?: string | null;\n serviceName?: string;\n}\n\n// When we know for sure that OpenTelemetry is disabled, we won't require\n// any other attributes to be set.\ninterface OpenTelemetryConfigDisabled extends Partial<OpenTelemetryConfigEnabled> {\n openTelemetryEnabled: false;\n}\n\nexport type OpenTelemetryConfig = OpenTelemetryConfigEnabled | OpenTelemetryConfigDisabled;\n\nfunction getHoneycombMetadata(config: OpenTelemetryConfig, datasetSuffix = ''): Metadata {\n if (!config.honeycombApiKey) throw new Error('Missing Honeycomb API key');\n if (!config.honeycombDataset) throw new Error('Missing Honeycomb dataset');\n\n const metadata = new Metadata();\n\n metadata.set('x-honeycomb-team', config.honeycombApiKey);\n metadata.set('x-honeycomb-dataset', config.honeycombDataset + datasetSuffix);\n\n return metadata;\n}\n\nfunction getTraceExporter(config: OpenTelemetryConfig): SpanExporter | null {\n if (!config.openTelemetryExporter) return null;\n\n if (typeof config.openTelemetryExporter === 'object') {\n return config.openTelemetryExporter;\n }\n\n switch (config.openTelemetryExporter) {\n case 'console':\n return new ConsoleSpanExporter();\n case 'honeycomb':\n return new OTLPTraceExporter({\n url: 'grpc://api.honeycomb.io:443/',\n credentials: credentials.createSsl(),\n metadata: getHoneycombMetadata(config),\n });\n break;\n case 'jaeger':\n return new OTLPTraceExporterHttp();\n default:\n throw new Error(`Unknown OpenTelemetry exporter: ${config.openTelemetryExporter}`);\n }\n}\n\nfunction getMetricExporter(config: OpenTelemetryConfig): PushMetricExporter | null {\n if (!config.openTelemetryMetricExporter) return null;\n\n if (typeof config.openTelemetryMetricExporter === 'object') {\n return config.openTelemetryMetricExporter;\n }\n\n switch (config.openTelemetryMetricExporter) {\n case 'console':\n return new ConsoleMetricExporter();\n case 'honeycomb':\n return new OTLPMetricExporter({\n url: 'grpc://api.honeycomb.io:443/',\n credentials: credentials.createSsl(),\n // Honeycomb recommends using a separate dataset for metrics, so we'll\n // adopt the convention of appending '-metrics' to the dataset name.\n metadata: getHoneycombMetadata(config, '-metrics'),\n // Delta temporality means that sums, histograms, etc. will reset each\n // time data is collected. This more closely matches how we want to\n // observe our metrics than the default cumulative temporality.\n temporalityPreference: AggregationTemporality.DELTA,\n });\n default:\n throw new Error(\n `Unknown OpenTelemetry metric exporter: ${config.openTelemetryMetricExporter}`,\n );\n }\n}\n\nfunction getSpanProcessor(config: OpenTelemetryConfig): SpanProcessor | null {\n if (typeof config.openTelemetrySpanProcessor === 'object') {\n return config.openTelemetrySpanProcessor;\n }\n\n const traceExporter = getTraceExporter(config);\n if (!traceExporter) return null;\n\n switch (config.openTelemetrySpanProcessor ?? 'batch') {\n case 'batch': {\n return new FilterBatchSpanProcessor(traceExporter, filter);\n }\n case 'simple': {\n return new SimpleSpanProcessor(traceExporter);\n }\n default: {\n throw new Error(`Unknown OpenTelemetry span processor: ${config.openTelemetrySpanProcessor}`);\n }\n }\n}\n\n/**\n * Should be called once we've loaded our config; this will allow us to set up\n * the correct metadata for the Honeycomb exporter. We don't actually have that\n * information available until we've loaded our config.\n */\nexport async function init(config: OpenTelemetryConfig) {\n if (!config.openTelemetryEnabled) {\n // If not enabled, do nothing. We used to disable the instrumentations, but\n // per maintainers, that can actually be problematic. See the comments on\n // https://github.com/open-telemetry/opentelemetry-js-contrib/issues/970\n // The Express instrumentation also logs a benign error, which can be\n // confusing to users. There's a fix in progress if we want to switch back\n // to disabling instrumentations in the future:\n // https://github.com/open-telemetry/opentelemetry-js-contrib/pull/972\n return;\n }\n\n const metricExporter = getMetricExporter(config);\n const spanProcessor = getSpanProcessor(config);\n\n let sampler: Sampler;\n switch (config.openTelemetrySamplerType ?? 'always-on') {\n case 'always-on': {\n sampler = new AlwaysOnSampler();\n break;\n }\n case 'always-off': {\n sampler = new AlwaysOffSampler();\n break;\n }\n case 'trace-id-ratio': {\n sampler = new ParentBasedSampler({\n root: new TraceIdRatioBasedSampler(config.openTelemetrySampleRate),\n });\n break;\n }\n default:\n throw new Error(`Unknown OpenTelemetry sampler type: ${config.openTelemetrySamplerType}`);\n }\n\n // Much of this functionality is copied from `@opentelemetry/sdk-node`, but\n // we can't use the SDK directly because of the fact that we load our config\n // asynchronously. We need to initialize our instrumentations first; only\n // then can we actually start requiring all of our code that loads our config\n // and ultimately tells us how to configure OpenTelemetry.\n\n let resource = detectResourcesSync({\n detectors: [awsEc2Detector, processDetector, envDetector],\n });\n\n if (config.serviceName) {\n resource = resource.merge(\n new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: config.serviceName }),\n );\n }\n\n // Set up tracing instrumentation.\n const nodeTracerProvider = new NodeTracerProvider({\n sampler,\n resource,\n });\n if (spanProcessor) {\n nodeTracerProvider.addSpanProcessor(spanProcessor);\n }\n nodeTracerProvider.register();\n instrumentations.forEach((i) => i.setTracerProvider(nodeTracerProvider));\n\n // Save the provider so we can shut it down later.\n tracerProvider = nodeTracerProvider;\n\n // Set up metrics instrumentation if it's enabled.\n if (metricExporter) {\n const meterProvider = new MeterProvider({\n resource,\n readers: [\n new PeriodicExportingMetricReader({\n exporter: metricExporter,\n exportIntervalMillis: config.openTelemetryMetricExportIntervalMillis ?? 30_000,\n }),\n ],\n });\n metrics.setGlobalMeterProvider(meterProvider);\n }\n}\n\n/**\n * Gracefully shuts down the OpenTelemetry instrumentation. Should be called\n * when a `SIGTERM` signal is handled.\n */\nexport async function shutdown(): Promise<void> {\n if (tracerProvider) {\n await tracerProvider.shutdown();\n tracerProvider = null;\n }\n}\n\n/**\n * Disables all OpenTelemetry instrumentations. This is useful for tests that\n * need to access the unwrapped modules.\n */\nexport function disableInstrumentations() {\n instrumentations.forEach((i) => i.disable());\n}\n"]}
package/dist/metrics.d.ts CHANGED
@@ -6,7 +6,7 @@ export declare function getObservableCounter(meter: Meter, name: string, options
6
6
  export declare function getObservableUpDownCounter(meter: Meter, name: string, options?: MetricOptions): ObservableUpDownCounter<import("@opentelemetry/api").Attributes>;
7
7
  export declare function getObservableGauge(meter: Meter, name: string, options?: MetricOptions): ObservableGauge<import("@opentelemetry/api").Attributes>;
8
8
  export declare function instrumentedWithMetrics<T>(meter: Meter, name: string, fn: () => Promise<T> | T): Promise<T>;
9
- export interface createObservableValueGaugesOptions extends MetricOptions {
9
+ export interface CreateObservableValueGaugesOptions extends MetricOptions {
10
10
  interval: number;
11
11
  }
12
12
  /**
@@ -20,7 +20,7 @@ export interface createObservableValueGaugesOptions extends MetricOptions {
20
20
  * - `${name}.max`
21
21
  * - `${name}.avg`
22
22
  */
23
- export declare function createObservableValueGauges(meter: Meter, name: string, options: createObservableValueGaugesOptions, observe: () => number): {
23
+ export declare function createObservableValueGauges(meter: Meter, name: string, options: CreateObservableValueGaugesOptions, observe: () => number): {
24
24
  minGauge: ObservableGauge<import("@opentelemetry/api").Attributes>;
25
25
  maxGauge: ObservableGauge<import("@opentelemetry/api").Attributes>;
26
26
  averageGauge: ObservableGauge<import("@opentelemetry/api").Attributes>;
package/dist/metrics.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createObservableValueGauges = exports.instrumentedWithMetrics = exports.getObservableGauge = exports.getObservableUpDownCounter = exports.getObservableCounter = exports.getUpDownCounter = exports.getCounter = exports.getHistogram = void 0;
4
- const api_1 = require("@opentelemetry/api");
1
+ import { ValueType, } from '@opentelemetry/api';
5
2
  const histogramCache = new WeakMap();
6
3
  const counterCache = new WeakMap();
7
4
  const upDownCounterCache = new WeakMap();
@@ -21,35 +18,29 @@ function getCachedMetric(cache, meter, name, create) {
21
18
  }
22
19
  return metric;
23
20
  }
24
- function getHistogram(meter, name, options) {
21
+ export function getHistogram(meter, name, options) {
25
22
  return getCachedMetric(histogramCache, meter, name, () => meter.createHistogram(name, options));
26
23
  }
27
- exports.getHistogram = getHistogram;
28
- function getCounter(meter, name, options) {
24
+ export function getCounter(meter, name, options) {
29
25
  return getCachedMetric(counterCache, meter, name, () => meter.createCounter(name, options));
30
26
  }
31
- exports.getCounter = getCounter;
32
- function getUpDownCounter(meter, name, options) {
27
+ export function getUpDownCounter(meter, name, options) {
33
28
  return getCachedMetric(upDownCounterCache, meter, name, () => meter.createUpDownCounter(name, options));
34
29
  }
35
- exports.getUpDownCounter = getUpDownCounter;
36
- function getObservableCounter(meter, name, options) {
30
+ export function getObservableCounter(meter, name, options) {
37
31
  return getCachedMetric(observableCounterCache, meter, name, () => meter.createObservableCounter(name, options));
38
32
  }
39
- exports.getObservableCounter = getObservableCounter;
40
- function getObservableUpDownCounter(meter, name, options) {
33
+ export function getObservableUpDownCounter(meter, name, options) {
41
34
  return getCachedMetric(observableUpDownCounterCache, meter, name, () => meter.createObservableUpDownCounter(name, options));
42
35
  }
43
- exports.getObservableUpDownCounter = getObservableUpDownCounter;
44
- function getObservableGauge(meter, name, options) {
36
+ export function getObservableGauge(meter, name, options) {
45
37
  return getCachedMetric(observableGaugeCache, meter, name, () => meter.createObservableGauge(name, options));
46
38
  }
47
- exports.getObservableGauge = getObservableGauge;
48
- async function instrumentedWithMetrics(meter, name, fn) {
49
- const error = getCounter(meter, `${name}.error`, { valueType: api_1.ValueType.INT });
39
+ export async function instrumentedWithMetrics(meter, name, fn) {
40
+ const error = getCounter(meter, `${name}.error`, { valueType: ValueType.INT });
50
41
  const histogram = getHistogram(meter, `${name}.duration`, {
51
42
  unit: 'milliseconds',
52
- valueType: api_1.ValueType.DOUBLE,
43
+ valueType: ValueType.DOUBLE,
53
44
  });
54
45
  const start = performance.now();
55
46
  try {
@@ -63,7 +54,6 @@ async function instrumentedWithMetrics(meter, name, fn) {
63
54
  histogram.record(performance.now() - start);
64
55
  }
65
56
  }
66
- exports.instrumentedWithMetrics = instrumentedWithMetrics;
67
57
  /**
68
58
  * Creates a set of gauges that track the min, max, and average of a value over
69
59
  * time. The value is observed on a regular interval.
@@ -75,7 +65,7 @@ exports.instrumentedWithMetrics = instrumentedWithMetrics;
75
65
  * - `${name}.max`
76
66
  * - `${name}.avg`
77
67
  */
78
- function createObservableValueGauges(meter, name, options, observe) {
68
+ export function createObservableValueGauges(meter, name, options, observe) {
79
69
  const { interval, ...metricOptions } = options;
80
70
  let min = 0;
81
71
  let max = 0;
@@ -99,7 +89,7 @@ function createObservableValueGauges(meter, name, options, observe) {
99
89
  const averageGauge = getObservableGauge(meter, `${name}.avg`, {
100
90
  ...metricOptions,
101
91
  // Average is always a double, even if the observed value is an int.
102
- valueType: api_1.ValueType.DOUBLE,
92
+ valueType: ValueType.DOUBLE,
103
93
  });
104
94
  minGauge.addCallback((observableResult) => {
105
95
  observableResult.observe(min);
@@ -117,5 +107,4 @@ function createObservableValueGauges(meter, name, options, observe) {
117
107
  });
118
108
  return { minGauge, maxGauge, averageGauge, stop: () => clearInterval(intervalId) };
119
109
  }
120
- exports.createObservableValueGauges = createObservableValueGauges;
121
110
  //# sourceMappingURL=metrics.js.map