Skip to content

Commit 2bf3628

Browse files
committed
adding kotlin page
1 parent c059a4f commit 2bf3628

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed
112 KB
Loading
171 KB
Loading
193 KB
Loading
273 KB
Loading
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Application Signals for Kotlin Services
2+
3+
## Introduction
4+
5+
Monitoring the performance and health of Kotlin web applications can be challenging due to the complex interactions between different components. [Kotlin](https://kotlinlang.org/) web services are usually built into Java Archive (jar) files, which can be deployed on any platform running Java. These applications often operate within distributed environments, involving multiple interconnected components such as databases, external APIs, and caching layers. This complexity can significantly escalate your Mean Time to Resolution (MTTR).
6+
7+
In this guide, we will demonstrate how to auto-instrument Kotlin web services that are running on a Linux EC2 server. Enabling [CloudWatch Application Signals](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Monitoring-Sections.html) allows for collection of telemetry from the application using [AWS Distro for OpenTelemetry](https://aws-otel.github.io/docs/introduction) (ADOT) Java Auto-Instrumentation Agent to collect metrics and traces from your applications without making any code changes. You can leverage key metrics such as call volume, availability, latency, faults, and errors to quickly see and triage current operational health of your application services and verify whether they are meeting the long term performance and business goals.
8+
9+
## Prerequisites
10+
11+
- A linux EC2 instance with the proper [IAM permissions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Application_Signals_Permissions.html) to interact with CloudWatch Application Signals. This guide leverages [Amazon Linux](https://aws.amazon.com/linux/amazon-linux-2023/) instance for this, so if you are using something else your commands may be slightly different.
12+
- The ability to [SSH](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-linux-inst-ssh.html) into the instance.
13+
14+
## Solution Overview
15+
16+
At a high level, the steps we will perform are the following.
17+
18+
- Enable CloudWatch Application Signals.
19+
- Deploy a [ktor web service](https://ktor.io/) in a fat jar.
20+
- Install the CloudWatch agent configured to receive Application Signals from the web service.
21+
- Download the [ADOT](https://aws-otel.github.io/docs/getting-started/java-sdk/auto-instr#introduction) Auto Instrumentation Agent.
22+
- Run our kotlin service jar alongside the java agent to auto-instrument the service.
23+
- Run some tests to generate telemetry.
24+
25+
### Architecture Diagram
26+
27+
![Architecture](./images/kotlin-arch.png)
28+
29+
### Enable CloudWatch Application Signals
30+
31+
Follow the instructions in Step 1: [Enable Application Signals](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Signals-Enable-EC2.html#CloudWatch-Application-Signals-EC2-Grant) in your account.
32+
33+
### Deploy a Ktor Web Service
34+
[Ktor](https://ktor.io/) is a popular kotlin framework for creating web services. It allows you to quickly get started with asynchronous server-side applications.
35+
36+
Create a working directory
37+
```
38+
mkdir kotlin-signals && cd kotlin-signals
39+
```
40+
41+
Clone the Ktor examples repo
42+
```
43+
git clone https://github.com/ktorio/ktor-samples.git && cd ktor-samples/structured-logging
44+
```
45+
46+
Build the application
47+
```
48+
./gradlew build && cd build/libs
49+
```
50+
51+
Test that the application runs
52+
```
53+
java -jar structured-logging-all.jar
54+
```
55+
56+
Assuming the service built and ran correctly, we can now stop it with `ctrl + c`
57+
58+
### Configure the CloudWatch Agent
59+
Amazon Linux instances have the CloudWatch agent installed by default. If your instance does not, you will need to [install](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-on-EC2-Instance.html) it.
60+
61+
Once installed, we can now create the configuration file.
62+
```
63+
sudo nano /opt/aws/amazon-cloudwatch-agent/bin/app-signals-config.json
64+
```
65+
66+
Copy and Paste the following configuration into the file
67+
```
68+
{
69+
"traces": {
70+
"traces_collected": {
71+
"app_signals": {}
72+
}
73+
},
74+
"logs": {
75+
"metrics_collected": {
76+
"app_signals": {}
77+
}
78+
}
79+
}
80+
```
81+
82+
Save the file and then start the CloudWatch agent with the config we just created
83+
```
84+
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/app-signals-config.json
85+
```
86+
87+
### Download the ADOT Auto Instrumenation Agent
88+
89+
Navigate to the directory that contains your jar file, we will put the agent here to make it easier for this demonstration. In a real scenario this would likely be in it's own folder.
90+
91+
```
92+
cd kotlin-signals/ktor-samples/structured-logging/build/libs
93+
```
94+
95+
Download the Auto Instrumentation Agent
96+
```
97+
wget https://github.com/aws-observability/aws-otel-java-instrumentation/releases/latest/download/aws-opentelemetry-agent.jar
98+
```
99+
100+
### Run your Ktor Service with the ADOT agent
101+
```
102+
OTEL_RESOURCE_ATTRIBUTES=service.name=KotlinApp,service.namespace=MyKotlinService,aws.hostedin.environment=EC2 \
103+
OTEL_AWS_APPLICATION_SIGNALS_ENABLED=true \
104+
OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT=http://localhost:4316/v1/metrics \
105+
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
106+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4316/v1/traces \
107+
OTEL_METRICS_EXPORTER=none \
108+
OTEL_LOGS_EXPORT=none \
109+
java -javaagent:aws-opentelemetry-agent.jar -jar structured-logging-all.jar
110+
```
111+
112+
### Generate Traffic to the Service to Create Telemetry
113+
```
114+
for i in {1..1800}; do curl http://localhost:8080 && sleep 2; done
115+
```
116+
117+
## Review Your Telemetry
118+
119+
You should now be able to see the Kotlin Service show up in the 'Services' section of CloudWatch
120+
121+
![kotlin-service](./images/kotlin-services.png)
122+
123+
You can also see our service in the 'Service Map'
124+
125+
![kotlin-service-map](./images/kotlin-service-map.png)
126+
127+
The instrumentation provides valuable metrics such as Latency:
128+
129+
![kotlin-metrics](./images/kotlin-metrics.png)
130+
131+
### Next Steps
132+
133+
From here your next steps would be to further explore the [Application Signals Experience](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Application-Monitoring-Sections.html) including creating [SLOs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-ServiceLevelObjectives.html) for your service. Another good next step would be to create more kotlin microservices in Ktor so you can start to put together a more complex backend. Distributed, complex environments are where you see the most benefit in a tool like Application Signals.
134+
135+
### Cleanup
136+
137+
Terminate your EC2 instance and delete the `/aws/appsignals/generic` log group.

docusaurus/sidebars.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ module.exports = {
220220
},
221221
],
222222
},
223+
{
224+
type: 'category',
225+
label: 'Application Signals',
226+
items: [
227+
'tools/application-signals/kotlin-signals',
228+
],
229+
},
223230
'tools/metrics',
224231
'tools/rum',
225232
'tools/synthetics',

0 commit comments

Comments
 (0)