@friggframework/devtools 2.0.0-next.127 → 2.0.0-next.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/infrastructure/README.md +32 -5
  2. package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +39 -0
  3. package/infrastructure/__tests__/management-api-gateway-routes.test.js +3 -0
  4. package/infrastructure/__tests__/postgres-config.test.js +3 -0
  5. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +3 -0
  6. package/infrastructure/__tests__/scoped-environment.test.js +3 -0
  7. package/infrastructure/__tests__/ssm-preload-node-options.test.js +3 -0
  8. package/infrastructure/__tests__/template-generation.test.js +3 -0
  9. package/infrastructure/app-definition-schema-contract.test.js +5 -0
  10. package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -0
  11. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +22 -6
  12. package/infrastructure/domains/database/migration-builder.js +21 -2
  13. package/infrastructure/domains/database/migration-builder.test.js +61 -6
  14. package/infrastructure/domains/database/migration-engines.js +93 -0
  15. package/infrastructure/domains/database/migration-engines.test.js +142 -0
  16. package/infrastructure/domains/integration/integration-builder.js +17 -0
  17. package/infrastructure/domains/integration/integration-builder.test.js +99 -6
  18. package/infrastructure/domains/scheduler/scheduler-builder.js +14 -2
  19. package/infrastructure/domains/scheduler/scheduler-builder.test.js +102 -0
  20. package/infrastructure/domains/shared/environment-builder.js +31 -5
  21. package/infrastructure/domains/shared/environment-builder.test.js +93 -7
  22. package/infrastructure/domains/shared/lambda-architectures.js +113 -0
  23. package/infrastructure/domains/shared/lambda-architectures.test.js +164 -0
  24. package/infrastructure/domains/shared/utilities/base-definition-factory.js +14 -1
  25. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +63 -4
  26. package/infrastructure/domains/shared/utilities/nested-node-modules.js +6 -5
  27. package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +20 -26
  28. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +92 -12
  29. package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +158 -6
  30. package/infrastructure/domains/shared/utilities/sqs-queue-arn.js +59 -0
  31. package/infrastructure/domains/shared/utilities/sqs-queue-arn.test.js +70 -0
  32. package/infrastructure/infrastructure-composer.js +12 -1
  33. package/infrastructure/infrastructure-composer.test.js +71 -0
  34. package/infrastructure/scripts/build-prisma-layer.js +136 -50
  35. package/infrastructure/scripts/build-prisma-layer.test.js +100 -0
  36. package/package.json +7 -7
@@ -0,0 +1,142 @@
1
+ const fs = require('fs');
2
+ const os = require('os');
3
+ const path = require('path');
4
+ const { ensureMigrationEngines } = require('./migration-engines');
5
+
6
+ describe('ensureMigrationEngines()', () => {
7
+ const target = 'linux-arm64-openssl-3.0.x';
8
+ const schemaEngine = `schema-engine-${target}`;
9
+ const queryEngineLibrary = `libquery_engine-${target}.so.node`;
10
+ let enginesDir;
11
+
12
+ const writeEngines = (...names) => {
13
+ for (const name of names) {
14
+ fs.writeFileSync(path.join(enginesDir, name), '');
15
+ }
16
+ };
17
+
18
+ beforeEach(() => {
19
+ enginesDir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-prisma-engines-'));
20
+ });
21
+
22
+ afterEach(() => {
23
+ fs.rmSync(enginesDir, { recursive: true, force: true });
24
+ });
25
+
26
+ it('fetches nothing when both engines for the target are already present', async () => {
27
+ writeEngines(schemaEngine, queryEngineLibrary);
28
+ const fetchEngines = jest.fn();
29
+
30
+ await ensureMigrationEngines({ prismaBinaryTarget: target, enginesDir, fetchEngines });
31
+
32
+ expect(fetchEngines).not.toHaveBeenCalled();
33
+ });
34
+
35
+ it('fetches the target engines into the engines directory when one is missing', async () => {
36
+ writeEngines(schemaEngine);
37
+ const fetchEngines = jest.fn(({ enginesDir: dir }) => {
38
+ fs.writeFileSync(path.join(dir, queryEngineLibrary), '');
39
+ });
40
+
41
+ await ensureMigrationEngines({ prismaBinaryTarget: target, enginesDir, fetchEngines });
42
+
43
+ expect(fetchEngines).toHaveBeenCalledWith({ enginesDir, prismaBinaryTarget: target });
44
+ });
45
+
46
+ it.each([
47
+ ['the schema engine', [queryEngineLibrary], schemaEngine],
48
+ ['the query engine library', [schemaEngine], queryEngineLibrary],
49
+ ['both engines', [], `${schemaEngine}, ${queryEngineLibrary}`],
50
+ ])('fails packaging naming %s when the fetch leaves it missing', async (_, present, missing) => {
51
+ writeEngines(...present);
52
+ const fetchEngines = jest.fn();
53
+
54
+ await expect(
55
+ ensureMigrationEngines({ prismaBinaryTarget: target, enginesDir, fetchEngines })
56
+ ).rejects.toThrow(missing);
57
+ });
58
+
59
+ describe('resolving the engines directory from cwd', () => {
60
+ let root;
61
+
62
+ const installEngines = (dir) => {
63
+ const engines = path.join(dir, 'node_modules', '@prisma', 'engines');
64
+ fs.mkdirSync(path.join(engines, 'scripts'), { recursive: true });
65
+ fs.writeFileSync(path.join(engines, 'scripts', 'postinstall.js'), '');
66
+ return engines;
67
+ };
68
+
69
+ beforeEach(() => {
70
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-app-root-'));
71
+ });
72
+
73
+ afterEach(() => {
74
+ fs.rmSync(root, { recursive: true, force: true });
75
+ });
76
+
77
+ it("uses the engines in the app's own node_modules", async () => {
78
+ const appDir = path.join(root, 'app');
79
+ const appEngines = installEngines(appDir);
80
+ fs.writeFileSync(path.join(appEngines, schemaEngine), '');
81
+ fs.writeFileSync(path.join(appEngines, queryEngineLibrary), '');
82
+ const fetchEngines = jest.fn();
83
+
84
+ await ensureMigrationEngines({ prismaBinaryTarget: target, cwd: appDir, fetchEngines });
85
+
86
+ expect(fetchEngines).not.toHaveBeenCalled();
87
+ });
88
+
89
+ it('fails with a readable error when only a parent directory has the engines', async () => {
90
+ installEngines(root);
91
+ const appDir = path.join(root, 'app');
92
+ fs.mkdirSync(appDir);
93
+ const fetchEngines = jest.fn();
94
+
95
+ const failure = ensureMigrationEngines({
96
+ prismaBinaryTarget: target,
97
+ cwd: appDir,
98
+ fetchEngines,
99
+ });
100
+
101
+ await expect(failure).rejects.toThrow(/prisma.*own node_modules.*hoisted parent/is);
102
+ await expect(failure).rejects.not.toHaveProperty('code', 'MODULE_NOT_FOUND');
103
+ expect(fetchEngines).not.toHaveBeenCalled();
104
+ });
105
+ });
106
+
107
+ describe('running the @prisma/engines postinstall', () => {
108
+ const pinnedEngineVars = ['PRISMA_SCHEMA_ENGINE_BINARY', 'PRISMA_QUERY_ENGINE_LIBRARY'];
109
+ let appDir;
110
+ let seenEnvPath;
111
+
112
+ beforeEach(() => {
113
+ appDir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-app-'));
114
+ const engines = path.join(appDir, 'node_modules', '@prisma', 'engines');
115
+ fs.mkdirSync(path.join(engines, 'scripts'), { recursive: true });
116
+ seenEnvPath = path.join(appDir, 'seen-env.json');
117
+ fs.writeFileSync(
118
+ path.join(engines, 'scripts', 'postinstall.js'),
119
+ `const fs = require('fs');
120
+ fs.writeFileSync(${JSON.stringify(seenEnvPath)}, JSON.stringify(process.env));
121
+ for (const name of ${JSON.stringify([schemaEngine, queryEngineLibrary])}) fs.writeFileSync(name, '');`
122
+ );
123
+ });
124
+
125
+ afterEach(() => {
126
+ fs.rmSync(appDir, { recursive: true, force: true });
127
+ pinnedEngineVars.forEach((name) => delete process.env[name]);
128
+ });
129
+
130
+ it("hides the host's pinned engine paths, so the postinstall does not skip the download", async () => {
131
+ pinnedEngineVars.forEach((name) => {
132
+ process.env[name] = `/host/${name}`;
133
+ });
134
+
135
+ await ensureMigrationEngines({ prismaBinaryTarget: target, cwd: appDir });
136
+
137
+ const seenEnv = JSON.parse(fs.readFileSync(seenEnvPath, 'utf-8'));
138
+ expect(seenEnv.PRISMA_CLI_BINARY_TARGETS).toBe(target);
139
+ pinnedEngineVars.forEach((name) => expect(seenEnv).not.toHaveProperty(name));
140
+ });
141
+ });
142
+ });
@@ -32,6 +32,8 @@ const {
32
32
  const {
33
33
  nestedNodeModulesExcludes,
34
34
  } = require('../shared/utilities/nested-node-modules');
35
+ const { queueArnFromUrl } = require('../shared/utilities/sqs-queue-arn');
36
+ const { bundledPrismaEngineExcludes } = require('../shared/lambda-architectures');
35
37
  const {
36
38
  INTEGRATION_QUEUE_MAX_RECEIVE_COUNT,
37
39
  QUEUE_MAX_RECEIVE_COUNT_ENV,
@@ -268,6 +270,7 @@ class IntegrationBuilder extends InfrastructureBuilder {
268
270
  'node_modules/@friggframework/core/generated/**',
269
271
  ]
270
272
  : []),
273
+ ...bundledPrismaEngineExcludes(appDefinition, usePrismaLayer),
271
274
 
272
275
  ...nestedNodeModulesExcludes(appDefinition, usePrismaLayer),
273
276
 
@@ -620,6 +623,20 @@ class IntegrationBuilder extends InfrastructureBuilder {
620
623
  appDefinition
621
624
  );
622
625
 
626
+ // The base role grants these only on the queues the stack names, and
627
+ // the queue worker sends, looks up and defers rate-limited messages
628
+ // on this queue too (ADR-049).
629
+ result.iamStatements.push({
630
+ Effect: 'Allow',
631
+ Action: [
632
+ 'sqs:SendMessage',
633
+ 'sqs:GetQueueUrl',
634
+ 'sqs:GetQueueAttributes',
635
+ 'sqs:ChangeMessageVisibility',
636
+ ],
637
+ Resource: [queueArnFromUrl(decision.physicalId)],
638
+ });
639
+
623
640
  console.log(` ✓ Using external queue: ${decision.physicalId}`);
624
641
  }
625
642
 
@@ -10,6 +10,9 @@ const {
10
10
  } = require('@friggframework/core/queues/queue-delivery');
11
11
  const { IntegrationBuilder } = require('./integration-builder');
12
12
  const { ValidationResult } = require('../shared/base-builder');
13
+ const { itBundlesOnlyTheTargetPrismaEngine } = require('../../__tests__/helpers/bundled-prisma-engine-excludes');
14
+ const { BuilderOrchestrator } = require('../shared/builder-orchestrator');
15
+ const { SchedulerBuilder } = require('../scheduler/scheduler-builder');
13
16
 
14
17
  describe('IntegrationBuilder', () => {
15
18
  let integrationBuilder;
@@ -259,6 +262,81 @@ describe('IntegrationBuilder', () => {
259
262
  ).toBeUndefined();
260
263
  });
261
264
 
265
+ it('lets the functions send to, look up and defer messages on an external queue', async () => {
266
+ const result = await integrationBuilder.build(
267
+ {
268
+ integrations: [
269
+ {
270
+ Definition: { name: 'test' },
271
+ ownership: { queue: 'external' },
272
+ queue: {
273
+ url: 'https://sqs.us-east-1.amazonaws.com/123456789012/test-queue',
274
+ },
275
+ },
276
+ ],
277
+ },
278
+ {}
279
+ );
280
+
281
+ expect(result.iamStatements).toEqual([
282
+ {
283
+ Effect: 'Allow',
284
+ Action: [
285
+ 'sqs:SendMessage',
286
+ 'sqs:GetQueueUrl',
287
+ 'sqs:GetQueueAttributes',
288
+ 'sqs:ChangeMessageVisibility',
289
+ ],
290
+ Resource: [
291
+ {
292
+ 'Fn::Sub':
293
+ 'arn:${AWS::Partition}:sqs:us-east-1:123456789012:test-queue',
294
+ },
295
+ ],
296
+ },
297
+ ]);
298
+ });
299
+
300
+ it('adds no queue statement for a queue the stack creates, because the base role covers it', async () => {
301
+ const result = await integrationBuilder.build(
302
+ { integrations: [{ Definition: { name: 'test' } }] },
303
+ {}
304
+ );
305
+
306
+ expect(result.iamStatements).toEqual([]);
307
+ });
308
+
309
+ it('adds no resource, function or env var when no module declares rateLimit', async () => {
310
+ class Api {}
311
+ const { merged } = await new BuilderOrchestrator([
312
+ new IntegrationBuilder(),
313
+ new SchedulerBuilder(),
314
+ ]).buildAll({
315
+ integrations: [
316
+ {
317
+ Definition: {
318
+ name: 'test',
319
+ modules: { crm: { definition: { API: Api } } },
320
+ },
321
+ },
322
+ ],
323
+ });
324
+ const before = await integrationBuilder.build(
325
+ { integrations: [{ Definition: { name: 'test' } }] },
326
+ {}
327
+ );
328
+
329
+ expect(Object.keys(merged.resources)).toEqual(
330
+ Object.keys(before.resources)
331
+ );
332
+ expect(Object.keys(merged.functions)).toEqual(
333
+ Object.keys(before.functions)
334
+ );
335
+ expect(Object.keys(merged.environment)).toEqual(
336
+ Object.keys(before.environment)
337
+ );
338
+ });
339
+
262
340
  it('should create queue worker function', async () => {
263
341
  const appDefinition = {
264
342
  integrations: [
@@ -1085,6 +1163,21 @@ describe('IntegrationBuilder', () => {
1085
1163
  });
1086
1164
 
1087
1165
 
1166
+ describe('IntegrationBuilder Lambda architecture with usePrismaLambdaLayer=false', () => {
1167
+ const functionsOf = async (usePrismaLambdaLayer, architecture) => {
1168
+ const result = await new IntegrationBuilder().build(
1169
+ {
1170
+ integrations: [{ Definition: { name: 'crm' } }],
1171
+ usePrismaLambdaLayer,
1172
+ ...(architecture && { architecture }),
1173
+ },
1174
+ {}
1175
+ );
1176
+ return Object.values(result.functions);
1177
+ };
1178
+ itBundlesOnlyTheTargetPrismaEngine(functionsOf);
1179
+ });
1180
+
1088
1181
  describe('IntegrationBuilder nested node_modules (lambda.keepNestedNodeModules)', () => {
1089
1182
  const appDefinition = (lambda) => ({
1090
1183
  integrations: [{ Definition: { name: 'test', webhooks: true } }],
@@ -1093,24 +1186,24 @@ describe('IntegrationBuilder nested node_modules (lambda.keepNestedNodeModules)'
1093
1186
  const packagedFunctions = (result) =>
1094
1187
  Object.values(result.functions).filter((fn) => fn.package?.exclude);
1095
1188
 
1096
- it('excludes every nested node_modules by default', async () => {
1189
+ it('keeps nested node_modules by default, still excluding nested Frigg copies', async () => {
1097
1190
  const result = await new IntegrationBuilder().build(appDefinition(), {});
1098
1191
 
1099
1192
  expect(packagedFunctions(result).length).toBeGreaterThan(0);
1100
1193
  for (const fn of packagedFunctions(result)) {
1101
- expect(fn.package.exclude).toContain('node_modules/**/node_modules/**');
1194
+ expect(fn.package.exclude).not.toContain('node_modules/**/node_modules/**');
1195
+ expect(fn.package.exclude).toContain('node_modules/**/node_modules/@friggframework/**');
1102
1196
  }
1103
1197
  });
1104
1198
 
1105
- it('keeps nested node_modules when the app opts in, still excluding nested Frigg copies', async () => {
1199
+ it('excludes every nested node_modules when the app opts out', async () => {
1106
1200
  const result = await new IntegrationBuilder().build(
1107
- appDefinition({ keepNestedNodeModules: true }),
1201
+ appDefinition({ keepNestedNodeModules: false }),
1108
1202
  {}
1109
1203
  );
1110
1204
 
1111
1205
  for (const fn of packagedFunctions(result)) {
1112
- expect(fn.package.exclude).not.toContain('node_modules/**/node_modules/**');
1113
- expect(fn.package.exclude).toContain('node_modules/**/node_modules/@friggframework/**');
1206
+ expect(fn.package.exclude).toContain('node_modules/**/node_modules/**');
1114
1207
  }
1115
1208
  });
1116
1209
  });
@@ -13,11 +13,18 @@
13
13
  */
14
14
 
15
15
  const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
16
+ const { ResourceOwnership } = require('../shared/types/resource-ownership');
16
17
  const {
17
18
  isScopedEnvironmentActive,
18
19
  getIntegrationFunctionNames,
19
20
  getAdminFunctionNames,
20
21
  } = require('../shared/function-environments');
22
+ const { queueArnFromUrl } = require('../shared/utilities/sqs-queue-arn');
23
+
24
+ const declaresRateLimit = (integration) =>
25
+ Object.values(integration?.Definition?.modules ?? {}).some((module) =>
26
+ Boolean(module?.definition?.API?.rateLimit)
27
+ );
21
28
 
22
29
  class SchedulerBuilder extends InfrastructureBuilder {
23
30
  constructor() {
@@ -37,7 +44,8 @@ class SchedulerBuilder extends InfrastructureBuilder {
37
44
  return appDefinition.integrations.some(
38
45
  (integration) =>
39
46
  integration?.Definition?.webhooks?.enabled === true ||
40
- integration?.Definition?.webhooks === true
47
+ integration?.Definition?.webhooks === true ||
48
+ declaresRateLimit(integration)
41
49
  );
42
50
  }
43
51
 
@@ -107,7 +115,11 @@ class SchedulerBuilder extends InfrastructureBuilder {
107
115
  if (Array.isArray(appDefinition.integrations)) {
108
116
  appDefinition.integrations.forEach((integration) => {
109
117
  const integrationName = integration?.Definition?.name;
110
- if (integrationName) {
118
+ if (
119
+ integration.ownership?.queue === ResourceOwnership.EXTERNAL
120
+ ) {
121
+ queueArns.push(queueArnFromUrl(integration.queue.url));
122
+ } else if (integrationName) {
111
123
  const capitalizedName =
112
124
  integrationName.charAt(0).toUpperCase() +
113
125
  integrationName.slice(1);
@@ -38,6 +38,61 @@ describe('SchedulerBuilder', () => {
38
38
  ).toBe(true);
39
39
  });
40
40
 
41
+ it('runs when any module declares a rate limit', () => {
42
+ class Api {
43
+ static rateLimit = { minRetryAfterMs: 1_000 };
44
+ }
45
+ expect(
46
+ schedulerBuilder.shouldExecute({
47
+ integrations: [
48
+ { Definition: { name: 'a' } },
49
+ {
50
+ Definition: {
51
+ name: 'b',
52
+ modules: { crm: { definition: { API: Api } } },
53
+ },
54
+ },
55
+ ],
56
+ })
57
+ ).toBe(true);
58
+ });
59
+
60
+ it('skips a module whose API declares no rate limit', () => {
61
+ class Api {}
62
+ expect(
63
+ schedulerBuilder.shouldExecute({
64
+ integrations: [
65
+ {
66
+ Definition: {
67
+ name: 'a',
68
+ modules: { crm: { definition: { API: Api } } },
69
+ },
70
+ },
71
+ ],
72
+ })
73
+ ).toBe(false);
74
+ });
75
+
76
+ it.each([
77
+ ['no modules', { name: 'a' }],
78
+ ['an empty modules object', { name: 'a', modules: {} }],
79
+ [
80
+ 'a module with no definition',
81
+ { name: 'a', modules: { crm: {} } },
82
+ ],
83
+ ['a null module', { name: 'a', modules: { crm: null } }],
84
+ [
85
+ 'a definition with no API',
86
+ { name: 'a', modules: { crm: { definition: {} } } },
87
+ ],
88
+ ])('skips an integration with %s', (_label, Definition) => {
89
+ expect(
90
+ schedulerBuilder.shouldExecute({
91
+ integrations: [{ Definition }],
92
+ })
93
+ ).toBe(false);
94
+ });
95
+
41
96
  it('skips otherwise', () => {
42
97
  expect(
43
98
  schedulerBuilder.shouldExecute({
@@ -115,4 +170,51 @@ describe('SchedulerBuilder', () => {
115
170
  expect(result.functionEnvironments).toBeUndefined();
116
171
  });
117
172
  });
173
+
174
+ describe('build() execution role', () => {
175
+ const sendableQueues = (result) =>
176
+ result.resources.SchedulerExecutionRole.Properties.Policies[0]
177
+ .PolicyDocument.Statement[0].Resource;
178
+
179
+ it('allows sending to a queue the stack creates', async () => {
180
+ const result = await schedulerBuilder.build(
181
+ {
182
+ scheduler: { enable: true },
183
+ integrations: [{ Definition: { name: 'hubspot' } }],
184
+ },
185
+ {}
186
+ );
187
+
188
+ expect(sendableQueues(result)).toEqual([
189
+ { 'Fn::GetAtt': ['HubspotQueue', 'Arn'] },
190
+ ]);
191
+ });
192
+
193
+ it('allows sending to an external queue by its ARN, not a resource the stack lacks', async () => {
194
+ const result = await schedulerBuilder.build(
195
+ {
196
+ scheduler: { enable: true },
197
+ integrations: [
198
+ { Definition: { name: 'hubspot' } },
199
+ {
200
+ Definition: { name: 'salesforce' },
201
+ ownership: { queue: 'external' },
202
+ queue: {
203
+ url: 'https://sqs.us-east-1.amazonaws.com/123456789012/acme-salesforce',
204
+ },
205
+ },
206
+ ],
207
+ },
208
+ {}
209
+ );
210
+
211
+ expect(sendableQueues(result)).toEqual([
212
+ { 'Fn::GetAtt': ['HubspotQueue', 'Arn'] },
213
+ {
214
+ 'Fn::Sub':
215
+ 'arn:${AWS::Partition}:sqs:us-east-1:123456789012:acme-salesforce',
216
+ },
217
+ ]);
218
+ });
219
+ });
118
220
  });
@@ -16,9 +16,12 @@ const {
16
16
  const { normalizeLogLevel } = require('./utilities/logging-config');
17
17
 
18
18
  // OTLP-family exporters read their endpoint/headers from these standard env
19
- // vars (ADR-011). When such an exporter is configured we auto-register them as
20
- // Serverless passthroughs so the deployed Lambda inherits them from the deploy
21
- // environment — no need for the adopter to also list them under `environment`.
19
+ // vars (ADR-011). When such an exporter is configured — or when the adopter
20
+ // opts into zero-code OTLP by setting OTEL_EXPORTER_OTLP_ENDPOINT (or marking
21
+ // it for SSM offload) with no Definition.telemetry.exporter — we auto-register
22
+ // them as Serverless passthroughs so the deployed Lambda inherits them from
23
+ // the deploy environment. An explicit exporter.type always wins: 'none' /
24
+ // 'console' do NOT register passthroughs even if the deploy shell has the env.
22
25
  //
23
26
  // NOTE (VPC egress): a Lambda in a private subnet needs a NAT gateway or a VPC
24
27
  // endpoint to reach an external OTLP backend (Honeycomb/Datadog). Without egress
@@ -29,9 +32,31 @@ const OTEL_PASSTHROUGH_VARS = [
29
32
  'OTEL_EXPORTER_OTLP_HEADERS',
30
33
  ];
31
34
 
35
+ function hasOtlpEndpointEnv() {
36
+ const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
37
+ return typeof endpoint === 'string' && endpoint.trim().length > 0;
38
+ }
39
+
40
+ /**
41
+ * Zero-code OTLP is active when Definition.telemetry.exporter is omitted and
42
+ * either the deploy shell has a non-empty OTEL_EXPORTER_OTLP_ENDPOINT or that
43
+ * key is declared for SSM offload (`environment: 'ssm'` / `ssm.parameters`).
44
+ */
45
+ function isZeroCodeOtlpActive(appDefinition) {
46
+ if (hasOtlpEndpointEnv()) return true;
47
+ return getOffloadedKeys(appDefinition).includes(
48
+ 'OTEL_EXPORTER_OTLP_ENDPOINT'
49
+ );
50
+ }
51
+
32
52
  function addTelemetryEnvPassthrough(appDefinition, envVars) {
33
53
  const exporterType = appDefinition?.telemetry?.exporter?.type;
34
- if (!OTLP_EXPORTER_TYPES.has(exporterType)) return;
54
+ if (exporterType !== undefined) {
55
+ // Explicit Definition.telemetry.exporter.type wins over the env var.
56
+ if (!OTLP_EXPORTER_TYPES.has(exporterType)) return;
57
+ } else if (!isZeroCodeOtlpActive(appDefinition)) {
58
+ return;
59
+ }
35
60
 
36
61
  // Skip offloaded keys here: baking '${env:KEY, ''}' resolves to '' at
37
62
  // deploy (the value lives only in SSM), and '' !== undefined then blocks
@@ -49,7 +74,8 @@ function addTelemetryEnvPassthrough(appDefinition, envVars) {
49
74
  // the core default, so it emits no env var.
50
75
  function addLoggingEnv(appDefinition, envVars) {
51
76
  const level = appDefinition?.logging?.level;
52
- const normalized = level === undefined ? undefined : normalizeLogLevel(level);
77
+ const normalized =
78
+ level === undefined ? undefined : normalizeLogLevel(level);
53
79
 
54
80
  // serverless-offline copies only AWS_* shell vars into handlers, so under
55
81
  // frigg start the shell level must travel through provider.environment.