{"id":13778572,"url":"https://github.com/saks/lua-resty-newrelic","last_synced_at":"2025-08-25T01:22:33.712Z","repository":{"id":52965324,"uuid":"55835364","full_name":"saks/lua-resty-newrelic","owner":"saks","description":"This Lua library is a luajit ffi-based wrapper around newrelic agent SDK for the ngx_lua nginx module","archived":false,"fork":false,"pushed_at":"2021-04-12T07:16:02.000Z","size":15,"stargazers_count":13,"open_issues_count":2,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-11T12:36:07.091Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saks.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":"2016-04-09T09:09:04.000Z","updated_at":"2021-11-02T06:51:04.000Z","dependencies_parsed_at":"2022-08-20T00:41:16.409Z","dependency_job_id":null,"html_url":"https://github.com/saks/lua-resty-newrelic","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/saks/lua-resty-newrelic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saks%2Flua-resty-newrelic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saks%2Flua-resty-newrelic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saks%2Flua-resty-newrelic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saks%2Flua-resty-newrelic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saks","download_url":"https://codeload.github.com/saks/lua-resty-newrelic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saks%2Flua-resty-newrelic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271990416,"owners_count":24854703,"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","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"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":"2024-08-03T18:00:54.899Z","updated_at":"2025-08-25T01:22:33.687Z","avatar_url":"https://github.com/saks.png","language":"Lua","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"Name\n====\n\nlua-resty-newrelic - Lua newrelic SDK for the ngx_lua based on the C SDK.\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Status](#status)\n* [Description](#description)\n* [Synopsis](#synopsis)\n* [Installation](#installation)\n* [Bugs and Patches](#bugs-and-patches)\n* [Author](#author)\n* [Copyright and License](#copyright-and-license)\n\nStatus\n======\n\nThis library is considered production ready. By default SDK will send all data using SSL.\nAlso, SDK provides an option to turn on so called \"HIGH_SECURITY\" mode.\nSo far, it looks like it doesn't work even if you set \"NEWRELIC_ENABLE_HIGH_SECURITY\" env var to \"1\".\n\nDescription\n===========\n\nThis Lua library is a luajit ffi-based wrapper around [newrelic agent SDK](https://docs.newrelic.com/docs/agents/agent-sdk/installation-configuration/installing-agent-sdk) for the ngx_lua nginx module:\n\nThis library **can only** be used with luajit, **NOT** lua, because uses [luajit ffi](http://luajit.org/ext_ffi.html).\n\nSynopsis\n========\n\n```lua\n    http {\n        # you do not need the following line if you are using\n        # the OpenResty bundle:\n        lua_package_path \"/path/to/resty-newrelic/lib/?.lua;;\";\n\n        env NEWRELIC_APP_LICENSE_KEY=\u003cyour newrelic lincense key\u003e;\n        env NEWRELIC_APP_NAME=\u003cyour newrelic application name\u003e;\n\n        init_worker_by_lua_block {\n            require('resty.newrelic_agent').enable()\n        }\n\n        server {\n            location /test {\n                rewrite_by_lua_block {\n                    require('resty.newrelic_agent').start_web_transaction()\n                }\n\n                # here you can use any directive that generates response body like: try_files,\n                # proxy_pass, content_by_lua_*, etc.\n                content_by_lua_block {\n                    local newrelic = require 'resty.newrelic'\n                    local newrelic_agent = require 'resty.newrelic_agent'\n                    local nr_transaction_id = ngx.ctx.nr_transaction_id\n\n                    local call_remote_host = function(uri)\n                      ngx.log(ngx.ERR, 'Calling ' .. uri .. ' host...')\n                      ngx.sleep(math.random())\n                    end\n\n                    local redis = require 'resty.redis'\n                    local red = redis:new()\n                    red:set_timeout(math.random(1000))\n\n                    -- track database query\n                    local redis_connect_segment_id = newrelic.begin_datastore_segment(\n                    nr_transaction_id, newrelic.NEWRELIC_ROOT_SEGMENT, 'redis', 'connect')\n                    local connect_ok, connect_err = red:connect('127.0.0.1', 6379)\n                    newrelic.end_segment(nr_transaction_id, redis_connect_segment_id)\n\n                    -- increment custom metric\n                    if connect_ok then\n                      newrelic.record_metric('redis_client/new_connect', 1)\n                    else\n                      -- log error to newrelic\n                      newrelic_agent.notice_error('Failed to connect to redis',\n                      connect_err, debug.traceback(), '\\n')\n                    end\n\n                    -- track remote call\n                    local uri = 'http://google.com'\n                    local external_segment_id = newrelic.begin_external_segment(nr_transaction_id,\n                    newrelic.NEWRELIC_ROOT_SEGMENT, uri, 'google home page')\n                    call_remote_host(uri)\n                    newrelic.end_segment(nr_transaction_id, external_segment_id)\n                }\n\n                log_by_lua_block {\n                    require('resty.newrelic_agent').finish_web_transaction()\n                }\n            }\n        }\n    }\n```\n\nFor experimentation purposes you can play with docker container in the examples directory.\n```sh\nNEWRELIC_APP_LICENSE_KEY=\u003cyour license key\u003e docker-compose run --rm server\nIP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' examples_server_run_1)\ncurl $IP/test/1\n```\n\n[Back to TOC](#table-of-contents)\n\nInstallation\n============\n\nIf you are using the OpenResty bundle (http://openresty.org ), then\njust download lua file [newrelic.lua](https://github.com/saks/lua-resty-newrelic/blob/master/lib/resty/newrelic.lua)\nand [newrelic_agent.lua](https://github.com/saks/lua-resty-newrelic/blob/master/lib/resty/newrelic_agent.lua)\nfiles to the directiory where nginx will find it. Another way to install is to use\n[luarocks](https://luarocks.org/modules/saksmlz/resty-newrelic) package.\nAnd you can just use it in your Lua code,\nas in\n\n```lua\n    local newrelic = require \"resty.newrelic\"\n    ...\n```\n\nIf you are using your own nginx + ngx_lua build, then you need to configure\nthe lua_package_path directive to add the path of your resty-newrelic source\ntree to ngx_lua's LUA_PATH search path, as in\n\n```nginx\n    # nginx.conf\n    http {\n        lua_package_path \"/path/to/resty-newrelic/lib/?.lua;;\";\n        ...\n    }\n```\n\nEnsure that the system account running your Nginx ''worker'' proceses have\nenough permission to read the `.lua` file.\n\n[Back to TOC](#table-of-contents)\n\n\nBugs and Patches\n================\n\nPlease report bugs or submit patches by\n\n1. creating a ticket on the [GitHub Issue Tracker](http://github.com/saks/lua-resty-newrelic/issues),\n\n[Back to TOC](#table-of-contents)\n\nAuthor\n======\n\nAliaksandr \"saksmlz\" Rahalevich \u003csaksmlz__at__gmail.com\u003e.\n\n[Back to TOC](#table-of-contents)\n\nCopyright and License\n=====================\n\nThis module is licensed under the BSD license.\n\nCopyright (C) 2016, by Aliaksandr Rahalevich (saksmlz) \u003csaksmlz__at__gmail.com\u003e.\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n[Back to TOC](#table-of-contents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaks%2Flua-resty-newrelic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaks%2Flua-resty-newrelic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaks%2Flua-resty-newrelic/lists"}