> ## Documentation Index
> Fetch the complete documentation index at: https://docs.odigos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Attributes

> The "Code Attributes" rule can be used to add [semantic Code attributes](https://opentelemetry.io/docs/specs/semconv/attributes-registry/code/) to spans. Code attributes can help trace back an operation in a trace to the code that generated it.

## Considerations

<Warning>
  Before enabling **code attributes**, please note the following:

  * Size of `code.stacktrace` can be large and may increase the size of your spans. This can impact the performance of your application and the cost of processing, storing and analyzing traces.
  * Code attributes have various level of support, depending on the programming language and instrumentation library used.
</Warning>

## Configuration Options

<AccordionGroup>
  <Accordion title="column">
    **column** `boolean` : Indicates whether to record the `code.column` attribute for the column number in the `code.filepath` best representing the operation.

    * This field is *optional*, and defaults to `false`
  </Accordion>

  <Accordion title="filePath">
    **filePath** `boolean` : Indicates whether to record the `code.filepath` attribute for the source code file name that identifies the code unit.

    * This field is *optional*, and defaults to `false`
  </Accordion>

  <Accordion title="function">
    **function** `boolean` : Indicates whether to record the `code.function` attribute for the method or function name, or equivalent.

    * This field is *optional*, and defaults to `false`
  </Accordion>

  <Accordion title="lineNumber">
    **lineNumber** `boolean` : Indicates whether to record the `code.lineno` attribute for the line number in the `code.filepath` best representing the operation.

    * This field is *optional*, and defaults to `false`
  </Accordion>

  <Accordion title="namespace">
    **namespace** `boolean` : Indicates whether to record the `code.namespace` attribute for the “namespace” within which `code.function` is defined. Usually the qualified class or module name, such that `code.namespace` + some separator + `code.function` form a unique identifier for the code unit.

    * This field is *optional*, and defaults to `false`
  </Accordion>

  <Accordion title="stackTrace">
    **stackTrace** \`boolean

    * This field is *optional*, and defaults to `false`
  </Accordion>
</AccordionGroup>

<Note>
  Any unspecified options will be set to the default value of `false` (not recorded).
</Note>

## Basic Example

The following example demonstrates how to enable code attributes for all supported workloads and instrumentation libraries in the cluster.

<Steps>
  <Step>
    Create a YAML file with the following content:

    ```yaml code-attributes.yaml theme={null}
    apiVersion: odigos.io/v1alpha1
    kind: InstrumentationRule
    metadata:
      name: collect-all-payloads
      namespace: odigos-system
    spec:
      ruleName: "collect all supported code attributes"
      codeAttributes:
        column: false
        filePath: true # recommended
        function: true # recommended
        lineNumber: true # recommended
        namespace: false
        stackTrace: false
    ```
  </Step>

  <Step>
    Apply the action to the cluster:

    ```shell theme={null}
    kubectl apply -f code-attributes.yaml
    ```
  </Step>
</Steps>
