---
title: Code-level metrics
source: https://docs.newrelic.com/docs/apm/agents/ruby-agent/features/ruby-code-level-metrics
---

Code-level metrics are span attributes that the Ruby agent attaches to your application's spans, pinpointing the exact method and class responsible for a given span. This allows you to be more proactive about addressing performance issues as you review your code. You can view these attributes on individual spans in [distributed tracing](https://docs.newrelic.com/docs/distributed-tracing/ui-data/understand-use-distributed-tracing-data/), or query them directly with [NRQL](https://docs.newrelic.com/docs/nrql/get-started/introduction-nrql-new-relics-query-language/).

> #### ⚠️ IMPORTANT
>
> Code-level metrics are available in Ruby agent version 8.8.0 and higher. For versions 8.10.0 and higher, code-level metrics are enabled by default. For versions 8.8.0 and 8.9.0 they must be enabled via configuration. To enable code-level metrics, either set `code_level_metrics.enabled: true` in `newrelic.yml` or `NEW_RELIC_CODE_LEVEL_METRICS_ENABLED=true` as an environment variable.

## Agent attributes

The Ruby agent reports and attaches the following attributes to spans produced by your application:

| **Name**         | **Description**                                                                                           | **Example**                                |
| ---------------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| `code.function`  | The name of the instrumented function (Ruby method). Note that class methods will be prefixed by `self.`. | create                                     |
| `code.filepath`  | The absolute path to the source code file in which `code.function` is defined                             | /app/app/controllers/widgets_controller.rb |
| `code.lineno`    | The line number where `code.function` is defined in code.filepath                                         | 1138                                       |
| `code.namespace` | The namespace (class or module name) in which `code.function` is defined                                  | WidgetsController                          |

> #### ⚠️ IMPORTANT
>
> Not every method in your application code will be instrumented with the above attributes. As of version 8.10.0, the Ruby agent will provide code-level metrics for Rails controller methods, `ActiveJob` methods, and any Ruby method which has been configured to be manually traced.
