An open API service indexing awesome lists of open source software.

https://github.com/serkan-ozal/stackwriter-serverless

StackWriter allows developers to be able to get, manipulate and send/report callstacks with local variables manually or automatically on error.
https://github.com/serkan-ozal/stackwriter-serverless

agent aws aws-lambda jvm jvmti serverless

Last synced: about 2 months ago
JSON representation

StackWriter allows developers to be able to get, manipulate and send/report callstacks with local variables manually or automatically on error.

Awesome Lists containing this project

README

        

# stackwriter-serverless

![license](https://img.shields.io/badge/License-Apache_2.0-blue.svg)
![maven-version](https://img.shields.io/maven-central/v/net.sozal/stackwriter)
![layer-version](https://api.globadge.com/v1/badgen/aws/lambda/layer/latest-version/us-east-1/273094347961/stackwriter) (badge powered by [Globadge serverless](https://www.globadge.com/badges/serverless))

`StackWriter` allows developers to be able to get, manipulate and send/report callstacks (frames in the stacktraces)
with local variables (name, type and value) manually (by programmatic API) or automatically (on error).

## Supported Environments

| Architecture/Runtime | `java8` | `java8.al2` | `java11` |
|:---------------------|:------------------:|:------------------:|:------------------:|
| **`x86_64`** | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| **`arm64`** | :x: | :x: | :x: |

## Installation

`StackWriter` serverless has 2 components (Agent and API) need to be installed:

- Add agent as layer into your AWS Lambda function:
```
arn:aws:lambda:${region}:273094347961:layer:stackwriter:${layer-version}
```

You can use the version shown below instead of `$layer-version}`:

![layer-version](https://api.globadge.com/v1/badgen/aws/lambda/layer/latest-version/us-east-1/273094347961/stackwriter) (badge powered by [Globadge serverless](https://www.globadge.com/badges/serverless))

- Add API as `provided` (no need to bundle it with the artifact as it is also available on AWS Lambda environment through by layer) dependency into your project:
```xml

net.sozal
stackwriter-api
${stackwriter.version}
provided

```

You can use the version shown below instead of ${stackwriter.version}.

![maven-version](https://img.shields.io/maven-central/v/net.sozal/stackwriter)

- Configure AWS Lambda function to use agent:

### `java8` (Java 8 on Amazon Linux) Runtime
- Set runtime to `Custom runtime`.

**Note:** `Custom runtime on Amazon Linux 2` is not supported yet.

### `java8.al2` (Java 8 on Amazon Linux 2) Runtime
- Set `AWS_LAMBDA_EXEC_WRAPPER` environment variable to `/opt/stackwriter_wrapper`.

### `java11` (Java 11 on Amazon Linux 2) Runtime
- Set `AWS_LAMBDA_EXEC_WRAPPER` environment variable to `/opt/stackwriter_wrapper`.

## Usage

### Getting callstack
```java
import net.sozal.stackwriter.api.StackWriter;
import net.sozal.stackwriter.api.StackWriter;
import net.sozal.stackwriter.api.domain.Frame;

...

System.out.println("FRAMES:");
for (Frame frame : StackWriter.takeSnapshot()) {
System.out.println(
String.format(
" - %s#%s@%d",
frame.getClazz().getName(),
frame.getMethod().getName(),
frame.getLine()));
Map locals = frame.getLocals();
for (LocalVariable local : locals.values()) {
String localVarName = local.getName();
Class localVarType = local.getType();
Object localVarValue = local.getValue();
System.out.println(
String.format(
" + %s: type=%s, value=%s",
localVarName, localVarType, localVarValue));
}
}
```

### Getting callstack from given start depth
```java
StackWriter.takeSnapshotWithStartDepth(2);
```

### Getting callstack with the frames at most as given max frame count
```java
StackWriter.takeSnapshotWithMaxFrameCount(10);
```

### Getting callstack from given start depth with the frames at most as given max frame count
```java
StackWriter.takeSnapshot(2, 10);
```

## Roadmap

- Automatically collect callstack on error (all errors or specified errors)
- `arm64` support
- Ability to send collected callstack to remote services (Webhook, Elasticsearch, Prometheus, etc ...)

## Contributing

Everyone is very welcome to contribute to this repository.
Feel free to [raise issues](https://github.com/serkan-ozal/stackwriter-serverless/issues)
or to [submit Pull Requests](https://github.com/serkan-ozal/stackwriter-serverless/pulls).

## License

Licensed under [Apache License 2.0](LICENSE).