{"name":"@opentelemetry/sdk-metrics","version":"2.6.0","keywords":["opentelemetry","nodejs","metrics","stats","profiling"],"author":{"name":"OpenTelemetry Authors"},"license":"Apache-2.0","_id":"@opentelemetry/sdk-metrics@2.6.0","maintainers":[{"name":"dyladan","email":"dyladan@gmail.com"},{"name":"pichlermarc","email":"marc.pichler@dynatrace.com"}],"homepage":"https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/sdk-metrics","bugs":{"url":"https://github.com/open-telemetry/opentelemetry-js/issues"},"dist":{"shasum":"c9f63eb68a5c7600a4ffc84bdce3ef59c9b1af47","tarball":"http://registry-npm.ywwl.com/@opentelemetry/sdk-metrics/download/@opentelemetry/sdk-metrics-2.6.0.tgz","fileCount":579,"integrity":"sha512-CicxWZxX6z35HR83jl+PLgtFgUrKRQ9LCXyxgenMnz5A1lgYWfAog7VtdOvGkJYyQgMNPhXQwkYrDLujk7z1Iw==","signatures":[{"sig":"MEYCIQD+0BMMkotRzh3L6NIgznoR35nGCQiCBk0yU1Emr9aoTAIhAOBTNQW1A4LB7x1vN58Z61rSS8dU8ydqfNjtODw3/sRc","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@opentelemetry%2fsdk-metrics@2.6.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":1698907,"size":167688,"noattachment":false,"key":"/@opentelemetry/sdk-metrics/-/@opentelemetry/sdk-metrics-2.6.0.tgz"},"main":"build/src/index.js","types":"build/src/index.d.ts","esnext":"build/esnext/index.js","module":"build/esm/index.js","engines":{"node":"^18.19.0 || >=20.6.0"},"gitHead":"541e1b4ad83ad2093459794a18283228fe58d199","scripts":{"tdd":"npm run test -- --watch-extensions ts --watch","lint":"eslint . --ext .ts","test":"nyc mocha 'test/**/*.test.ts'","clean":"tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json","watch":"tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json","compile":"tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json","version":"node ../../scripts/version-update.js","lint:fix":"eslint . --ext .ts --fix","prewatch":"node ../../scripts/version-update.js","tdd:browser":"karma start","test:browser":"karma start --single-run","align-api-deps":"node ../../scripts/align-api-deps.js","peer-api-check":"node ../../scripts/peer-api-check.js","prepublishOnly":"npm run compile"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:579331b4-3444-4018-9fae-315393f82057"}},"repository":{"url":"git+https://github.com/open-telemetry/opentelemetry-js.git","type":"git"},"_npmVersion":"lerna/9.0.4/node@v24.13.1+x64 (linux)","description":"OpenTelemetry metrics SDK","directories":{},"sideEffects":false,"_nodeVersion":"24.13.1","dependencies":{"@opentelemetry/core":"2.6.0","@opentelemetry/resources":"2.6.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"17.1.0","karma":"6.4.4","mocha":"11.7.5","sinon":"18.0.1","webpack":"5.104.1","ts-loader":"9.5.4","typescript":"5.0.4","@babel/core":"7.27.1","@types/node":"18.19.130","karma-mocha":"2.0.1","webpack-cli":"6.0.1","@types/mocha":"10.0.10","@types/sinon":"17.0.4","karma-webpack":"5.0.1","karma-coverage":"2.2.1","@babel/preset-env":"7.27.2","@opentelemetry/api":">=1.9.0 <1.10.0","karma-spec-reporter":"0.0.36","babel-plugin-istanbul":"7.0.1","karma-chrome-launcher":"3.1.0"},"peerDependencies":{"@opentelemetry/api":">=1.9.0 <1.10.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk-metrics_2.6.0_1772577318774_0.07799263658486821","host":"s3://npm-registry-packages-npm-production"},"readme":"# OpenTelemetry Metrics SDK\n\n[![NPM Published Version][npm-img]][npm-url]\n[![Apache License][license-image]][license-image]\n\nThis module contains the Metrics SDK of [opentelemetry-js](https://github.com/open-telemetry/opentelemetry-js).\n\nUsed standalone, this module provides methods for manual instrumentation of code, offering full control over recording metrics for client-side JavaScript (browser) and Node.js.\n\nIt does **not** provide automated instrumentation of known libraries or host environment metrics out-of-the-box.\n\n## Installation\n\n```bash\nnpm install --save @opentelemetry/api\nnpm install --save @opentelemetry/sdk-metrics\n```\n\n## Usage\n\nThe basic setup of the SDK can be seen as followings:\n\n```js\nconst opentelemetry = require('@opentelemetry/api');\nconst { MeterProvider } = require('@opentelemetry/sdk-metrics');\n\n// To create an instrument, you first need to initialize the Meter provider.\n// NOTE: The default OpenTelemetry meter provider does not record any metric instruments.\n//       Registering a working meter provider allows the API methods to record instruments.\nopentelemetry.metrics.setGlobalMeterProvider(new MeterProvider());\n\n// To record a metric event, we used the global singleton meter to create an instrument.\nconst counter = opentelemetry.metrics.getMeter('default').createCounter('foo');\n\n// record a metric event.\n// NOTE: By default, each instrument can track up to 2000 unique time series.\n//       This can be configured using cardinalityLimits. See \"Configuring Cardinality Limits\" below.\ncounter.add(1, { attributeKey: 'attribute-value' });\n```\n\nIn conditions, we may need to setup an async instrument to observe costly events:\n\n```js\n// Creating an async instrument, similar to synchronous instruments\nconst observableCounter = opentelemetry.metrics\n  .getMeter('default')\n  .createObservableCounter('observable-counter');\n\n// Register a single-instrument callback to the async instrument.\nobservableCounter.addCallback(async observableResult => {\n  // ... do async stuff\n  observableResult.observe(1, { attributeKey: 'attribute-value' });\n});\n\n// Register a multi-instrument callback and associate it with a set of async instruments.\nopentelemetry.metrics\n  .getMeter('default')\n  .addBatchObservableCallback(batchObservableCallback, [observableCounter]);\nasync function batchObservableCallback(batchObservableResult) {\n  // ... do async stuff\n  batchObservableResult.observe(observableCounter, 1, {\n    attributeKey: 'attribute-value',\n  });\n}\n```\n\nViews can be registered when instantiating a `MeterProvider`:\n\n```js\nconst meterProvider = new MeterProvider({\n  views: [\n    // override the bucket boundaries on `my.histogram` to [0, 50, 100]\n    {\n      aggregation: {\n        type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,\n        options: {\n          boundaries: [0, 50, 100],\n        },\n      },\n      instrumentName: 'my.histogram',\n    },\n    // rename 'my.counter' to 'my.renamed.counter'\n    { name: 'my.renamed.counter', instrumentName: 'my.counter' },\n  ],\n});\n```\n\n## Configuring Cardinality Limits\n\nThe `cardinalityLimits` is an optional property in `PeriodicExportingMetricReader` that allows configuration of the maximum cardinality limits per instrument type (`InstrumentType`). This limit controls the maximum number of unique time series that can be tracked for each metric instrument. If not specified in the property, the limit will default to 2000 (the default value can also be specified).\n\nIt is converted to a `cardinalitySelector` function that:\n\n- Takes an `InstrumentType` as input\n- Returns the configured cardinality limit for that instrument type\n- Falls back to the default value if a specific type isn't configured\n- Uses 2000 as the default if the default value is also not specified\n\nIf the `cardinalityLimits` property is omitted:\n\n```js\nimport { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';\nimport { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';\n\nconst exporter = new OTLPMetricExporter();\nconst reader = new PeriodicExportingMetricReader({\n  exporter,\n  exportIntervalMillis: 60000,\n});\n\n// All instruments will use the default limit of 2000 time series\n```\n\nConfiguring specific instrument types:\n\n```js\nconst reader = new PeriodicExportingMetricReader({\n  exporter,\n  exportIntervalMillis: 60000,\n  cardinalityLimits: {\n    counter: 10000, // Counters can have up to 10,000 time series\n    histogram: 5000, // Histograms limited to 5,000 time series\n    gauge: 3000, // Gauges limited to 3,000 time series\n    default: 2500, // changes the default from 2000 to 2500\n  },\n});\n```\n\nAvailable configuration options:\n\n```js\ntype cardinalityLimits = {\n  counter?: number;\n  gauge?: number;\n  histogram?: number;\n  upDownCounter?: number;\n  observableCounter?: number;\n  observableGauge?: number;\n  observableUpDownCounter?: number;\n  default?: number;\n};\n```\n\n## Example\n\nSee [examples/prometheus](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/examples/prometheus) for an end-to-end example, including exporting metrics.\n\n## Useful links\n\n- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>\n- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>\n- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]\n\n## License\n\nApache 2.0 - See [LICENSE][license-url] for more information.\n\n[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions\n[license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/main/LICENSE\n[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat\n[npm-url]: https://www.npmjs.com/package/@opentelemetry/sdk-metrics\n[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fsdk%2Dmetrics.svg\n","publish_time":1772577319036,"_cnpm_publish_time":1772577319036,"dist-tags":{"canary":"3.0.0-rc.0","latest":"3.1.0","next":"1.8.0"}}