# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.allstak.io/spring-boot-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
