{"id":20209010,"url":"https://github.com/palantir/tritium","last_synced_at":"2025-04-10T13:05:17.878Z","repository":{"id":37514378,"uuid":"66020851","full_name":"palantir/tritium","owner":"palantir","description":"Tritium is a library for instrumenting applications to provide better observability at runtime","archived":false,"fork":false,"pushed_at":"2025-04-09T14:56:02.000Z","size":4234,"stargazers_count":47,"open_issues_count":16,"forks_count":10,"subscribers_count":279,"default_branch":"develop","last_synced_at":"2025-04-09T15:48:31.926Z","etag":null,"topics":["instrumentation","java","octo-correct-managed"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palantir.png","metadata":{"files":{"readme":"README.md","changelog":"changelog/0.15.0/pr-308.v2.yml","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}},"created_at":"2016-08-18T18:23:06.000Z","updated_at":"2025-04-09T14:56:06.000Z","dependencies_parsed_at":"2023-11-23T12:27:36.350Z","dependency_job_id":"b75f419f-b1af-478d-8086-6b718801e154","html_url":"https://github.com/palantir/tritium","commit_stats":null,"previous_names":[],"tags_count":173,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Ftritium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Ftritium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Ftritium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Ftritium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palantir","download_url":"https://codeload.github.com/palantir/tritium/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248223827,"owners_count":21068069,"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":["instrumentation","java","octo-correct-managed"],"created_at":"2024-11-14T05:38:32.232Z","updated_at":"2025-04-10T13:05:17.855Z","avatar_url":"https://github.com/palantir.png","language":"Java","funding_links":[],"categories":["指标库"],"sub_categories":[],"readme":"\u003cp align=\"right\"\u003e\n\u003ca href=\"https://autorelease.general.dmz.palantir.tech/palantir/tritium\"\u003e\u003cimg src=\"https://img.shields.io/badge/Perform%20an-Autorelease-success.svg\" alt=\"Autorelease\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# [Tritium](https://github.com/palantir/tritium)\n\nTritium is a library for instrumenting applications  to provide better observability at runtime. Tritium allows for instrumentation of service interfaces through a Java proxy, providing call backs to extensible invocation event handlers. Two main invocation handlers currently provided are:\n\n* Metrics - records aggregate service time and call rates using Dropwizard metrics\n* Logging - logs individual service times\n\n## Why Tritium?\n\nTritium gives us aggregate metrics for the various services exposed and consumed by a server.\n\n* invocation response times (including min, average, max, percentile distribution, request count and 1, 5, and 15 rates)\n* cache effectiveness (eviction count, hit count, hit ratio, load average millis, load failure count, load success count, miss count, miss ratio, request count)\n\nThese metrics can be exposed at the Dropwizard ``MetricsServlet`` and can be exported via any of the [Dropwizard provided reporters](http://metrics.dropwizard.io/3.1.0/manual/core/#reporters).\n\n## Basic Usage\n\n### Instrumenting a service using the Tritium annotation processor\n\nThe `tritium-processor` annotation processor must be applied to the annotation processor scope, and `tritium-annotations` must be available at both build and runtime.\n\nExample using gradle, however all modern build systems are capable of registering annotation processors:\n```gradle\ndependencies {\n    implementation 'com.palantir.tritium:tritium-annotations'\n    annotationProcessor 'com.palantir.tritium:tritium-processor'\n}\n```\n\nApply the `@Instrument` annotation to methods on an interface. Only the annotated methods will be instrumented.\n```java\ninterface Service {\n    @Instrument\n    String getGreeting();\n}\n```\n\nYou can also apply the `@Instrument` annotation to the interface itself to instrument all methods.\n```java\n@Instrument\ninterface Service {\n    String getGreeting();\n}\n```\n\nIf the interface is defined externally, a new interface may be defined which extends the target interface. The `@Instrument` annotation may be applied to either individual methods or the interface itself.\n```java\ninterface DelegateSupplier\u003cT\u003e extends Supplier\u003cT\u003e {\n    @Instrument\n    @Override\n    String get();\n}\n```\n```java\n@Instrument\ninterface DelegateSupplier\u003cT\u003e extends Supplier\u003cT\u003e {}\n```\n\nThis generates the `InstrumentedService` wrapper implementation equivalent to the legacy dynamic proxy, with less overhead.\n```java\nService interestingService = ...\nService instrumentedService =\n        InstrumentedService.instrument(interestingService, environment.metrics());\n```\n\n### Instrumenting a service interface of a dropwizard application with default metrics timers and optional trace logging.\n\n_Prefer using the annotation processor whenever possible_\n\n```java\nimport com.palantir.tritium.Tritium;\n\nService interestingService = ...\nService instrumentedService = Tritium.instrument(Service.class,\n        interestingService, environment.metrics());\n```\n\n## Instrumenting a [Caffeine cache](https://github.com/ben-manes/caffeine/)\n\n```java\nimport com.palantir.tritium.metrics.caffeine.CacheStats;\n\nTaggedMetricRegistry taggedMetricRegistry = ...\n\nCache\u003cInteger, String\u003e cache = CacheStats.of(taggedMetricRegistry, \"unique-cache-name\")\n        .register(stats -\u003e Caffeine.newBuilder()\n                .recordStats(stats)\n                .build());\n\nLoadingCache\u003cString, Integer\u003e loadingCache = CacheStats.of(taggedMetricRegistry, \"unique-loading-cache-name\")\n        .register(stats -\u003e Caffeine.newBuilder()\n                .recordStats(stats)\n                .build(key::length);\n```\n\n## Creating a metric registry with reservoirs backed by [HDR Histograms](https://hdrhistogram.github.io/HdrHistogram/).\n\nHDR histograms are more useful if the service is long running, so the stats represents the lifetime of the server rather than using default exponential decay which can lead to some mis-interpretations of timings (especially higher percentiles and things like max dropping over time) if the consumer isn't aware of these assumptions.\n\nNote that the Histogram collects metrics throughout the lifetime of the service.\n\n### Dropwizard 0.9+ Integration\n\n```java\n\n    @Override\n    public void initialize(Bootstrap\u003cApplicationConfiguration\u003e bootstrap) {\n        super.initialize(bootstrap);\n        bootstrap.setMetricRegistry(MetricRegistries.createWithHdrHistogramReservoirs());\n        ...\n    }\n```\n\nLicense\n-------\nThis project is made available under the\n[Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalantir%2Ftritium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalantir%2Ftritium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalantir%2Ftritium/lists"}