{"id":19061143,"url":"https://github.com/bo0mer/gentools","last_synced_at":"2025-04-24T07:02:54.312Z","repository":{"id":28949082,"uuid":"119813021","full_name":"Bo0mer/gentools","owner":"Bo0mer","description":"Generate logging, tracing and monitoring Go interface implementations","archived":false,"fork":false,"pushed_at":"2022-02-14T11:31:44.000Z","size":2579,"stargazers_count":8,"open_issues_count":4,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-24T07:01:55.745Z","etag":null,"topics":["code-generation","golang","logging","monitoring","tracing"],"latest_commit_sha":null,"homepage":"","language":"Go","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/Bo0mer.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":"2018-02-01T09:24:31.000Z","updated_at":"2024-04-07T06:51:55.000Z","dependencies_parsed_at":"2022-08-07T14:01:00.543Z","dependency_job_id":null,"html_url":"https://github.com/Bo0mer/gentools","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bo0mer%2Fgentools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bo0mer%2Fgentools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bo0mer%2Fgentools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bo0mer%2Fgentools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bo0mer","download_url":"https://codeload.github.com/Bo0mer/gentools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250580729,"owners_count":21453534,"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":["code-generation","golang","logging","monitoring","tracing"],"created_at":"2024-11-09T00:18:03.324Z","updated_at":"2025-04-24T07:02:54.109Z","avatar_url":"https://github.com/Bo0mer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gentools\n\nGentools provides a collection of tools that help by generating Go interface\nimplementations that add monitoring, logging and tracing.\n\n## Installation\n\nIn order to install all tools run:\n```\ngo get -u github.com/Bo0mer/gentools/cmd/...\n```\n\n## Using mongen\n\nGiven a path to a package and an interface name, you could generate monitoring\nimplementation of the interface.\n\n```go\npackage service\n\nimport \"context\"\n\ntype Service interface {\n    DoWork(context.Context, int, string) (string, error)\n}\n```\n\n```bash\n$ mongen path/to/service Service\nWrote monitoring implementation of \"path/to/service.Service\" to \"path/to/service/servicews/monitoring_service.go\"\n```\n\nBy default the generated implementation uses [go-kit metrics](https://github.com/go-kit/kit/tree/master/metrics). It can\nbe changed to use [opencensus](https://github.com/census-instrumentation/opencensus-go) by providing it as a 3rd\nargument:\n\n```bash\n$ mongen path/to/service Service opencensus\nWrote monitoring implementation of \"path/to/service.Service\" to \"path/to/service/servicews/monitoring_service.go\"\n```\n\n### Using monitoring implementation in your program\n\n#### With Go-Kit\n\nInstantiate monitoring implementations with `NewMonitoring{InterfaceName}`:\n\n```go\nvar svc Service = service.New()\nsvc = servicemws.NewMonitoringService(svc, totalOps, faildOps, opsDuration)\n```\n\n#### With Opencensus\n\nUsage with opencensus is similar with the addition of the `ctxFunc` parameter. It can be used to add custom labels at\nrun time.\n\n```go\nctxFunc := func(ctx context.Context) context.Context {\n  // modify the context the way you need it\n  ctx, _ = tag.New(ctx,\n    tag.Insert(\"service_name\", \"payments\"),\n  )\n  return ctx\n}\nvar svc Service = service.New()\nsvc = servicemws.NewMonitoringService(svc, totalOps, faildOps, opsDuration, ctxFunc)\n```\n\n`ctxFunc` is optional and can be set to `nil`.\n\n### Examples\n\nSee `cmd/mongen/examples` for the files that mongen produces.\n\n## Using logen\n\nGiven a path to a package and an interface name, you could generate logging\nimplementation of the interface. ATM only error logging is supported.\n\n## Using tracegen\n\nGiven a path to a package and an interface name, you could generate tracing\nimplementation of the interface. Tracing will be added only to methods that\ntake a `context.Context` as a first argument. All other methods will be proxied\nto the original implementation, without any modifications or additions.\n\n## Integration with go generate\n\nThe best way to integrate the tools within your project is to use the\n`go:generate` directive in your code.\n\n```bash\n$ cat path/to/service/file.go\n```\n\n```go\npackage service\n\nimport \"context\"\n\n//go:generate mongen . Service\n//go:generate tracegen . Service\n//go:generate logen . Service\n\ntype Service interface {\n\tDoWork(context.Context, int, string) (string, error)\n}\n```\n\n```\n$ go generate ./...\nWrote monitoring implementation of \"path/to/service.Service\" to \"servicemws/monitoring_service.go\"\nWrote tracing implementation of \"path/to/service.Service\" to \"servicemws/tracing_service.go\"\nWrote logging implementation of \"path/to/service.Service\" to \"servicemws/logging_service.go\"\n```\n\n## Credits\n\n* Special thanks to [Momchil Atanasov](https://github.com/mokiat) and his\n  awesome project [gostub](https://github.com/mokiat/gostub), which code was\n  used as a starting point for developing gentools v2.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbo0mer%2Fgentools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbo0mer%2Fgentools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbo0mer%2Fgentools/lists"}