> For the complete documentation index, see [llms.txt](https://docs.allstak.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.allstak.io/spring-boot-sdk.md).

# Spring Boot SDK

## AllStak Spring Boot SDK Installation Guide

### Step 1: Add the AllStak Dependency

To integrate AllStak with your Spring Boot application, add the following dependency to your `pom.xml`:

```xml
<dependency>
    <groupId>io.allstak</groupId>
    <artifactId>allstak-springboot</artifactId>
    <version>1.0.4</version>
</dependency>
```

For Gradle users, add this to `build.gradle`:

```gradle
dependencies {
    implementation 'io.allstak:allstak-springboot:1.0.4'
}
```

### Step 2: Configure AllStak Properties

Add the following properties to your `application.properties` or `application.yml` file:

#### For `application.properties`:

```properties
allstak.api-key=your-api-key
allstak.environment=dev
allstak.release=1.0.0
```

#### For `application.yml`:

```yaml
allstak:
  api-key: your-api-key
  environment: dev
  release: 1.0.0
```

### Step 3: Capture Exceptions with AllStak

To automatically capture exceptions, add the following snippet inside a `try-catch` block:

```java
try {
    // Your application logic here
} catch (Exception e) {
    AllStak.captureException(e);
}
```

This ensures that all unhandled exceptions are logged and sent to AllStak for monitoring.

### Step 4: Enable Global Exception Handling (Optional)

To globally capture exceptions in your Spring Boot application, you can use `@ControllerAdvice` as follows:

```java
import io.allstak.AllStak;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String handleException(Exception e) {
        AllStak.captureException(e);
        return "An error occurred. The issue has been logged.";
    }
}
```

This setup ensures that all exceptions in your application are automatically sent to AllStak for tracking and debugging.

***

### Additional Notes

* Ensure that your API key is kept secure and not exposed in public repositories.
* The `allstak.environment` property allows you to specify different environments (e.g., `dev`, `staging`, `prod`).
* The `allstak.release` property helps track issues across different application versions.

By following these steps, you will have successfully integrated AllStak with your Spring Boot application for enhanced error monitoring and tracking.
