{"id":20419398,"url":"https://github.com/risingstack/opentracing-metrics-tracer","last_synced_at":"2025-04-12T17:41:14.221Z","repository":{"id":80615895,"uuid":"102188868","full_name":"RisingStack/opentracing-metrics-tracer","owner":"RisingStack","description":"Exports cross-process metrics via OpenTracing to Prometheus.","archived":false,"fork":false,"pushed_at":"2018-03-06T07:01:15.000Z","size":76,"stargazers_count":13,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T06:41:41.650Z","etag":null,"topics":["node","nodejs","opentracing","prometheus","prometheus-exporter","tracer"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RisingStack.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-09-02T10:21:57.000Z","updated_at":"2022-11-03T23:52:36.000Z","dependencies_parsed_at":"2023-04-07T09:00:58.552Z","dependency_job_id":null,"html_url":"https://github.com/RisingStack/opentracing-metrics-tracer","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Fopentracing-metrics-tracer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Fopentracing-metrics-tracer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Fopentracing-metrics-tracer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Fopentracing-metrics-tracer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RisingStack","download_url":"https://codeload.github.com/RisingStack/opentracing-metrics-tracer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248607813,"owners_count":21132614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["node","nodejs","opentracing","prometheus","prometheus-exporter","tracer"],"created_at":"2024-11-15T06:36:48.506Z","updated_at":"2025-04-12T17:41:14.200Z","avatar_url":"https://github.com/RisingStack.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# opentracing-metrics-tracer\n\n[![Build Status](https://travis-ci.org/RisingStack/opentracing-metrics-tracer.svg?branch=master)](https://travis-ci.org/RisingStack/opentracing-metrics-tracer)  \n\nExports cross-process metrics via OpenTracing instrumentation to reporters: Prometheus.  \nIt's capable to measure operation characteristics in a distributed system like microservices.  \n\nIt also makes possible to reverse engineer the infrastructure topology as we know the initiators\n\n## Available Reporters\n\n- [Prometheus](https://prometheus.io/) via [prom-client](https://github.com/siimon/prom-client)\n\n## Getting started\n\n```js\nconst MetricsTracer = require('@risingstack/opentracing-metrics-tracer')\nconst prometheusReporter = new MetricsTracer.PrometheusReporter()\nconst metricsTracer = new MetricsTracer('my-service', [prometheusReporter])\n\n// Instrument\nconst span = metricsTracer.startSpan('my-operation')\nspan.finish()\n...\n\napp.get('/metrics', (req, res) =\u003e {\n  res.set('Content-Type', MetricsTracer.PrometheusReporter.Prometheus.register.contentType)\n  res.end(prometheusReporter.metrics())\n})\n```\n\n### With auto instrumentation and multiple tracers\n\nCheck out: https://github.com/RisingStack/opentracing-auto\n\n```js\n// Prometheus metrics tracer\nconst MetricsTracer = require('@risingstack/opentracing-metrics-tracer')\nconst prometheusReporter = new MetricsTracer.PrometheusReporter()\nconst metricsTracer = new MetricsTracer('my-service', [prometheusReporter])\n\n// Jaeger tracer (classic distributed tracing)\nconst jaeger = require('jaeger-client')\nconst UDPSender = require('jaeger-client/dist/src/reporters/udp_sender').default\nconst sampler = new jaeger.RateLimitingSampler(1)\nconst reporter = new jaeger.RemoteReporter(new UDPSender())\nconst jaegerTracer = new jaeger.Tracer('my-server-pg', reporter, sampler)\n\n// Auto instrumentation\nconst Instrument = require('@risingstack/opentracing-auto')\nconst instrument = new Instrument({\n  tracers: [metricsTracer, jaegerTracer]\n})\n\n// Rest of your code\nconst express = require('express')\nconst app = express()\n\napp.get('/metrics', (req, res) =\u003e {\n  res.set('Content-Type', MetricsTracer.PrometheusReporter.Prometheus.register.contentType)\n  res.end(prometheusReporter.metrics())\n})\n```\n\n### Example\n\nSee [example server](/example/server.js).\n\n```sh\nnode example/server\ncurl http://localhost:3000\ncurl http://localhost:3000/metrics\n```\n\n## API\n\n`const Tracer = require('@risingstack/opentracing-metrics-tracer')`\n\n### new Tracer(serviceKey, [reporter1, reporter2, ...])\n\n- **serviceKey** *String*, *required*, unique key that identifies a specific type of service *(for example: my-frontend-api)*\n- **reporters** *Array of reporters*, *optional*, *default:* []\n\n[OpenTracing](https://github.com/opentracing/opentracing-javascript) compatible tracer, for the complete API check out the official [documentation](https://opentracing-javascript.surge.sh/).\n\n### new Tracer.PrometheusReporter([opts])\n\n- **opts** *Object*, *optional*\n- **opts.ignoreTags** *Object*, *optional*\n  - Example: `{ ignoreTags: { [Tags.HTTP_URL]: /\\/metrics$/ } }` to ignore Prometheus scraper\n\nCreates a new Prometheus reporter.\n\n### Tracer.PrometheusReporter.Prometheus\n\nExposed [prom-client](https://github.com/siimon/prom-client).\n\n## Reporters\n\n### Prometheus Reporter\n\nExposes metrics in Prometheus format via [prom-client](https://github.com/siimon/prom-client)\n\n#### Metrics\n\n- [operation_duration_seconds](#operation_duration_seconds)\n- [http_request_duration_seconds](#http_request_duration_seconds)\n\n##### operation_duration_seconds\n\nAlways measured.  \nSample output: Two distributed services communicate over the network.\n\n```\n# HELP operation_duration_seconds Duration of operations in second\n# TYPE operation_duration_seconds histogram\noperation_duration_seconds_bucket{le=\"0.005\",parent_service=\"my-parent-service\",name=\"my-operation\" 0\noperation_duration_seconds_bucket{le=\"0.01\",parent_service=\"my-parent-service\",name=\"my-operation\" 0\noperation_duration_seconds_bucket{le=\"0.025\",parent_service=\"my-parent-service\",name=\"my-operation\" 0\noperation_duration_seconds_bucket{le=\"0.05\",parent_service=\"my-parent-service\",name=\"my-operation\" 0\noperation_duration_seconds_bucket{le=\"0.1\",parent_service=\"my-parent-service\",name=\"my-operation\" 1\noperation_duration_seconds_bucket{le=\"0.25\",parent_service=\"my-parent-service\",name=\"my-operation\" 1\noperation_duration_seconds_bucket{le=\"0.5\",parent_service=\"my-parent-service\",name=\"my-operation\" 2\noperation_duration_seconds_bucket{le=\"1\",parent_service=\"my-parent-service\",name=\"my-operation\" 2\noperation_duration_seconds_bucket{le=\"2.5\",parent_service=\"my-parent-service\",name=\"my-operation\" 2\noperation_duration_seconds_bucket{le=\"5\",parent_service=\"my-parent-service\",name=\"my-operation\" 2\noperation_duration_seconds_bucket{le=\"10\",parent_service=\"my-parent-service\",name=\"my-operation\" 2\noperation_duration_seconds_bucket{le=\"+Inf\",parent_service=\"my-parent-service\",name=\"my-operation\" 2\noperation_duration_seconds_sum{parent_service=\"my-parent-service\",name=\"my-operation\" 0.4\noperation_duration_seconds_count{parent_service=\"my-parent-service\",name=\"my-operation\" 2\n```\n\n##### http_request_duration_seconds\n\nMeasured only when the span is tagged with `SPAN_KIND_RPC_SERVER` and any of `HTTP_URL`, `HTTP_METHOD` or `HTTP_STATUS_CODE`.  \nSample output:\n```\n# HELP http_request_handler_duration_seconds Duration of HTTP requests in second\n# TYPE http_request_handler_duration_seconds histogram\nhttp_request_handler_duration_seconds_bucket{le=\"0.005\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 0\nhttp_request_handler_duration_seconds_bucket{le=\"0.01\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 0\nhttp_request_handler_duration_seconds_bucket{le=\"0.025\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 0\nhttp_request_handler_duration_seconds_bucket{le=\"0.05\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 0\nhttp_request_handler_duration_seconds_bucket{le=\"0.1\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 1\nhttp_request_handler_duration_seconds_bucket{le=\"0.25\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 1\nhttp_request_handler_duration_seconds_bucket{le=\"0.5\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 2\nhttp_request_handler_duration_seconds_bucket{le=\"1\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 2\nhttp_request_handler_duration_seconds_bucket{le=\"2.5\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 2\nhttp_request_handler_duration_seconds_bucket{le=\"5\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 2\nhttp_request_handler_duration_seconds_bucket{le=\"10\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 2\nhttp_request_handler_duration_seconds_bucket{le=\"+Inf\",parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 2\nhttp_request_handler_duration_seconds_sum{parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 0.4\nhttp_request_handler_duration_seconds_count{parent_service=\"my-parent-service\",method=\"GET\",code=\"200\",name=\"http_request\" 2\n```\n\n## Future and ideas\n\nThis library is new, in the future we could measure much more useful and specific metrics with it.  \nPlease share your ideas in a form of issues or pull-requests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frisingstack%2Fopentracing-metrics-tracer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frisingstack%2Fopentracing-metrics-tracer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frisingstack%2Fopentracing-metrics-tracer/lists"}