{"id":20037998,"url":"https://github.com/perfectlysoft/perfect-newrelic-linux","last_synced_at":"2025-05-05T06:31:53.602Z","repository":{"id":63920171,"uuid":"89407209","full_name":"PerfectlySoft/Perfect-NewRelic-Linux","owner":"PerfectlySoft","description":"This project provides a Swift class wrapper for New Relic Agent SDK.","archived":false,"fork":false,"pushed_at":"2018-02-09T17:44:25.000Z","size":49,"stargazers_count":2,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-17T09:17:01.274Z","etag":null,"topics":["newrelic","perfect","performance-monitoring","profiling","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/PerfectlySoft.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-25T21:11:21.000Z","updated_at":"2023-06-11T14:37:03.000Z","dependencies_parsed_at":"2023-01-14T14:00:52.578Z","dependency_job_id":null,"html_url":"https://github.com/PerfectlySoft/Perfect-NewRelic-Linux","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-NewRelic-Linux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-NewRelic-Linux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-NewRelic-Linux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-NewRelic-Linux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerfectlySoft","download_url":"https://codeload.github.com/PerfectlySoft/Perfect-NewRelic-Linux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252451595,"owners_count":21749955,"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":["newrelic","perfect","performance-monitoring","profiling","swift"],"created_at":"2024-11-13T10:24:35.696Z","updated_at":"2025-05-05T06:31:53.300Z","avatar_url":"https://github.com/PerfectlySoft.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Perfect New Relic Library for Linux [简体中文](README.zh_CN.md)\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://perfect.org/get-involved.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.org/assets/github/perfect_github_2_0_0.jpg\" alt=\"Get Involed with Perfect!\" width=\"854\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/PerfectlySoft/Perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_1_Star.jpg\" alt=\"Star Perfect On Github\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://stackoverflow.com/questions/tagged/perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/perfect_gh_button_2_SO.jpg\" alt=\"Stack Overflow\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"https://twitter.com/perfectlysoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_3_twit.jpg\" alt=\"Follow Perfect on Twitter\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_4_slack.jpg\" alt=\"Join the Perfect Slack\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat\" alt=\"Swift 4.0\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Platforms-Linux%20-lightgray.svg?style=flat\" alt=\"Linux\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.org/licensing.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/License-Apache-lightgrey.svg?style=flat\" alt=\"License Apache\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://twitter.com/PerfectlySoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Twitter-@PerfectlySoft-blue.svg?style=flat\" alt=\"PerfectlySoft Twitter\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.ly/badge.svg\" alt=\"Slack Status\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nThis project provides a Swift Agent SDK for New Relic.\n\nThis package builds with Swift Package Manager and is part of the [Perfect](https://github.com/PerfectlySoft/Perfect) project but can be used as an independent module.\n\n## Release Note\n\nThis project is only compatible with Ubuntu 16.04 and Swift 4.0.3 Tool Chain.\n\n## Quick Start\n\nPlease use [Perfect Assistant](http://www.perfect.org/en/assistant/) to import this project, otherwise an install script is available for Ubuntu 16.04:\n\n```\n$ git clone https://github.com/PerfectlySoft/Perfect-NewRelic-linux.git\n$ cd Perfect-libNewRelic-linux\n$ sudo ./install.sh\n```\n\nDuring the installation, it will automatically ask for **license key**, **application name**, language and its version. Then it will install the command line `newrelic-collector-client-daemon` as a service which you can find the configuration on `/usr/local/etc/newrelic.service`.\n\nConfigure Package.swift:\n\n``` swift\n.Package(url: \"https://github.com/PerfectlySoft/Perfect-NewRelic-linux.git\", majorVersion: 3)\n```\n\nImport library into your code ( ⚠️**NOTE**⚠️ Since Swift 4.0.3 on linux has a significant linker issue, so module `PerfectNewRelic` must be accompanied with `Foundation` and `Dispatch`):\n\n``` swift\nimport PerfectNewRelic\nimport Foundation\nimport Dispatch\n```\n\nAside of Swift - C syntax conversion differences, document can be found on [New Relic Agent SDK](https://docs.newrelic.com/docs/agents/agent-sdk/using-agent-sdk/using-agent-sdk)\n\n## Configuration\n\nPost Installation \u0026 Configuration can be found on [New Relic - Configuring the Agent SDK](https://docs.newrelic.com/docs/agents/agent-sdk/installation-configuration/configuring-agent-sdk), please note that NewRelic instance is configured as **Daemon Mode** which is highly recommended because the *Embedded-mode* is still experimental.\n\nIf success, you can create NewRelic instance easily:\n\n``` swift\nlet nr = try NewRelic()\n```\n\n- Create a function to receive status change notifications:\n\n``` swift\nnr.registerStatus { code in\n\tguard let status = NewRelic.Status(rawValue: code) else {\n\t\t// something wrong here\n\t}//end guard\n\tswitch status {\n\t\tcase .STARTING: // New Relic Daemon Service is starting\n\t\tcase .STARTED: // New Relic Daemon Service is started\n\t\tcase .STOPPING: // New Relic Daemon Service is stopping\n\t\tdefault: // shutdown already\n   }//end case\n}//end callback\n```\n## Limiting or disabling Agent SDK settings\n\nAccording to [New Relic Limiting or disabling Agent SDK Settings](https://docs.newrelic.com/docs/agents/agent-sdk/installation-configuration/limiting-or-disabling-agent-sdk-settings), the following settings are available in Perfect NewRelic:\n\nIf you want to ... | Use this setting ...\n-------------------|---------------------\nDisable data collection during a transaction|`nr.enableInstrumentation(false)`\nConfigure the number of trace segments collected in a transaction trace|`let t = try Transaction(nr, maxTraceSegments: 50)` // // Only collect up to 50 trace segments\n\n## API Quick Help\n\nBase on [New Relic's Document of Using the Agent SDK](https://docs.newrelic.com/docs/agents/agent-sdk/using-agent-sdk/using-agent-sdk), Perfect NewRelic library provides identically the same functions of New Relic Agent SDK in Swift:\n\n### Instruments \u0026 Profiling\n\nFunction | `recordMetric()`\n---|---\nDemo|`try nr.recordMetric(name: \"ActiveUsers\", value: 25)`\nDescription|Record a custom metric.\nParameters| - name: name of the metric. \u003cbr\u003e - value: value of the metric.\n\nFunction | `recordCPU()`\n---|---\nDemo|`try nr.recordCPU(timeSeconds: 5.0, usagePercent: 1.2)`\nDescription|Record CPU user time in seconds and as a percentage of CPU capacity.\nParameters| - timeSeconds: Double, number of seconds CPU spent processing user-level code \u003cbr\u003e - usagePercent: Double, CPU user time as a percentage of CPU capacity\n\nFunction | `recordMemory()`\n---|---\nDemo|`try nr.recordMemory(megabytes: 32)`\nDescription|Record the current amount of memory being used.\nParameters| - megabytes: Double, amount of memory currently being used\n\n### Transaction\n\nTransaction in Perfect NewRelic has been defined as a class, with constructior as below:\n\n``` swift\npublic init(_ instance: NewRelic,\n    webType: Bool? = nil,\n    category: String? = nil,\n    name: String? = nil,\n    url: String? = nil,\n    attributes: [String: String],\n    maxTraceSegments: Int? = nil\n  ) throws\n```\n\n#### Constructor parameters:\n\n- instance: NewRelic instance, **required**.\n- webType: **optional**. true for WebTransaction and false for other. default is true.\n- category: **optional**. name of the transaction category, default is 'Uri'\n- name: **optional**. transaction name\n- url: **optional**. request url for a web transaction\n- attributes: **optional**. transaction attributes, pair of \"name: value\"\n- maxTraceSegments: **optional**. Set the maximum number of trace segments allowed in a transaction trace. By default, the maximum is set to 2000, which means the first 2000 segments in a transaction will create trace segments if the transaction exceeds the trace threshold (4 x apdex_t).\n\n#### Demo of Transaction Class Initialization:\n\n``` swift\nlet nr = NewRelic()\nlet t = try Transaction(nr, webType: false,\n\tcategory: \"my-class-1\", name: \"my-transaction-name\",\n\turl: \"http://localhost\",\n\tattributes: [\"tom\": \"jerry\", \"pros\":\"cons\", \"muddy\":\"puddels\"],\n\tmaxTraceSegments: 2000)\n```\n\n#### Error Notice\n\nPerfect NewRelic provides `setErrorNotice()` function for transactions:\n\n``` swift\ntry t.setErrorNotice(\n\texceptionType: \"my-panic-type-1\",\n\terrorMessage: \"my-notice\",\n\tstackTrace: \"my-stack\",\n\tstackFrameDelimiter: \"\u003cframe\u003e\")\n```\n\nParameters of `setErrorNotice()`:\n\n- exceptionType: type of exception that occurred\n- errorMessage: error message\n- stackTrace: print stack trace when error occurred\n- stackFrameDelimiter:  delimiter to split stack trace into frames\n\n#### Segments\n\nSegments in a transaction can be either Generic, DataStore or External, see demo below:\n\n``` swift\n// assume t is a transaction\ntry t.setErrorNotice(exceptionType: \"my-panic-type-1\", errorMessage: \"my-notice\", stackTrace: \"my-stack\", stackFrameDelimiter: \"\u003cframe\u003e\")\n\nlet root = try t.segBeginGeneric(name: \"my-segment\")\n// do some generic operations in this transaction\ntry t.segEnd(root)\n\n// NOTE: it will automatically obfuscate the sql input and rollup if failed as well\nlet sub = try t.segBeginDataStore(table: \"my-table\", operation: .INSERT, sql: \"INSERT INTO table(field) value('000-000-0000')\")\n// do some data operations in this transaction\ntry t.segEnd(sub)\n\nlet s2 = try t.segBeginExternal(host: \"perfect.org\", name: \"my-seg\")\n// do some external operations in this transaction\ntry t.segEnd(s2)\n```\n\nParameters:\n\n- parentSegmentId: id of parent segment, root segment by default, i.e., ` NewRelic.ROOT_SEGMENT`.\n- name: name to represent segment\n\n## Further Information\nFor more information on the Perfect project, please visit [perfect.org](http://perfect.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperfectlysoft%2Fperfect-newrelic-linux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperfectlysoft%2Fperfect-newrelic-linux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperfectlysoft%2Fperfect-newrelic-linux/lists"}