{"id":21152966,"url":"https://github.com/opentracing-contrib/java-mongo-driver","last_synced_at":"2025-07-09T10:33:21.940Z","repository":{"id":56596670,"uuid":"88231534","full_name":"opentracing-contrib/java-mongo-driver","owner":"opentracing-contrib","description":"OpenTracing Instrumentation for Mongo Driver","archived":false,"fork":false,"pushed_at":"2023-08-03T16:31:55.000Z","size":184,"stargazers_count":13,"open_issues_count":6,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-15T23:00:00.196Z","etag":null,"topics":["java","mongo-driver","opentracing"],"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/opentracing-contrib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-14T04:01:20.000Z","updated_at":"2023-08-03T16:15:24.000Z","dependencies_parsed_at":"2022-08-15T21:40:24.990Z","dependency_job_id":null,"html_url":"https://github.com/opentracing-contrib/java-mongo-driver","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentracing-contrib%2Fjava-mongo-driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentracing-contrib%2Fjava-mongo-driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentracing-contrib%2Fjava-mongo-driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentracing-contrib%2Fjava-mongo-driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentracing-contrib","download_url":"https://codeload.github.com/opentracing-contrib/java-mongo-driver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225040340,"owners_count":17411460,"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":["java","mongo-driver","opentracing"],"created_at":"2024-11-20T10:47:49.226Z","updated_at":"2024-11-20T10:47:49.891Z","avatar_url":"https://github.com/opentracing-contrib.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![Released Version][maven-img]][maven] [![Apache-2.0 license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n# OpenTracing Mongo Driver Instrumentation\nOpenTracing instrumentation for Mongo Driver.\n\n## Installation\n\n### Mongo Driver\n\npom.xml\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.opentracing.contrib\u003c/groupId\u003e\n    \u003cartifactId\u003eopentracing-mongo-driver\u003c/artifactId\u003e\n    \u003cversion\u003eVERSION\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Mongo Driver Async\n\npom.xml\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.opentracing.contrib\u003c/groupId\u003e\n    \u003cartifactId\u003eopentracing-mongo-driver-async\u003c/artifactId\u003e\n    \u003cversion\u003eVERSION\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Mongo Driver Reactive Streams\n\npom.xml\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.opentracing.contrib\u003c/groupId\u003e\n    \u003cartifactId\u003eopentracing-mongo-driver-reactivestreams\u003c/artifactId\u003e\n    \u003cversion\u003eVERSION\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Usage\n\n```java\n// Instantiate tracer\nTracer tracer = ...\n\n// Optionally register tracer with GlobalTracer\nGlobalTracer.register(tracer);\n``` \n\nThere are 2 ways to instrument `MongoClient`:\n- using Mongo Tracing Client\n- using `MongoClientSettings.Builder` with `TracingCommandListener`\n\n### Mongo Tracing Client \n\n```java\n// Instantiate TracingCommandListener\nTracingCommandListener listener = new TracingCommandListener.Builder(tracer).build()\n\n// Instantiate Synchronous Tracing MongoClient\nMongoClient mongoClient = new TracingMongoClient(listener, ...);\n\n// Instantiate Asynchronous Tracing MongoClient\nMongoClient mongoClient = new TracingAsyncMongoClient(listener, ...);\n\n```\n\n### `MongoClientSettings.Builder` with `TracingCommandListener`\n```java\n// Instantiate TracingCommandListener\nTracingCommandListener listener = new TracingCommandListener.Builder(tracer).build()\n\n// Add TracingCommandListener to MongoClientSettings.Builder\nMongoClient mongoClient = MongoClients.create(\n        MongoClientSettings.builder()\n                .addCommandListener(listener)\n                ...\n                .build());\n\n```\n\n### Mongo Span Name\nBy default, span names are set to the operation performed by the Mongo client. To customize the span name, provide a MongoSpanNameProvider to the client that alters the span name. If a provider is not provided, the span name will remain the default.\n\n```java\n\n// Create TracingCommandListener with custom span name provider\nTracingCommandListener listener = new TracingCommandListener.Builder(tracer)\\\n    .withSpanNameProvider(new PrefixSpanNameProvider(\"mongo.\"))\n    .build();\n\n// Create TracingMongoClient\nTracingMongoClient client = new TracingMongoClient(\n    listener, \n    replicaSetAddresses, \n    credentials, \n    clientOptions \n    );\nDocument doc = new Document();\nclient.getDatabase(\"db\").getCollection(\"collection).insertOne(doc);\n// Span name is now set to \"mongo.insert\"\n```\n\n### Exclude commands from tracing\nTo exclude specific Mongo commands from tracing add `ExcludedCommand` to `TracingCommandListener`:\n```java\nList\u003cExcludedCommand\u003e excludedCommands = new ArrayList\u003c\u003e();\nExcludedCommand excludedCommand = new ExcludedCommand();\nexcludedCommand.put(\"getMore\",  BsonNull.VALUE);\nexcludedCommand.put(\"collection\",  new BsonString(\"oplog.rs\"));\n\nexcludedCommands.add(excludedCommand);\n\n    \nTracingCommandListener listener =  new TracingCommandListener.Builder(tracer)\n    .withExcludedCommands(excludedCommands).build();    \n    \n```\n\n## License\n\n[Apache 2.0 License](./LICENSE).\n\n[ci-img]: https://travis-ci.org/opentracing-contrib/java-mongo-driver.svg?branch=master\n[ci]: https://travis-ci.org/opentracing-contrib/java-mongo-driver\n[cov-img]: https://coveralls.io/repos/github/opentracing-contrib/java-mongo-driver/badge.svg?branch=master\n[cov]: https://coveralls.io/github/opentracing-contrib/java-mongo-driver?branch=master\n[maven-img]: https://img.shields.io/maven-central/v/io.opentracing.contrib/opentracing-mongo-driver.svg\n[maven]: http://search.maven.org/#search%7Cga%7C1%7Copentracing-mongo-driver\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentracing-contrib%2Fjava-mongo-driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentracing-contrib%2Fjava-mongo-driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentracing-contrib%2Fjava-mongo-driver/lists"}