{"id":15926693,"url":"https://github.com/nflaig/loopback4-tracing","last_synced_at":"2026-02-19T14:03:28.227Z","repository":{"id":222105419,"uuid":"756246187","full_name":"nflaig/loopback4-tracing","owner":"nflaig","description":"LoopBack 4 Tracing Component","archived":false,"fork":false,"pushed_at":"2025-02-17T22:48:22.000Z","size":705,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-29T08:40:56.339Z","etag":null,"topics":["jaeger","loopback-4","loopback-extension","opentelemetry","profiling","tracing"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/nflaig.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":"2024-02-12T09:26:43.000Z","updated_at":"2024-12-19T02:01:32.000Z","dependencies_parsed_at":"2024-03-29T19:24:39.788Z","dependency_job_id":"0fcd46ea-b47b-4f4d-9929-aa838cf848a6","html_url":"https://github.com/nflaig/loopback4-tracing","commit_stats":null,"previous_names":["nflaig/loopback4-tracing"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nflaig/loopback4-tracing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nflaig%2Floopback4-tracing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nflaig%2Floopback4-tracing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nflaig%2Floopback4-tracing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nflaig%2Floopback4-tracing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nflaig","download_url":"https://codeload.github.com/nflaig/loopback4-tracing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nflaig%2Floopback4-tracing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29616954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T13:04:20.082Z","status":"ssl_error","status_checked_at":"2026-02-19T13:03:33.775Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["jaeger","loopback-4","loopback-extension","opentelemetry","profiling","tracing"],"created_at":"2024-10-06T22:41:44.011Z","updated_at":"2026-02-19T14:03:23.217Z","avatar_url":"https://github.com/nflaig.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- omit in toc --\u003e\n# loopback4-tracing\n\n[![Actions Status][build-badge]][actions]\n[![Coverage Status][coveralls-badge]][coveralls]\n\n[![Latest version][npm-version-badge]][npm-package]\n[![License][license-badge]][license]\n[![Downloads][npm-downloads-badge]][npm-package]\n[![Total Downloads][npm-total-downloads-badge]][npm-package]\n\nLoopBack 4 Tracing Component\n\n\u003c!-- omit in toc --\u003e\n## Contents\n\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n  - [Initialize tracing](#initialize-tracing)\n  - [Bind the component](#bind-the-component)\n- [Usage](#usage)\n  - [Trace decorator](#trace-decorator)\n  - [Create custom span](#create-custom-span)\n  - [Get active span](#get-active-span)\n- [Configuration](#configuration)\n- [Example](#example)\n- [Debug](#debug)\n- [Related resources](#related-resources)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Prerequisites\n\nSome modules need to be installed as peer dependencies with at least a certain version.\n\n```sh\n@loopback/core  \u003e=2.14.0\n@loopback/rest  \u003e=9.1.2\n```\n\n## Installation\n\n```sh\nnpm install loopback4-tracing\n```\n\n### Initialize tracing\n\nBefore loading any application code it is required to initialize tracing. This is usually done at\nthe top of the `index.js` or `index.ts` file.\n\n```js\nrequire(\"loopback4-tracing\").init({/* config */});\n```\n\nor in TypeScript it is also possible to do\n\n```ts\nimport { initializeTracing } from \"loopback4-tracing\";\n\ninitializeTracing({/* config */});\n```\n\n### Bind the component\n\nThis will add the tracing interceptor and observer to the application. The interceptor will create\nmethod invocation spans and the observer is required to gracefully shutdown the tracer\nprovider and exporters when the application is stopped.\n\n```ts\nimport { TracingBindings, TracingComponent } from \"loopback4-tracing\";\n\nexport class MyApplication extends BootMixin(\n    ServiceMixin(RepositoryMixin(RestApplication))\n) {\n    constructor(options?: ApplicationConfig) {\n        super(options);\n\n        this.component(TracingComponent);\n    }\n}\n```\n\n## Usage\n\nThe module provides a lot of auto instrumentations by default but is also possible to create\ncustom spans in your code.\n\n### Trace decorator\n\nThe easiest way create custom spans is by using the decorator which can be added to any method.\n\n```ts\nimport { trace } from \"loopback4-tracing\";\n\nclass ExampleService {\n    constructor() {}\n\n    @trace()\n    exampleMethod() {\n        // do some work\n    }\n}\n```\n\nThe decorator will wrap the method into a span which will use the method name as span name by default.\nIt is also possible to use a custom span name by setting the operation name in the decorator options.\n\n```ts\n@trace({ operationName: \"customName\" })\n```\n\n### Create custom span\n\nThe first step is get the tracer of the service either by using dependency injection\n\n```ts\nimport { Tracer, TracingBindings } from \"loopback4-tracing\";\n\nclass ExampleService {\n    constructor(\n        @inject(TracingBindings.TRACER)\n        private tracer: Tracer\n    ) {}\n\n    exampleMethod() {\n        const span = this.tracer.startSpan(\"exampleMethod\");\n\n        // do some work\n\n        span.end();\n    }\n}\n```\n\nor by directly importing the `tracer`\n\n```ts\nimport { tracer } from \"loopback4-tracing\";\n\nfunction exampleFunction() {\n    const span = tracer.startSpan(\"exampleFunction\");\n\n    // do some work\n\n    span.end();\n}\n```\n\n### Get active span\n\nIn some cases it might not be desired to create a new span but instead get the active span to\nadd additional events and attributes to it.\n\n```ts\nimport { getActiveSpan } from \"loopback4-tracing\";\n\nfunction exampleFunction() {\n    const span = getActiveSpan();\n\n    span.addEvent(\"some event\");\n\n    span.setAttribute(\"custom.attribute\", \"some value\");\n}\n```\n\n## Configuration\n\nMost of the time it is not recommended to change the [default configuration][default-config] but\nthere are some cases where it makes sense, for example to enable / disable default instrumentations\nprovided by the module such as `http`.\n\nThe module can be configured by providing custom values in the [init function](#initialize-tracing)\nor by using [environment variables][env-vars] which will have highest priority.\n\n**Note:** By default tracing is not enabled. The recommended approach is to enable tracing by setting\nthe environment variable `TRACING_ENABLED=true` and to only enable it if the collected traces are analyzed.\n\n\u003c!-- omit in toc --\u003e\n### Configuration parameters\n\n| Parameter                   | Environment Variable                 | Description                          | Default       | Type                  |\n| --------------------------- | ------------------------------------ | ------------------------------------ | ------------- | --------------------- |\n| `enabled`                   | `TRACING_ENABLED`                    | Enable tracing                       | `false`       | `boolean`             |\n| `serviceName`               | `TRACING_SERVICE_NAME`               | Name of service                      | `pkg.name`    | `string`              |\n| `serviceVersion`            | `TRACING_SERVICE_VERSION`            | Version of service                   | `pkg.version` | `string`              |\n| `propagationFormat`         | `TRACING_PROPAGATION_FORMAT`         | Propagation format                   | `\"jaeger\"`    | `\"jaeger\" \\| \"w3c\"`   |\n| `setRequestId`              | `TRACING_SET_REQUEST_ID`             | Set request id in error and response | `true`        | `boolean`             |\n| `jaeger.enabled`            | `TRACING_JAEGER_ENABLED`             | Enable jaeger exporter               | `true`        | `boolean`             |\n| `jaeger.host`               | `TRACING_JAEGER_HOST`                | Jaeger host                          | `\"localhost\"` | `string`              |\n| `jaeger.port`               | `TRACING_JAEGER_PORT`                | Jaeger port                          | `6832`        | `number`              |\n| `jaeger.endpoint`           | `TRACING_JAEGER_ENDPOINT`            | Jaeger traces endpoint               | `undefined`   | `string`              |\n| `jaeger.spanProcessor.type` | `TRACING_JAEGER_SPAN_PROCESSOR`      | Jaeger span processor type           | `\"batch\"`     | `\"simple\" \\| \"batch\"` |\n| `console.enabled`           | `TRACING_CONSOLE_ENABLED`            | Enable console exporter              | `false`       | `boolean`             |\n| `diagnostics.enabled`       | `TRACING_DIAGNOSTICS_ENABLED`        | Enable diagnostics logger            | `false`       | `boolean`             |\n| `diagnostics.logLevel`      | `TRACING_DIAGNOSTICS_LOG_LEVEL`      | Log level of diag logger             | `9999`        | `DiagLogLevel`        |\n| `methodInvocations.enabled` | `TRACING_METHOD_INVOCATIONS_ENABLED` | Enable method invocation spans       | `true`        | `boolean`             |\n| `http.enabled`              | `TRACING_HTTP_ENABLED`               | Enable http instrumentation          | `true`        | `boolean`             |\n\nFor further details about possible configuration options, see [tracing options][tracing-options].\n\n**Note:** Some values can not be configured by using environment variables but instead need to be\nprovided to the [init function](#initialize-tracing).\n\n## Example\n\nFor an example on how to create custom spans see [tracing interceptor][tracing interceptor]\nand for more information, please read the [opentelemetry tracing documentation][opentelemetry-tracing].\n\n## Debug\n\nTo enable debug logs set the `DEBUG` environment variable to `loopback:tracing:*`, see\n[Setting debug strings][lb4-debug-strings] for further details.\n\n## Related resources\n\n- [Specifications for OpenTelemetry][opentelemtry-specifications]\n- [Jaeger Distributed Tracing][jaeger-tracing]\n\n## Contributing\n\n[![contributions welcome][contributions-welcome-badge]][issues]\n\n## License\n\nThis project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.\n\n[actions]: https://github.com/nflaig/loopback4-tracing/actions\n[license]: https://github.com/nflaig/loopback4-tracing/blob/main/LICENSE\n[issues]: https://github.com/nflaig/loopback4-tracing/issues\n[coveralls]: https://coveralls.io/github/nflaig/loopback4-tracing?branch=main\n[npm-package]: https://www.npmjs.com/package/loopback4-tracing\n\n[build-badge]: https://github.com/nflaig/loopback4-tracing/workflows/build/badge.svg\n[coveralls-badge]: https://coveralls.io/repos/github/nflaig/loopback4-tracing/badge.svg?branch=main\n[npm-version-badge]: https://img.shields.io/npm/v/loopback4-tracing.svg?style=flat-square\n[npm-downloads-badge]: https://img.shields.io/npm/dw/loopback4-tracing.svg?label=Downloads\u0026style=flat-square\u0026color=blue\n[npm-total-downloads-badge]: https://img.shields.io/npm/dt/loopback4-tracing.svg?label=Total%20Downloads\u0026style=flat-square\u0026color=blue\n[license-badge]: https://img.shields.io/github/license/nflaig/loopback4-tracing.svg?color=blue\u0026label=License\u0026style=flat-square\n[contributions-welcome-badge]: https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat\n\n[lb4-debug-strings]: https://loopback.io/doc/en/lb4/Setting-debug-strings.html\n\n[default-config]: https://github.com/nflaig/loopback4-tracing/blob/main/src/constants.ts#L16\n[env-vars]: https://github.com/nflaig/loopback4-tracing/blob/main/src/constants.ts#L48\n[tracing-options]: https://github.com/nflaig/loopback4-tracing/blob/main/src/types.ts#L17\n[tracing interceptor]: https://github.com/nflaig/loopback4-tracing/blob/main/src/interceptors/tracing.interceptor.ts\n\n[opentelemetry-tracing]: https://github.com/open-telemetry/opentelemetry-js-api/blob/main/docs/tracing.md\n[opentelemtry-specifications]: https://github.com/open-telemetry/opentelemetry-specification\n\n[jaeger-tracing]: https://www.jaegertracing.io/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnflaig%2Floopback4-tracing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnflaig%2Floopback4-tracing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnflaig%2Floopback4-tracing/lists"}