---
title: "Custom Profiling Instrumentation for Java"
slug: "custom-profiling-configure-for-java"
description: "Leverage Custom Instrumentation & Tracked Functions in Stackify Python Profiler 1.1+. Easily track classes & methods for detailed insights. "
updated: 2019-11-21T21:31:38Z
published: 2019-11-21T21:31:38Z
---

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

# Custom Instrumentation

The custom configuration file needs to be named 'stackify-apm.json' and be located in the classpath. You can configure additional classes and methods that you want to instrument. Example:

```
[
    {
        "Class": "com.stackify.example.util.ClassToBeInstrumented",
        "Method": "methodToBeInstrumented"
    },
    {
        "Class": "com.stackify.example.util.ClassToBeInstrumented",
        "Method": "anotherMethodToBeInstrumented"
    }
]
```

You can also add custom instrumentation to classes by using @Trace Annotation. See more information on our Github page here: [https://github.com/stackify/stackify-java-apm-annot](https://github.com/stackify/stackify-java-apm-annot) Once the configuration has been saved, please restart the Web container.

## **Tracked Functions**

- **trackedFunction** marks a specific method as a tracked function.
- **trackedFunctionName** gives control over how the tracked function will be identified in the dashboard. The function name can be a `String` and can also include the variables `{{ClassName}}`, `{{MethodName}}` and `{{MethodParameters[#]}}`(where `#` is an `int` referencing the parameter index on the annotated method, index starts at 0).

```
import com.stackify.apm.Trace;

@Trace
public class ClassToBeInstrumented 
{
    @Trace
    public void methodToBeInstrumented()
    {
        ...
    }

    @Trace
    public void anotherMethodToBeInstrumented()
    {
        ...
    }

    @Trace(trackedFunction = true, trackedFunctionName = "Tracked Function Identifier")
    public void anotherMethodToBeInstrumentedAndMarkedAsTrackedFunction()
    {
        ...
    }

    @Trace(trackedFunction = true, trackedFunctionName = "Tracked Function {{ClassName}} - {{MethodParameters\[0\]}}")
    public void anotherMethodToBeInstrumentedAndMarkedAsTrackedFunctionVariable(String value)
    {
        ...
    }

    public void notInstrumented()
    {
        ...
    }
}
```

## Custom Trace Entry Point

Retrace by default generates traces from web-requests on supported application servers and non-web-requests from supported frameworks ([Retrace: Supported Java Application Containers and Frameworks](/docs/java-supported-application-containers-and-frameworks)). You can extend support by using `@Trace(start = true)` on a method; which will start a new trace.

```
[
    {
        "Class": "com.stackify.example.util.ClassToBeInstrumented",
        "Method": "methodToBeInstrumented",
        "StartTrace": true
    },
    {
        "Class": "com.stackify.example.util.ClassToBeInstrumented",
        "Method": "methodToBeInstrumented"
    }
]
```

**JSON Configuration:**

```
[
    {
        "Class": "com.company.SampleController",
        "Method": "testMethod",
        "TrackedFunction": true,
        "TrackedFunctionName": "Tracked Function Test {{ClassName}}.{{MethodName}}"
    }
]
```
