{"id":20414497,"url":"https://github.com/codecov/impact-analysis-example-ruby","last_synced_at":"2025-04-12T16:45:45.223Z","repository":{"id":37003318,"uuid":"504233020","full_name":"codecov/impact-analysis-example-ruby","owner":"codecov","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-07T12:48:55.000Z","size":10163,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-11T15:10:25.608Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/codecov.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-16T16:43:12.000Z","updated_at":"2025-03-20T16:45:26.000Z","dependencies_parsed_at":"2023-11-07T05:05:53.295Z","dependency_job_id":"9a9bd57b-d311-4ec1-b255-5b5b3e386930","html_url":"https://github.com/codecov/impact-analysis-example-ruby","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/codecov%2Fimpact-analysis-example-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecov%2Fimpact-analysis-example-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecov%2Fimpact-analysis-example-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecov%2Fimpact-analysis-example-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codecov","download_url":"https://codeload.github.com/codecov/impact-analysis-example-ruby/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248600625,"owners_count":21131518,"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":[],"created_at":"2024-11-15T06:10:23.739Z","updated_at":"2025-04-12T16:45:45.194Z","avatar_url":"https://github.com/codecov.png","language":"Ruby","readme":"# Ruby RTI Example\n\n[![codecov](https://codecov.io/gh/codecov/impact-analysis-example-ruby/branch/main/graph/badge.svg)](https://codecov.io/gh/codecov/impact-analysis-example-ruby)\n\nThis repository demonstrating how to use Codecov's [Impact Analysis](https://about.codecov.io/product/feature/impact-analysis/) feature with ruby. It runs with the [Rails](https://rubyonrails.org/) framework and leverages the [codecov/opentelem-ruby](https://github.com/codecov/opentelem-ruby) package to send information to Codecov's Runtime Insights API.\n\nThis repository is set up to do to be used as\n1. a working sandbox to explore Impact Analysis\n1. a reference for adding Impact Analysis to your own repositories\n\n## Getting Started\n\nThe following section details how to get started with Impact Analysis. Before getting started, you will need\n1. `ruby` version 3+\n2. An account on [Codecov](https://about.codecov.com)\n\n\u003cbr /\u003e\n\n**Step 1: Fork and clone this repository**\n-------------\n\n[Fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository) this repository from GitHub. It is strongly recommended that you fork the repository to your personal GitHub account.\nClone your new repository to your local machine.\n\n\u003cbr /\u003e\n\n**Step 2: Set the `profiling token`**\n-------------\n\nGo to [Codecov](https://app.codecov.io/gh) and find the fork in the list of repositories. Note that it may be under `Not yet setup` in the right-hand section.\n\nIn the `settings` page, grab the `Impact analysis token`, and set the token locally in a terminal.\n```\nexport CODECOV_OPENTELEMETRY_TOKEN='***'\n```\n\n\u003cbr /\u003e\n\n**Step 3: Install the dependencies**\n-------------\n\nInstall all dependencies for this project.\n```\nbundle install\n```\n\n\u003cbr /\u003e\n\n**Step 4: Run the server locally and generate profiling data**\n-------------\n\nRun the server from your machine using the command\n```\n./bin/rails server\n```\nIf the token has been set properly, you should see the server running with the following logs\n```\n=\u003e Booting Puma\n=\u003e Rails 7.0.3.1 application starting in development\n=\u003e Run `bin/rails server --help` for more startup options\n...\nPuma starting in single mode...\n* Puma version: 5.6.4 (ruby 3.1.2-p20) (\"Birdie's Version\")\n*  Min threads: 5\n*  Max threads: 5\n*  Environment: development\n*          PID: 95097\n* Listening on http://127.0.0.1:3000\n* Listening on http://[::1]:3000\nUse Ctrl-C to stop\n```\n\nYou can view the app by going to `http://127.0.0.1:3000/`.\nThe app has two pages, the main page that has a button to `Get the time`, while the other page displays the time.\n\n\u003cbr /\u003e\n\n**Step 5: Overloading the `/time` endpoint**\n-------------\n\nIn order for us to see what happens when we change a critical (frequently hit) line, we will need to hit the `/time` endpoint. In a python shell, run the following with the server running\n```\nimport requests\n\nfor i in range(1000):\n    print(i)\n    requests.get('http://127.0.0.1:3000/time')\n```\nThis should hit our `/time` endpoint 1000 times and upload the telemetry data to Codecov.\n\nYou may need to wait an hour or two before continuing to the next step for the profiling data to be processed by Codecov.\n\n\u003cbr /\u003e\n\n**Step 6: Making a change to critical code**\n-------------\n\nLet's now make a change in our code to see if what we are changing is critical.\n\nIn `app/helpers/timer_helper.rb`, update line 7 from\n```\n    time.strftime('%Y-%m-%d:%H:%M:%S')\n```\nto\n```\n    time.strftime('%Y-%m-%d::%H:%M:%S')\n```\n\n\nYou will also need to update the tests. Change line 7 of `spec/helpers/timer_helper_spec`\n```\n      expect(helper.format_time(current_time)).to eql(current_time.strftime('%Y-%m-%d:%H:%M:%S'))\n```\nto\n```\n      expect(helper.format_time(current_time)).to eql(current_time.strftime('%Y-%m-%d::%H:%M:%S'))\n```\n\nSave the changes, create a new branch, and push to GitHub.\n```\ngit checkout -b 'test-codecov'\ngit add example-app/\ngit commit -m 'fix: update time display with colon'\ngit push origin test-codecov\n```\nOpen a new pull request. Be sure to set the base branch to your fork.\n\n\u003cbr /\u003e\n\n**Step 7: Seeing Impact Analysis in the UI**\n-------------\n\nAfter CI/CD has completed, you should see a comment from Codecov similar to this [PR](https://github.com/codecov/impact-analysis-example-ruby/pull/23). The comment will now show 2 new elements\n\n1. Under `impacted files`, you should see a `Critical` label next to `app/helpers/timer_helper.rb`. This means that the PR has a change in that file that is frequently hit in production.\n2. Under `related entrypoints`, you should see `action_view render_template`. This means that the PR has a change that touches that endpoint.\n\nYou should now be able to see how Impact Analysis can give crucial information on how a code change can affect critical code in your system.\n\n### Troubleshooting\n------------\nYou may need to add profiling fixes to your application. You can do this in the `codecov.yml` file under `profiling -\u003e fixes`. We recommend finding the full path of the environment that is sending telemetry data (e.g. local or CI) and using the portion from the beginning to the repository name on the left side of the fixes.\n\nFor example, if running locally, the full path might be\n\n```\n/Users/localuser/src/github/codecov/impact-analysis-example-ruby/...\n```\n\nThe `codecov.yml` should add the following\n```\nprofiling:\n  fixes:\n    - \"/Users/localuser/src/github/codecov/impact-analysis-example-ruby::\"\n```\n\n### Using your own repositories\nTo get started with Impact Analysis on your own repositories, check out our getting started [guide](https://docs.codecov.com/docs/impact-analysis-quickstart-ruby).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecov%2Fimpact-analysis-example-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodecov%2Fimpact-analysis-example-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecov%2Fimpact-analysis-example-ruby/lists"}