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.
- Host: GitHub
- URL: https://github.com/serkan-ozal/stackwriter-serverless
- Owner: serkan-ozal
- License: apache-2.0
- Created: 2022-05-19T08:18:13.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-05-20T13:29:07.000Z (about 3 years ago)
- Last Synced: 2025-02-12T12:22:18.409Z (4 months ago)
- Topics: agent, aws, aws-lambda, jvm, jvmti, serverless
- Homepage:
- Size: 10.7 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stackwriter-serverless


 (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}`:
 (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:
```xmlnet.sozal
stackwriter-api
${stackwriter.version}
provided```
You can use the version shown below instead of ${stackwriter.version}.

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