Skip to content

Commit d18e866

Browse files
authored
Merge pull request #4926 from streamfold/clickstack-int-aws-lambda
Add AWS Lambda logs integration with Rotel
2 parents 7b0a1fb + ff8c4cf commit d18e866

File tree

4 files changed

+332
-1
lines changed

4 files changed

+332
-1
lines changed
Lines changed: 330 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,330 @@
1+
---
2+
slug: /use-cases/observability/clickstack/integrations/aws-lambda
3+
title: 'Monitoring AWS Lambda Logs with ClickStack using Rotel'
4+
sidebar_label: 'AWS Lambda Logs'
5+
pagination_prev: null
6+
pagination_next: null
7+
description: 'Monitoring AWS Lambda Logs with ClickStack using Rotel'
8+
doc_type: 'guide'
9+
keywords: ['AWS', 'Lambda', 'OTEL', 'ClickStack', 'logs', 'CloudWatch']
10+
---
11+
12+
import Image from '@theme/IdealImage';
13+
import useBaseUrl from '@docusaurus/useBaseUrl';
14+
import log_view from '@site/static/images/clickstack/lambda/lambda-log-view.png';
15+
import log from '@site/static/images/clickstack/lambda/lambda-log.png';
16+
import CommunityMaintainedBadge from '@theme/badges/CommunityMaintained';
17+
18+
# Monitoring AWS Lambda Logs with ClickStack using Rotel {#lambda-clickstack}
19+
20+
<CommunityMaintainedBadge/>
21+
22+
:::note[TL;DR]
23+
This guide shows you how to monitor AWS Lambda functions with ClickStack by using the Rotel Lambda Extension to collect and forward function logs, extension logs, and OpenTelemetry data directly to ClickHouse. You'll learn how to:
24+
25+
- Deploy the Rotel Lambda Extension layer to your Lambda functions
26+
- Configure the extension to export logs and traces to ClickStack
27+
- Optionally disable CloudWatch Logs to reduce costs
28+
29+
This approach can significantly reduce your Lambda observability costs by bypassing CloudWatch Logs entirely.
30+
31+
Time Required: 5-10 minutes
32+
:::
33+
34+
## Integration with existing Lambda functions {#existing-lambda}
35+
36+
This section covers configuring your existing AWS Lambda functions to send logs and traces to ClickStack using the Rotel Lambda Extension.
37+
38+
### Prerequisites {#prerequisites}
39+
- ClickStack instance running
40+
- AWS Lambda function(s) to monitor
41+
- AWS CLI configured with appropriate permissions
42+
- Lambda execution role with permissions to add layers
43+
44+
<VerticalStepper headerLevel="h4">
45+
46+
#### Choose the appropriate Rotel Lambda Extension layer {#choose-layer}
47+
48+
The [Rotel Lambda Extension](https://github.com/streamfold/rotel-lambda-extension) is available as a pre-built AWS Lambda layer. Choose the layer ARN that matches your Lambda function's architecture:
49+
50+
| Architecture | ARN Pattern | Latest Version |
51+
|--------------|-------------|----------------|
52+
| x86-64/amd64 | `arn:aws:lambda:{region}:418653438961:layer:rotel-extension-amd64-alpha:{version}` | ![Version](https://img.shields.io/github/v/release/streamfold/rotel-lambda-extension?filter=*alpha&label=version&labelColor=%2338BDF8&color=%23312E81&cacheSeconds=600) |
53+
| arm64 | `arn:aws:lambda:{region}:418653438961:layer:rotel-extension-arm64-alpha:{version}` | ![Version](https://img.shields.io/github/v/release/streamfold/rotel-lambda-extension?filter=*alpha&label=version&labelColor=%2338BDF8&color=%23312E81&cacheSeconds=600) |
54+
55+
**Available regions:**
56+
- us-east-{1, 2}, us-west-{1, 2}
57+
- eu-central-1, eu-north-1, eu-west-{1, 2, 3}
58+
- ca-central-1
59+
- ap-southeast-{1, 2}, ap-northeast-{1, 2}
60+
- ap-south-1
61+
- sa-east-1
62+
63+
#### Add the Rotel layer to your Lambda function {#add-layer}
64+
65+
_In these examples replace `{arch}`, `{region}`, and `{version}` with the appropriate values above._
66+
67+
##### Option 1: AWS Console {#console}
68+
69+
1. Open the AWS Lambda console
70+
2. Navigate to your Lambda function
71+
3. Scroll to the **Layers** section and click **Add a layer**
72+
4. Select **Specify an ARN**
73+
5. Enter the Rotel layer ARN:
74+
```text
75+
arn:aws:lambda:{region}:418653438961:layer:rotel-extension-{arch}-alpha:{version}
76+
```
77+
6. Click **Add**
78+
79+
##### Option 2: AWS CLI {#cli}
80+
81+
```bash
82+
aws lambda update-function-configuration \
83+
--function-name my-function \
84+
--layers arn:aws:lambda:{region}:418653438961:layer:rotel-extension-{arch}-alpha:{version}
85+
```
86+
87+
##### Option 3: AWS SAM {#sam}
88+
89+
```yaml
90+
Resources:
91+
MyFunction:
92+
Type: AWS::Serverless::Function
93+
Properties:
94+
# ... other configuration ...
95+
Layers:
96+
- arn:aws:lambda:{version}:418653438961:layer:rotel-extension-{arch}-alpha:{version}
97+
```
98+
99+
#### Configure the extension to export to ClickStack {#configure-extension}
100+
101+
The Rotel Lambda Extension is configured using environment variables. You need to configure the OTLP exporter endpoint to point to your ClickStack instance. The examples assume your AWS Lambda function is able to reach the ClickStack instance.
102+
103+
##### Basic configuration (environment variables) {#basic-config}
104+
105+
Add these environment variables to your Lambda function:
106+
107+
```bash
108+
# Required: ClickStack OTLP endpoint
109+
ROTEL_OTLP_EXPORTER_ENDPOINT=https://clickstack.example.com:4317
110+
111+
# Optional: Authentication headers
112+
ROTEL_OTLP_EXPORTER_CUSTOM_HEADERS="Authorization=<YOUR_INGESTION_API_KEY>"
113+
114+
# Optional: Service name (defaults to Lambda function name)
115+
ROTEL_OTEL_RESOURCE_ATTRIBUTES="service.name=my-lambda-api,service.version=1.0.0"
116+
```
117+
118+
##### Advanced configuration (using .env file) {#advanced-config}
119+
120+
For more complex configurations, create a `rotel.env` file in your Lambda function bundle:
121+
122+
**rotel.env:**
123+
```bash
124+
ROTEL_OTLP_EXPORTER_ENDPOINT=https://clickstack.example.com:4317
125+
ROTEL_OTLP_EXPORTER_CUSTOM_HEADERS="Authorization=<YOUR_INGESTION_API_KEY>"
126+
ROTEL_OTEL_RESOURCE_ATTRIBUTES="service.name=my-lambda-api,deployment.environment=production"
127+
```
128+
129+
Then set the environment variable to point to this file:
130+
```bash
131+
ROTEL_ENV_FILE=/var/task/rotel.env
132+
```
133+
134+
##### Using AWS Secrets Manager or Parameter Store {#secrets}
135+
136+
For production deployments, store sensitive values like API keys in AWS Secrets Manager or Parameter Store:
137+
138+
**AWS Secrets Manager Example:**
139+
```bash
140+
ROTEL_OTLP_EXPORTER_ENDPOINT=https://clickstack.example.com:4317
141+
ROTEL_OTLP_EXPORTER_CUSTOM_HEADERS="Authorization=${arn:aws:secretsmanager:us-east-1:123456789012:secret:clickstack-api-key-abc123}"
142+
```
143+
144+
**AWS Parameter Store Example:**
145+
```bash
146+
ROTEL_OTLP_EXPORTER_ENDPOINT=https://clickstack.example.com:4317
147+
ROTEL_OTLP_EXPORTER_CUSTOM_HEADERS="Authorization=${arn:aws:ssm:us-east-1:123456789012:parameter/clickstack-api-key}"
148+
```
149+
150+
**Required IAM Permissions:**
151+
152+
Add these permissions to your Lambda execution role:
153+
154+
For Secrets Manager:
155+
```json
156+
{
157+
"Version": "2012-10-17",
158+
"Statement": [
159+
{
160+
"Effect": "Allow",
161+
"Action": [
162+
"secretsmanager:GetSecretValue",
163+
"secretsmanager:BatchGetSecretValue"
164+
],
165+
"Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:clickstack-api-key-*"
166+
}
167+
]
168+
}
169+
```
170+
171+
For Parameter Store:
172+
```json
173+
{
174+
"Version": "2012-10-17",
175+
"Statement": [
176+
{
177+
"Effect": "Allow",
178+
"Action": [
179+
"ssm:GetParameters"
180+
],
181+
"Resource": "arn:aws:ssm:us-east-1:123456789012:parameter/clickstack-api-key"
182+
}
183+
]
184+
}
185+
```
186+
187+
:::note
188+
AWS API calls for secret retrieval add 100-150ms to cold start latency. Secrets are retrieved in batches (up to 10) and only on initialization, so subsequent invocations are not impacted.
189+
:::
190+
191+
#### Test the integration {#test-integration}
192+
193+
Invoke your Lambda function to verify logs are being sent to ClickStack:
194+
195+
```bash
196+
aws lambda invoke \
197+
--function-name my-function \
198+
--payload '{"test": "data"}' \
199+
response.json
200+
```
201+
202+
Check the Lambda logs for any errors:
203+
```bash
204+
aws logs tail /aws/lambda/my-function --follow
205+
```
206+
207+
#### Verify logs in HyperDX {#verify-logs}
208+
209+
Once configured, log into HyperDX (ClickStack's UI) and verify that logs are flowing:
210+
211+
<Image img={log_view} alt="Lambda Log View"/>
212+
213+
<Image img={log} alt="Lambda Log Detail"/>
214+
215+
Look for these key attributes in the logs:
216+
- `service.name`: Your Lambda function name
217+
- `faas.name`: AWS Lambda function name
218+
- `faas.invocation_id`: Unique invocation ID
219+
- `cloud.provider`: "aws"
220+
- `cloud.platform`: "aws_lambda"
221+
222+
</VerticalStepper>
223+
224+
## Disabling CloudWatch Logs (cost optimization) {#disable-cloudwatch}
225+
226+
By default, AWS Lambda sends all logs to CloudWatch Logs, which can be expensive at scale. Once you've verified that logs are flowing to ClickStack, you can disable CloudWatch logging to reduce costs.
227+
228+
<VerticalStepper headerLevel="h4">
229+
230+
#### Remove CloudWatch permissions from the execution role {#remove-permissions}
231+
232+
1. Open the AWS Console and navigate to **AWS Lambda**
233+
2. Navigate to your Lambda function
234+
3. Select **Configuration****Permissions**
235+
4. Click the execution role name to open the IAM console
236+
5. Edit the role and remove any `logs:*` actions:
237+
- If using a custom policy, edit to remove `logs:CreateLogGroup`, `logs:CreateLogStream`, and `logs:PutLogEvents`
238+
- If using the AWS managed policy `AWSLambdaBasicExecutionRole`, remove it from the role
239+
6. Save the role
240+
241+
#### Verify CloudWatch logging is disabled {#verify-disabled}
242+
243+
Invoke your function again and verify that:
244+
1. No new CloudWatch log streams are created
245+
2. Logs continue to appear in ClickStack/HyperDX
246+
247+
```bash
248+
# This should show no new log streams after the policy change
249+
aws logs describe-log-streams \
250+
--log-group-name /aws/lambda/my-function \
251+
--order-by LastEventTime \
252+
--descending \
253+
--max-items 5
254+
```
255+
256+
</VerticalStepper>
257+
258+
## Adding OpenTelemetry auto-instrumentation {#auto-instrumentation}
259+
260+
The Rotel Lambda Extension works seamlessly with OpenTelemetry auto-instrumentation layers to collect distributed traces and metrics in addition to logs.
261+
262+
<VerticalStepper headerLevel="h4">
263+
264+
#### Choose your language instrumentation layer {#choose-instrumentation}
265+
266+
AWS provides OpenTelemetry auto-instrumentation layers for multiple languages:
267+
268+
| Language | Layer ARN Pattern |
269+
|----------|-------------------|
270+
| Node.js | `arn:aws:lambda:{region}:901920570463:layer:aws-otel-nodejs-{arch}-ver-{version}` |
271+
| Python | `arn:aws:lambda:{region}:901920570463:layer:aws-otel-python-{arch}-ver-{version}` |
272+
| Java | `arn:aws:lambda:{region}:901920570463:layer:aws-otel-java-agent-{arch}-ver-{version}` |
273+
274+
Find the latest versions in the [AWS OpenTelemetry Lambda repository](https://github.com/aws-observability/aws-otel-lambda).
275+
276+
#### Add both layers to your function {#add-both-layers}
277+
278+
Add **both** the Rotel extension layer and the instrumentation layer:
279+
280+
```bash
281+
aws lambda update-function-configuration \
282+
--function-name my-function \
283+
--layers \
284+
arn:aws:lambda:{region}:418653438961:layer:rotel-extension-{arch}-alpha:{version} \
285+
arn:aws:lambda:{region}:901920570463:layer:aws-otel-nodejs-{arch}-ver-1-30-2:1
286+
```
287+
288+
#### Configure the auto-instrumentation {#configure-instrumentation}
289+
290+
Set the `AWS_LAMBDA_EXEC_WRAPPER` environment variable to enable auto-instrumentation:
291+
292+
**For Node.js:**
293+
```bash
294+
AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
295+
```
296+
297+
**For Python:**
298+
```bash
299+
AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-instrument
300+
```
301+
302+
**For Java:**
303+
```bash
304+
AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
305+
```
306+
307+
#### Verify traces in HyperDX {#verify-traces}
308+
309+
After invoking your function:
310+
311+
1. Navigate to the **Traces** view in HyperDX
312+
2. You should see traces with spans from your Lambda function
313+
3. Traces will be correlated with logs via `trace_id` and `span_id` attributes
314+
315+
</VerticalStepper>
316+
317+
## Example applications {#examples}
318+
319+
Checkout the example Python app demonstrating the Rotel Lambda Extension:
320+
321+
- **[Python + ClickHouse](https://github.com/streamfold/python-aws-lambda-clickhouse-example)**: Python application with manual OpenTelemetry instrumentation, sending traces and logs directly to ClickHouse
322+
323+
## Join the Rotel community {#join-rotel-community}
324+
325+
If you have questions about Rotel, please join the [Rotel Discord server](https://rotel.dev) and share your feedback or questions. Check out the [Rotel Lambda Extension](https://github.com/streamfold/rotel-lambda-extension) to contribute any improvements.
326+
327+
## Additional resources {#resources}
328+
329+
- **[Rotel Lambda Extension](https://github.com/streamfold/rotel-lambda-extension)**: Source code and detailed documentation
330+
- **[Rotel Core](https://github.com/streamfold/rotel)**: The lightweight OTEL data plane powering the extension

docs/use-cases/observability/clickstack/integration-examples/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ Several of these integration guides use ClickStack's built-in OpenTelemetry Coll
2525
| [PostgreSQL Logs](/use-cases/observability/clickstack/integrations/postgresql-logs) | Quick start guide for PostgreSQL Logs |
2626
| [PostgreSQL Metrics](/use-cases/observability/clickstack/integrations/postgresql-metrics) | Quick start guide for PostgreSQL Metrics |
2727
| [Redis Logs](/use-cases/observability/clickstack/integrations/redis) | Quick start guide for Redis Logs |
28-
| [Redis Metrics](/use-cases/observability/clickstack/integrations/redis-metrics) | Quick start guide for Redis Metrics |
28+
| [Redis Metrics](/use-cases/observability/clickstack/integrations/redis-metrics) | Quick start guide for Redis Metrics |
29+
| [AWS Lambda Logs using Rotel](/use-cases/observability/clickstack/integrations/aws-lambda) | Quick start guide for AWS Lambda Logs using Rotel |
187 KB
Loading
105 KB
Loading

0 commit comments

Comments
 (0)