{"id":21303060,"url":"https://github.com/bzon/errors","last_synced_at":"2025-03-15T18:45:53.034Z","repository":{"id":141940522,"uuid":"195717207","full_name":"bzon/errors","owner":"bzon","description":"A drop-in replacement for Go errors package with tracing.","archived":false,"fork":false,"pushed_at":"2020-04-21T22:27:46.000Z","size":140,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-22T08:28:12.885Z","etag":null,"topics":["devops","golang","opencensus","stackdriver"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bzon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-07-08T01:43:00.000Z","updated_at":"2020-04-21T22:31:19.000Z","dependencies_parsed_at":"2024-06-20T17:21:49.923Z","dependency_job_id":"347ac8b4-4255-4557-a592-893bdb7ed07e","html_url":"https://github.com/bzon/errors","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzon%2Ferrors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzon%2Ferrors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzon%2Ferrors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzon%2Ferrors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bzon","download_url":"https://codeload.github.com/bzon/errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243776693,"owners_count":20346353,"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":["devops","golang","opencensus","stackdriver"],"created_at":"2024-11-21T15:58:45.661Z","updated_at":"2025-03-15T18:45:53.007Z","avatar_url":"https://github.com/bzon.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GoDoc](https://godoc.org/github.com/bzon/errors?status.svg)](http://godoc.org/github.com/bzon/errors)\n\n# errors\n\nA drop-in replacement for creating errors with OpenCensus instrumentation (OpenTelemetry soon).\n\nInitially, I created this package to help me link the details of my Stackdriver traces with Stackdriver logs.\n\n* https://cloud.google.com/trace/docs/viewing-details\n* https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry\n* https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation\n\nThis package also supports the Go 1.13 `errors.As` and `errors.Is` methods. Please check the examples in Go doc.\n\n\n## Getting Started\n\nDrop-in replacement. Creating an error.\n\n```golang\nerr := errors.New(\"msg\") // Wrap .. Wrapf .. Errorf ..\n```\n\nCreating an error with context useful for monitoring.\n\n```golang\nfunc main() {\n\t_, span := trace.StartSpan(context.Background(), \"main\")\n\tdefer span.End()\n\n\terr := errors.NewT(span, \"error\")\n\tfmt.Println(err)\n\n\tif erctx, ok := err.(errors.ErrorTracer); ok {\n\t\tfmt.Println(erctx.SourceLocation().Function)\n\t\tfmt.Println(erctx.SourceLocation().File)\n\t\tfmt.Println(erctx.SourceLocation().Line)\n\t\tfmt.Println(erctx.TraceContext().TraceID)\n\t\tfmt.Println(erctx.TraceContext().SpanID)\n\t}\n}\n```\n\nOutput\n\n```txt\nmain.main\n/Users/jb/Golang/src/github.com/bzon/errors/examples/main.go\n15\nd2d2b126d0474947821106525e32b6e0\n1644b4b9be26c929\n```\n\n## Production Usage\n\nSee the source code of the example server in [examples](./examples) folder.\n\nUseful for logging error with tracing context.\n\n```console\n$ go run main.go | jq '.'\n\n{\n  \"caller\": \"main.go:38\",\n  \"logging.googleapis.com/sourceLocation\": {\n    \"function\": \"main.work\",\n    \"file\": \"/Users/jb/Golang/src/github.com/bzon/errors/examples/main.go\",\n    \"line\": 55\n  },\n  \"logging.googleapis.com/spanId\": \"1eb9494ab1a7831c\",\n  \"logging.googleapis.com/trace\": \"e97499da53ef2a8fdf9681beddbe3d64\",\n  \"message\": \"error\",\n  \"ts\": \"2019-07-15T09:37:06.885078+02:00\"\n}\n```\n\nThe annotations are automatically exported to any OpenCensus supported tracing platform. E.g. Jaeger.\n\n![img](./jaeger-error-trace.png)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbzon%2Ferrors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbzon%2Ferrors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbzon%2Ferrors/lists"}