Skip to content

Commit 4f74d38

Browse files
committed
worked on auto tracing
1 parent 443ea3c commit 4f74d38

File tree

22 files changed

+1538
-67
lines changed

22 files changed

+1538
-67
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,15 @@ app.setDefaultFunctionProps({
130130

131131
## Automatic Instrumentation
132132

133-
WIP - you still need to manually apply baselime.wrap(handler). This will be automated in future versions.
133+
### Manual Setup
134134

135-
## SST
135+
1. Add the baselime-node layer - `arn:aws:lambda:${region:097948374213:layer:baselime-node:2`
136+
2. Add the baselime-extension layer - `arn:aws:lambda:${region}:097948374213:layer:baselime-extension-${'x86_64' || 'arm64'}:1`
137+
3. Set the handler to `/opt/nodejs/node_modules/@baselime/lambda-node-opentelemetry/handler.handler`
138+
4. Set the BASELIME_ORIGINAL_HANDLER environment variable to the original path of your lambda
139+
5. Set the BASELIME_KEY environment variable with the value of your environments baselime api key
140+
141+
### SST
136142

137143
```typescript
138144
import { LayerVersion } from "aws-cdk-lib/aws-lambda";
@@ -152,7 +158,7 @@ if (!scope.local) {
152158
}
153159
```
154160

155-
## Serverless
161+
### Serverless
156162

157163
```yml
158164
provider:
@@ -164,7 +170,7 @@ provider:
164170
BASELIME_KEY: ${env:BASELIME_KEY}
165171
```
166172
167-
## Architect
173+
### Architect
168174
169175
```
170176
// app.arc

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lambda-wrapper.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/serverless/serverless.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ provider:
3434
NODE_OPTIONS: --require node_modules/@baselime/lambda-node-opentelemetry/lambda-wrapper.js
3535
OTEL_LOG_LEVEL: debug
3636
COLLECTOR_URL: https://otel.baselime.cc/v1
37+
DISPATCH_POST_URI: https://lambda-extension.baselime.cc
3738
functions:
3839
hello:
3940
handler: src/main.handler
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import baselime from "@baselime/lambda-node-opentelemetry";
2-
3-
export const handler = baselime.wrap(async () => {
1+
export const handler = async () => {
42
console.log("TODO LIST", JSON.stringify({ MESSAGE:[{ id: 1, text: "TODO 1" }]}));
53

64
return {
75
statusCode: 200,
86
body: JSON.stringify({ MESSAGE:[{ id: 1, text: "TODO 1" }]}),
97
}
10-
})
8+
}

examples/sst/stacks/MyStack.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { StackContext, Api, EventBus, App } from "sst/constructs";
22
import { LayerVersion } from "aws-cdk-lib/aws-lambda";
33

4+
5+
function magicShit(api) {
6+
console.log(api)
7+
}
48
export function API({ stack }: StackContext) {
59

610
const baselime = LayerVersion.fromLayerVersionArn(
711
stack,
812
"BaselimeLayer",
9-
`arn:aws:lambda:eu-west-2:097948374213:layer:baselime-node:2`
13+
`arn:aws:lambda:eu-west-2:374211872663:layer:baselime-node:7`
1014
);
1115

1216
if (!(stack.node.scope as App)?.local) {
@@ -15,7 +19,8 @@ export function API({ stack }: StackContext) {
1519
AWS_LAMBDA_EXEC_WRAPPER: '/opt/baselime',
1620
BASELIME_KEY: process.env.BASELIME_KEY as string,
1721
COLLECTOR_URL: 'https://otel.baselime.cc/v1',
18-
OTEL_LOG_LEVEL: 'debug'
22+
OTEL_LOG_LEVEL: 'debug',
23+
BASELIME_ORIGINAL_HANDLER: 'packages/functions/src/todo.handler',
1924
});
2025

2126
}
@@ -40,10 +45,11 @@ export function API({ stack }: StackContext) {
4045
},
4146
routes: {
4247
"GET /": "packages/functions/src/todo.handler",
43-
"POST /": "packages/functions/src/todo.handler",
4448
},
4549
});
4650

51+
magicShit(api);
52+
4753
bus.subscribe("todo.created", {
4854
handler: "packages/functions/src/events/todo-created.handler",
4955
});

handler.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { loadSync } = require('../src/loader');
2+
3+
exports.handler = function (...args) {
4+
5+
loadSync();
6+
};

handler.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { load } from '../src/loader.js';
2+
import { wrap } from '../src/index.js';
3+
4+
export const handler = async function (...args) {
5+
const actualHandler = process.env.BASELIME_ACTUAL_HANDLER;
6+
const taskRoot = process.env.LAMBDA_TASK_ROOT;
7+
8+
if(!taskRoot) {
9+
throw Error('LAMBDA_TASK_ROOT is not defined');
10+
}
11+
12+
if(!actualHandler) {
13+
throw Error('BASELIME_ACTUAL_HANDLER is not defined');
14+
}
15+
16+
const handler = await load(taskRoot, actualHandler);
17+
18+
const [event, context] = args
19+
return wrap(handler)(event, context);
20+
};

handlers/handler.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { loadSync } = require('../src/loader');
2+
3+
exports.handler = function (...args) {
4+
5+
loadSync();
6+
};

handlers/handler.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { load } from '../src/loader.js';
2+
import { wrap } from '../src/index.js';
3+
4+
export const handler = async function (...args) {
5+
const actualHandler = process.env.BASELIME_ACTUAL_HANDLER;
6+
const taskRoot = process.env.LAMBDA_TASK_ROOT;
7+
8+
if(!taskRoot) {
9+
throw Error('LAMBDA_TASK_ROOT is not defined');
10+
}
11+
12+
if(!actualHandler) {
13+
throw Error('BASELIME_ACTUAL_HANDLER is not defined');
14+
}
15+
16+
const handler = await load(taskRoot, actualHandler);
17+
18+
const [event, context] = args
19+
return wrap(handler)(event, context);
20+
};

0 commit comments

Comments
 (0)