{"id":28125153,"url":"https://github.com/xing/logjam-agent-go","last_synced_at":"2026-07-22T11:32:52.505Z","repository":{"id":46291971,"uuid":"258733516","full_name":"xing/logjam-agent-go","owner":"xing","description":"Golang logjam agent","archived":false,"fork":false,"pushed_at":"2021-11-01T17:22:37.000Z","size":131,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-10-17T17:02:10.983Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","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/xing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-25T09:30:39.000Z","updated_at":"2021-11-01T17:22:39.000Z","dependencies_parsed_at":"2022-08-26T05:02:37.634Z","dependency_job_id":null,"html_url":"https://github.com/xing/logjam-agent-go","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/xing/logjam-agent-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xing%2Flogjam-agent-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xing%2Flogjam-agent-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xing%2Flogjam-agent-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xing%2Flogjam-agent-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xing","download_url":"https://codeload.github.com/xing/logjam-agent-go/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xing%2Flogjam-agent-go/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35760583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-22T02:00:06.236Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-05-14T09:20:25.765Z","updated_at":"2026-07-22T11:32:52.477Z","avatar_url":"https://github.com/xing.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logjam client for Go\n\n[![GoDoc](https://godoc.org/github.com/xing/logjam-agent-go?status.svg)](https://godoc.org/github.com/xing/logjam-agent-go)\n[![build](https://github.com/xing/logjam-agent-go/actions/workflows/build.yml/badge.svg)](https://github.com/xing/logjam-agent-go/actions/workflows/build.yml)\n\nThis package provides integration with the [Logjam](https://github.com/skaes/logjam_core)\nmonitoring tool for Go web-applications.\n\nIt buffers all log output for a request and sends the result to a configured logjam device\nwhen the request was finished.\n\n\n## Requirements\nThis package depends on [github.com/pebbe/zmq4](https://github.com/pebbe/zmq4) which\nrequires ZeroMQ version 4.0.1 or above. Make sure you have it installed on your machine.\n\nE.g. for MacOS:\n```bash\nbrew install zmq\n```\n\n## How to use it\nInstall via `go get github.com/xing/logjam-agent-go`.\n\n### Initialize the client\n\n```go\n// create a logger\nlogger := logjam.Logger{\n\tLogger: log.New(os.Stderr, \"\", log.StdFlags),\n\tLogLevel: logjam.ERROR,\n}\n\n// create an agent\nagent := logjam.NewAgent(\u0026logjam.Options{\n\tAppName: \"MyApp\",\n\tEnvName: \"production\",\n\tLogger: logger,\n\tLogLevel: logjam.INFO,\n})\n```\n\nNote that logger and the agent have individual log levels: the one on the logger\ndetermines the log level for lines sent to the device it is attached to (`os.Stderr` in\nthis example), whereas the one on the agent determines which lines are sent to the logjam\nendpoint.\n\n### Use the logjam middleware\n\n```go\nr := mux.NewRouter()\nr.NotFoundHandler = http.HandlerFunc(logjam.NotFoundHandler)\nr.MethodNotAllowedHandler = http.HandlerFunc(logjam.MethodNotAllowedHandler)\n...\nserver := http.Server{\n\tHandler: agent.NewHandler(r, logjam.MiddlewareOptions{BubblePanics: false})\n\t...\n}\n```\n\nThis example uses the Gorilla Mux package but it should also work with other router\npackages. Don't use the Gorilla syntax: `r.Use(agent.NewMiddleware)` because middleware\nadded that way is only called for configured routes. So you'll not get 404s tracked\nin logjam.\n\nYou also need to set environment variables to point to the actual logjam broker instance:\n\n`export LOGJAM_BROKER=my-logjam-broker.host.name`\n\n### Shutting down\n\nMake sure to shut down the agent upon program termination in order to properly close the\nZeroMQ socket used to send messages to logjam.\n\n```go\nagent.Shutdown()\n```\n\n### Adapting logjam action names\n\nBy default, the logjam middleware fabricates logjam action names from the escaped request\npath and request method. For example, a GET request to the endpoint \"/users/123/friends\"\nwill be translated to \"Users::Id::Friends#get\". If you're not happy with that, you can\noverride the action name in your request handler, as the associated logjam request is\navailable from the request context:\n\n```go\nfunc ShowFriends(w http.ResponseWriter, r *http.Request) {\n\trequest := logjam.GetRequest(r)\n\trequest.ChangeAction(w, \"Users#friends\")\n\tfmt.Fprintf(w, \"Hello, %q\", html.EscapeString(r.URL.Path))\n})\n```\n\nIf you're using the gorilla mux package, you can configure the desired logjam action name\nwhen declaring the route. The following examples uses a Rails inspired naming:\n\n```go\nimport (\"github.com/xing/logjam-agent-go/gorilla\")\n\ngorilla.ActionName(router.Path(\"/users\").Methods(\"GET\").HandlerFunc(...), \"Users#index\")\ngorilla.ActionName(router.Path(\"/users\").Methods(\"POST\").HandlerFunc(...), \"Users#create\")\ngorilla.ActionName(router.Path(\"/users/{user_id}\").Methods(\"GET\").HandlerFunc(...), \"Users#show\")\ngorilla.ActionName(router.Path(\"/users/{user_id}\").Methods(\"PUT\", \"PATCH\").HandlerFunc(...), \"Users#update\")\ngorilla.ActionName(router.Path(\"/users/{user_id}\").Methods(\"DELETE\").HandlerFunc(...), \"Users#destroy\")\ngorilla.ActionName(router.Path(\"/users/{user_id}/friends\").Methods(\"GET\").HandlerFunc(...), \"Users#friends\")\n```\n\nMake sure to have the route fully configured before calling `gorilla.ActionName`.\n\n\n### Using the agent for non web requests\n\nThe agent's middleware takes care of all the internal plumbing for web requests. If you\nhave some other request handling mechanism, like a message processor for example, you have\nto manage that yourself.\n\nYou will need to create a request, then store the request in a context to be used by the\nlogging mechanism and sending call headers to other services, then perform your business\nlogic and then finally make sure to send the request information to logjam.\n\n```go\n// Let's assume that the variable agent points to a logjam.Agent and logger is\n// an instance of a logjam.Logger.\n\nfunc myHandler(ctx context.Context) {\n    // create a new request\n    request := agent.NewRequest(\"myHandler#call\")\n    // create a new context containing the request, so the logjam logger can access it\n    ctx := request.NewContext(ctx)\n    code := int(200)\n    // make sure to send the request at the end\n    defer func() {\n        // make we send information to logjam in case the app panics\n        if r := recover(); r != nil {\n            code = 500\n            request.Finish(code)\n            // optionally reraise the original panic:\n            // panic(r)\n        }\n        request.Finish(code)\n    }()\n    ...\n    // your logic belongs here\n    ...\n    if sucess {\n        logger.Info(ctx, \"200 OK\")\n        return\n    }\n    code = 500\n    logger.Error(ctx, \"500 Internal Server Error\")\n}\n```\n\nObviously one could abstract this logic into a helper function, but a.t.m. we think this\nis best left to the application programmer, until we have an agreement on the desired API\nof such a helper.\n\n\n### Passing call headers to other logjam instrumented services\n\nLogjam can provide caller relationship information between a collection of services, which\nhelps in debugging and understanding your overall system. It can be considered a form of\ndistributed tracing, restricted to HTTP based service relationships. The agent provides a\nhelper function to simplify the task of passing the required information to the called\nservice.\n\n```go\n// Call some REST service passing the required logjam headers assuming the variable client\n// refers to a http.Client, agent to the logjam agent and ctx refers to the http request\n// context of the currently executing request handler which has been augmented by the logjam agent.\n\nreq, err := http.NewRequest(\"GET\", \"http://example.com\", nil)\nagent.SetCallHeaders(ctx, req)\nresp, err := client.Do(req)\n```\n\n\n## How to contribute?\nPlease fork the repository and create a pull-request for us.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxing%2Flogjam-agent-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxing%2Flogjam-agent-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxing%2Flogjam-agent-go/lists"}