Commit 8bdd819
authored
feat: Handle API key resolution failure (#732)
# Context
The previous PR
#717 defers API
key resolution from extension init stage to flush time. However, that PR
doesn't well handle the failure case.
- Before that PR, if resolution fails in init stage, the extension will
run an idle loop.
- After that PR, the extension will crash at flush time, which will kill
the runtime as well, which is not desired.
# What does this PR do?
1. For traces, defer key resolution from
`TraceProcessor.process_traces()` to `TraceFlusher.flush()`.
- (This should ideally be in the previous PR, but since that is already
approved, let me add this change in this new PR.)
2. If resolution fails at flush time, then make flush a no-op, so the
extension can keep running and consume events without crashing.
# Dependencies
1. DataDog/serverless-components#25
2. DataDog/libdatadog#1140
# Manual Test
## Steps
1. Create a layer in sandbox
2. Apply the layer to a Lambda function
3. Set the env var `DD_API_KEY_SECRET_ARN` to an invalid value
5. Run the Lambda
6. Then set `DD_API_KEY_SECRET_ARN` to a valid value
7. Run the Lambda
## Result
1. The function was successful
<img width="319" alt="image"
src="https://github.com/user-attachments/assets/f8a5cb36-f678-4643-ba1c-85f41256ffa1"
/>
2. The extension printed some error logs
<img width="737" height="33" alt="image"
src="https://github.com/user-attachments/assets/22553d24-e1f5-4ee5-9a91-0d18e3e2f297"
/>
<img width="603" height="186" alt="image"
src="https://github.com/user-attachments/assets/e797f991-ecba-45f0-8f49-7b7b59dd9e7b"
/>
3. With valid secret ARN, the Lambda runs successfully and reports to
Datadog
<img width="678" height="150" alt="image"
src="https://github.com/user-attachments/assets/073089f8-1e9a-4728-b8d1-1db7aa85d031"
/>
<img width="533" height="96" alt="image"
src="https://github.com/user-attachments/assets/d5f2b81c-5e02-42bc-b3ef-85e611228fc6"
/>
# Automated Test
I didn't add any automated test because from what I see in the codebase,
existing tests are usually unit tests for short functions and not for
long functions that this PR touches. Please let me know if you think I
should add automated tests.1 parent a8d05a1 commit 8bdd819
10 files changed
Lines changed: 56 additions & 44 deletions
File tree
- bottlecap
- src
- bin/bottlecap
- logs
- proxy
- traces
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
| 442 | + | |
447 | 443 | | |
448 | 444 | | |
449 | 445 | | |
| |||
517 | 513 | | |
518 | 514 | | |
519 | 515 | | |
520 | | - | |
| 516 | + | |
521 | 517 | | |
522 | 518 | | |
523 | 519 | | |
| |||
1038 | 1034 | | |
1039 | 1035 | | |
1040 | 1036 | | |
1041 | | - | |
| 1037 | + | |
1042 | 1038 | | |
1043 | 1039 | | |
1044 | 1040 | | |
| |||
1064 | 1060 | | |
1065 | 1061 | | |
1066 | 1062 | | |
| 1063 | + | |
1067 | 1064 | | |
1068 | 1065 | | |
1069 | 1066 | | |
| |||
1077 | 1074 | | |
1078 | 1075 | | |
1079 | 1076 | | |
1080 | | - | |
1081 | 1077 | | |
1082 | 1078 | | |
1083 | 1079 | | |
| |||
1098 | 1094 | | |
1099 | 1095 | | |
1100 | 1096 | | |
1101 | | - | |
1102 | 1097 | | |
1103 | 1098 | | |
1104 | 1099 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
| |||
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
57 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | | - | |
403 | 402 | | |
404 | 403 | | |
405 | 404 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| |||
83 | 82 | | |
84 | 83 | | |
85 | 84 | | |
86 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
67 | | - | |
68 | 73 | | |
69 | 74 | | |
70 | 75 | | |
71 | 76 | | |
72 | | - | |
| 77 | + | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
| |||
95 | 100 | | |
96 | 101 | | |
97 | 102 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 103 | + | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
| |||
86 | 85 | | |
87 | 86 | | |
88 | 87 | | |
89 | | - | |
90 | 88 | | |
91 | 89 | | |
92 | 90 | | |
| |||
99 | 97 | | |
100 | 98 | | |
101 | 99 | | |
102 | | - | |
103 | 100 | | |
104 | 101 | | |
105 | 102 | | |
| |||
120 | 117 | | |
121 | 118 | | |
122 | 119 | | |
123 | | - | |
124 | 120 | | |
125 | 121 | | |
126 | 122 | | |
| |||
147 | 143 | | |
148 | 144 | | |
149 | 145 | | |
150 | | - | |
151 | 146 | | |
152 | 147 | | |
153 | 148 | | |
| |||
207 | 202 | | |
208 | 203 | | |
209 | 204 | | |
210 | | - | |
211 | 205 | | |
212 | 206 | | |
213 | 207 | | |
| |||
395 | 389 | | |
396 | 390 | | |
397 | 391 | | |
| 392 | + | |
| 393 | + | |
398 | 394 | | |
399 | 395 | | |
400 | 396 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
| |||
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
41 | | - | |
42 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
43 | 57 | | |
44 | 58 | | |
45 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
46 | 65 | | |
47 | 66 | | |
48 | 67 | | |
| |||
64 | 83 | | |
65 | 84 | | |
66 | 85 | | |
| 86 | + | |
| 87 | + | |
67 | 88 | | |
68 | 89 | | |
69 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
34 | | - | |
35 | 33 | | |
36 | 34 | | |
37 | 35 | | |
| |||
164 | 162 | | |
165 | 163 | | |
166 | 164 | | |
167 | | - | |
168 | 165 | | |
169 | 166 | | |
170 | 167 | | |
171 | | - | |
| 168 | + | |
| 169 | + | |
172 | 170 | | |
173 | 171 | | |
174 | 172 | | |
| |||
194 | 192 | | |
195 | 193 | | |
196 | 194 | | |
197 | | - | |
198 | 195 | | |
199 | 196 | | |
200 | 197 | | |
| |||
299 | 296 | | |
300 | 297 | | |
301 | 298 | | |
302 | | - | |
303 | 299 | | |
304 | 300 | | |
305 | 301 | | |
| |||
0 commit comments