{"id":15137800,"url":"https://github.com/discue/open-telemetry-tracing","last_synced_at":"2026-03-06T07:32:26.903Z","repository":{"id":195405651,"uuid":"692664583","full_name":"discue/open-telemetry-tracing","owner":"discue","description":"Simple access to tracing with OpenTelemetry","archived":false,"fork":false,"pushed_at":"2026-02-27T20:04:13.000Z","size":1583,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-28T00:32:44.558Z","etag":null,"topics":["cloud-run","discue","google-cloud","google-cloud-platform","open-telemetry","open-telemetry-js","open-telemetry-node","tracing","tracing-library"],"latest_commit_sha":null,"homepage":"https://www.discue.io","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/discue.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-09-17T07:40:29.000Z","updated_at":"2026-02-27T20:03:05.000Z","dependencies_parsed_at":"2023-09-17T20:17:45.439Z","dependency_job_id":"832390aa-9b66-4d13-987d-092cbd7b6afc","html_url":"https://github.com/discue/open-telemetry-tracing","commit_stats":null,"previous_names":["discue/open-telemetry-tracing"],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/discue/open-telemetry-tracing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discue%2Fopen-telemetry-tracing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discue%2Fopen-telemetry-tracing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discue%2Fopen-telemetry-tracing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discue%2Fopen-telemetry-tracing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/discue","download_url":"https://codeload.github.com/discue/open-telemetry-tracing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discue%2Fopen-telemetry-tracing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30165627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T04:43:31.446Z","status":"ssl_error","status_checked_at":"2026-03-06T04:40:30.133Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cloud-run","discue","google-cloud","google-cloud-platform","open-telemetry","open-telemetry-js","open-telemetry-node","tracing","tracing-library"],"created_at":"2024-09-26T07:02:07.573Z","updated_at":"2026-03-06T07:32:26.872Z","avatar_url":"https://github.com/discue.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.discue.io/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\u003cimg width=\"128\" src=\"https://www.discue.io/icons-fire-no-badge-square/web/icon-192.png\" alt=\"Vue logo\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr/\u003e\n\u003cdiv align=\"center\"\u003e\n\n[![GitHub tag](https://img.shields.io/github/tag/discue/open-telemetry-tracing?include_prereleases=\u0026sort=semver\u0026color=blue)](https://github.com/discue/open-telemetry-tracing/releases/)\n[![Latest Stable Version](https://img.shields.io/npm/v/@discue/open-telemetry-tracing.svg)](https://www.npmjs.com/package/@discue/open-telemetry-tracing)\n[![License](https://img.shields.io/npm/l/@discue/open-telemetry-tracing.svg)](https://www.npmjs.com/package/@discue/open-telemetry-tracing)\n\u003cbr/\u003e\n[![NPM Downloads](https://img.shields.io/npm/dt/@discue/open-telemetry-tracing.svg)](https://www.npmjs.com/package/@discue/open-telemetry-tracing)\n[![NPM Downloads](https://img.shields.io/npm/dm/@discue/open-telemetry-tracing.svg)](https://www.npmjs.com/package/@discue/open-telemetry-tracing)\n\u003cbr/\u003e\n[![contributions - welcome](https://img.shields.io/badge/contributions-welcome-blue)](/CONTRIBUTING.md \"Go to contributions doc\")\n[![Made with Node.js](https://img.shields.io/badge/Node.js-\u003e=18-blue?logo=node.js\u0026logoColor=white)](https://nodejs.org \"Go to Node.js homepage\")\n\n\u003c/div\u003e\n\n# open-telemetry-tracing\nKickstarts your [OpenTelemetry](https://opentelemetry.io/docs/instrumentation/js/getting-started/nodejs/) implementation with first-class abstractions for\n- adding tracing capabilities to NodeJS environments\n- collecting and publishing of spans to local and cloud environments\n- creating spans and child spans\n- tracking successful completion of spans\n- recording exceptions in case of errors during span execution\n\n![Screenshot of traces collected by Jaeger.](traces.png)\n\n## Setup\n[OpenTelemetry](https://opentelemetry.io/docs/instrumentation/js/getting-started/nodejs/) and its [Instrumentations](https://opentelemetry.io/docs/instrumentation/js/libraries/) will inject tracing functionality into well-known and supported packages. \n\nTo enable tracing, the tracing runtime needs to be loaded **before** your application. To do so, set the `NODE_OPTIONS` environment variable and `require` the file `node_modules/@discue/open-telemetry-tracing/lib/instrumentation.cjs`, which is the entry point for tracing.\n- `NODE_OPTIONS=--require node_modules/@discue/open-telemetry-tracing/lib/instrumentation.cjs`\n\n## Instrumentation\n[Instrumentations](https://opentelemetry.io/docs/instrumentation/js/libraries/) are the heart of tracing. Most of the tracing instrumentation is platform-agnostic. However, some parts of it can be platform-dependent.\n\nThis module features support for GCP and half-baked support for AWS (due to lack of usage of the platform in other projects). You can find the default instrumentations here:\n- [Amazon Web Services](lib/tracing/aws-lambda/aws-instrumentations.cjs)\n- [Google Cloud Run](lib/tracing/gcp-cloud-run/gcp-instrumentations.cjs)\n- [Localhost / Development](lib/tracing/gcp-cloud-run/gcp-instrumentations.cjs)\n\nIf you feel instrumentations (or other features) are missing, please get in touch with us and / or open a PR 🙂.\n\n## How to create a span\n\nImport the function `createTracer` function.\n```js\nimport { createTracer } from '@discue/open-telemetry-tracing';\n```\n\nCall the function `createTracer` and pass the `filepath` to the current file as an optional parameter.\n```js\nconst { withActiveSpan } = createTracer({\n    filepath: import.meta.url\n})\n```\n\nWrap existing or new code inside a call to `withActiveSpan`. You can add `spanEvents` to add additional information for later analysis.\n```js\n/**\n * \n * @param {_types.Request} req \n * @param {_types.Response} res \n * @param {Object} options\n * @returns \n */\nasync handleRequest(req, res, { resourceIds }) {\n    // creates a new active span with name handle-delete-request\n    // will watch execution and record failures\n    //\n    // pass an object with additional attributes as second parameter\n    // to get more key value pairs added to the span\n    await withActiveSpan('handle-delete-request', async (span) =\u003e {\n        const resource = await this._service.get(resourceIds)\n        if (resource == null) {\n            // custom extension of the span with implementation-specific\n            // event and status\n            span.addEvent('Not found', { resourceIds })\n                .setStatus({ code: SpanStatusCode.ERROR })\n\n            return sendNotFound(res)\n        } else {\n            await this._service.delete(resourceIds)\n            sendOk({ req, res, body: {}, links: {} })\n        }\n    })\n}\n```\n\nSee a full implementation e.g. in [@stfsy/api-kit/http-post-resource-endpoint](https://github.com/stfsy/node-api-kit/blob/main/lib/endpoints/http-post-resource-endpoint.js).\n\n## How to create a span synchronously\nTo wrap a synchronous function inside a span, use the `withActiveSpanSync` method. It also accepts a `spanAttributes` object as optional second parameter.\n\n```js\nimport { createTracer } from '@discue/open-telemetry-tracing';\nimport { nanoid } from \"nanoid\";\n\nconst { withActiveSpanSync } = createTracer({\n    filepath: import.meta.url\n})\n\n/**\n * Creates a url-safe resource id.\n * \n * @module newResourceId\n * @returns {String}\n */\nexport const newResourceId = () =\u003e {\n    // wrap the sync call in a span and return the value\n    // that way the tracing is transparent for all callers\n    return withActiveSpanSync('create-resource-id', () =\u003e {\n        return nanoId()\n    })\n}\n```\n\nSee a full implementation e.g. in [@stfsy/api-kit/resource-id](https://github.com/stfsy/node-api-kit/blob/main/lib/util/resource-id.js).\n\n\n## How to create an orphaned span\nThat is a span that has no parent. Useful if you want to prevent deep nesting of spans. To create an orphan span call the `withOrphanedSpan` method of the module. The `spanAttributes` object is optional and can be omitted.\n\n```js\nimport { createTracer } from '@discue/open-telemetry-tracing';\nimport { SpanStatusCode } from '@opentelemetry/api';\n\nconst { withOrphanedSpan } = createTracer({\n    filepath: import.meta.url\n})\n\nconst { method, headers } = request\nconst incomingContentType = headers['content-type'] ?? ''\nconst spanAttributes = { method, incomingContentType }\n\n// checks whether the content type is set\n// sets span status accordingly\n// adds content-type as a span attribute so it can be queried via UI e.g. Jaeger\nawait withOrphanedSpan('check-content-type-is-set', spanAttributes, (span) =\u003e {\n    if (!incomingContentType ) {\n        span.addEvent('Check failed').setStatus({ code: SpanStatusCode.ERROR })\n        return sendUnsupportedMedia(response)\n\n    } else {\n        span.addEvent('Check succeeded').setStatus({ code: SpanStatusCode.OK })\n    }\n\n    return nextFunction()\n})\n```\n\nSee a full implementation e.g. in [@stfsy/api-kit/content-type-middleware](https://github.com/stfsy/node-api-kit/blob/main/lib/middlewares/content-type.js).\n\n## Configuration\nThe following environment variables can be set:\n- `DSQ_OT_TRACING_SERVICE_NAME` \n  - default: api-kit\n- `DSQ_OT_LOCAL_OLTP_URL`\n  - default: http://127.0.0.1:4318/v1/traces\n  - note:  for cloud environments automatically, this library will configure the right exporter\n- `DSQ_OT_USE_SIMPLE_SPAN_PROCESSOR`\n  - default: false\n- `DSQ_OT_ENABLE_DEBUG_LOGGING`\n  - default: false\n\n## Exports\n- **/**: The main export is the `createTracer` function. Import it via `@discue/open-telemetry-tracing` to create traces as shown above. \n- **/status-codes**: Returns valid status codes a span can have. Use this expor to not couple your application to the Open Telemetry libraries. Use it via `@discue/open-telemetry-tracing/status-codes`.\n- **/instrumentation**: The `instrumentation` script needs to be loaded via `NODE_OPTIONS` function. This export is used internally via `@discue/open-telemetry-tracing/instrumentation` to get ahold of the current tracer. Users of this library should not need to use this export.\n\n## Test\n```bash\n./test.sh\n```\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscue%2Fopen-telemetry-tracing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiscue%2Fopen-telemetry-tracing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscue%2Fopen-telemetry-tracing/lists"}