mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
refactor(Console): Report logs with opt out option
This commit is contained in:
parent
62af0eab9b
commit
ababd90f09
@ -40,9 +40,9 @@ class Console {
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
const { configurationInput: configuration } = this.serverless;
|
||||
this.isEnabled = (() => {
|
||||
const {
|
||||
configurationInput: configuration,
|
||||
processedInput: { commands, options },
|
||||
} = this.serverless;
|
||||
if (!_.get(configuration, 'console')) return false;
|
||||
@ -88,6 +88,7 @@ class Console {
|
||||
this.service = this.serverless.service.service;
|
||||
this.stage = this.provider.getStage();
|
||||
this.region = this.provider.getRegion();
|
||||
this.shouldDisableLogsCollection = configuration.console.disableLogsCollection;
|
||||
this.otelIngestionUrl = (() => {
|
||||
if (process.env.SLS_CONSOLE_OTEL_INGESTION_URL) {
|
||||
return process.env.SLS_CONSOLE_OTEL_INGESTION_URL;
|
||||
@ -366,6 +367,9 @@ Object.defineProperties(
|
||||
AWS_LAMBDA_EXEC_WRAPPER: '/opt/otel-extension/internal/exec-wrapper.sh',
|
||||
};
|
||||
if (process.env.SLS_OTEL_LAYER_DEV_BUILD) result.DEBUG_SLS_OTEL_LAYER = '1';
|
||||
if (!this.shouldDisableLogsCollection) {
|
||||
result.SLS_OTEL_REPORT_LOGS_URL = `${this.otelIngestionUrl}/v1/logs`;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}),
|
||||
|
||||
@ -15,7 +15,18 @@ const schema = {
|
||||
* The default is `warn`, and will be set to `error` in v2
|
||||
*/
|
||||
configValidationMode: { enum: ['error', 'warn', 'off'] },
|
||||
console: { type: 'boolean' },
|
||||
console: {
|
||||
anyOf: [
|
||||
{ type: 'boolean' },
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
disableLogsCollection: { type: 'boolean' },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
custom: {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
|
||||
@ -182,6 +182,7 @@ describe('test/unit/lib/classes/console.test.js', () => {
|
||||
for (const fnVariables of fnVariablesList) {
|
||||
expect(fnVariables).to.have.property('SLS_OTEL_REPORT_REQUEST_HEADERS');
|
||||
expect(fnVariables).to.have.property('SLS_OTEL_REPORT_METRICS_URL');
|
||||
expect(fnVariables).to.have.property('SLS_OTEL_REPORT_LOGS_URL');
|
||||
expect(fnVariables).to.have.property('AWS_LAMBDA_EXEC_WRAPPER');
|
||||
}
|
||||
|
||||
@ -267,6 +268,35 @@ describe('test/unit/lib/classes/console.test.js', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('disable logs collection', () => {
|
||||
it('should not setup report logs url', async () => {
|
||||
const fetchStub = createFetchStub().stub;
|
||||
const { cfTemplate, awsNaming } = await runServerless({
|
||||
fixture: 'function',
|
||||
command: 'package',
|
||||
configExt: {
|
||||
console: { disableLogsCollection: true },
|
||||
org: 'testorg',
|
||||
},
|
||||
modulesCacheStub: {
|
||||
[getRequire(path.dirname(require.resolve('@serverless/dashboard-plugin'))).resolve(
|
||||
'@serverless/platform-client'
|
||||
)]: { ServerlessSDK: ServerlessSDKMock },
|
||||
[require.resolve('node-fetch')]: fetchStub,
|
||||
},
|
||||
awsRequestStubMap: createAwsRequestStubMap(),
|
||||
env: { SERVERLESS_ACCESS_KEY: 'dummy' },
|
||||
});
|
||||
|
||||
const fnVariables =
|
||||
cfTemplate.Resources[awsNaming.getLambdaLogicalId('basic')].Properties.Environment
|
||||
.Variables;
|
||||
expect(fnVariables).to.have.property('SLS_OTEL_REPORT_REQUEST_HEADERS');
|
||||
expect(fnVariables).to.not.have.property('SLS_OTEL_REPORT_LOGS_URL');
|
||||
expect(fnVariables).to.have.property('AWS_LAMBDA_EXEC_WRAPPER');
|
||||
});
|
||||
});
|
||||
|
||||
describe('package for custom deployment bucket', () => {
|
||||
let cfTemplate;
|
||||
let awsNaming;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user