Skip to content

docs: update environment variable tables for utilities #1153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ These settings will be used across all metrics emitted:
| Setting | Description | Environment variable | Default | Allowed Values | Example | Constructor parameter |
|----------------------|-----------------------------------------------------------------|-------------------------------|--------------------|----------------|--------------------|-----------------------|
| **Service** | Optionally, sets **service** metric dimension across all metrics| `POWERTOOLS_SERVICE_NAME` | `service_undefined`| Any string | `serverlessAirline`| `serviceName` |
| **Metric namespace** | Logical container where all metrics will be placed | `POWERTOOLS_METRICS_NAMESPACE`| `default_namespace`| Any string | `serverlessAirline`| `namespace` |
| **Metric namespace** | Logical container where all metrics will be placed | `POWERTOOLS_METRICS_NAMESPACE`| `default_namespace`| Any string | `serverlessAirline`| `default_namespace` |

!!! tip
Use your application name or main service as the metric namespace to easily group all metrics
Expand Down
8 changes: 8 additions & 0 deletions packages/commons/tests/unit/Utility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ describe('Class: Utility', () => {
jest.resetModules();
});

describe('Method: getDefaultServiceName', ()=> {
test('it returns the default service name', ()=> {
const utility = new Utility();

expect(utility.getDefaultServiceName).toBe('service_undefined');
});
});

describe('Method: getColdStart', () => {

test('when called multiple times on the parent class, it returns true the first time, then false afterwards', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/logger/tests/unit/Logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ describe('Class: Logger', () => {
console: expect.any(Console),
coldStart: false, // This is now false because the `coldStart` attribute has been already accessed once by the `addContext` method
customConfigService: undefined,
defaultServiceName: 'service_undefined',
envVarsService: expect.any(EnvironmentVariablesService),
logEvent: false,
logFormatter: expect.any(PowertoolLogFormatter),
Expand Down Expand Up @@ -1269,6 +1270,7 @@ describe('Class: Logger', () => {
console: expect.any(Console),
coldStart: true,
customConfigService: undefined,
defaultServiceName: 'service_undefined',
envVarsService: expect.any(EnvironmentVariablesService),
logEvent: false,
logFormatter: expect.any(PowertoolLogFormatter),
Expand All @@ -1293,6 +1295,7 @@ describe('Class: Logger', () => {
console: expect.any(Console),
coldStart: true,
customConfigService: undefined,
defaultServiceName: 'service_undefined',
envVarsService: expect.any(EnvironmentVariablesService),
logEvent: false,
logFormatter: expect.any(PowertoolLogFormatter),
Expand All @@ -1319,6 +1322,7 @@ describe('Class: Logger', () => {
console: expect.any(Console),
coldStart: true,
customConfigService: undefined,
defaultServiceName: 'service_undefined',
envVarsService: expect.any(EnvironmentVariablesService),
logEvent: false,
logFormatter: expect.any(PowertoolLogFormatter),
Expand All @@ -1343,6 +1347,7 @@ describe('Class: Logger', () => {
console: expect.any(Console),
coldStart: true,
customConfigService: undefined,
defaultServiceName: 'service_undefined',
envVarsService: expect.any(EnvironmentVariablesService),
logEvent: false,
logFormatter: expect.any(PowertoolLogFormatter),
Expand Down
22 changes: 13 additions & 9 deletions packages/logger/tests/unit/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ describe('Helper: createLogger function', () => {
},
envVarsService: expect.any(EnvironmentVariablesService),
customConfigService: undefined,
defaultServiceName: 'service_undefined',
logLevel: 'DEBUG',
logFormatter: expect.any(PowertoolLogFormatter),
}));

});

test('when no parameters are set, returns a Logger instance with the correct proprieties', () => {
test('when no parameters are set, returns a Logger instance with the correct properties', () => {

// Prepare
const loggerOptions = {
Expand All @@ -74,6 +75,7 @@ describe('Helper: createLogger function', () => {
expect(logger).toBeInstanceOf(Logger);
expect(logger).toEqual({
coldStart: true,
defaultServiceName: 'service_undefined',
customConfigService: expect.any(EnvironmentVariablesService),
envVarsService: expect.any(EnvironmentVariablesService),
logEvent: false,
Expand All @@ -100,7 +102,7 @@ describe('Helper: createLogger function', () => {

});

test('when no constructor parameters and no environment variables are set, returns a Logger instance with the default proprieties', () => {
test('when no constructor parameters and no environment variables are set, returns a Logger instance with the default properties', () => {

// Prepare
const loggerOptions = undefined;
Expand All @@ -115,6 +117,7 @@ describe('Helper: createLogger function', () => {
expect(logger).toEqual({
coldStart: true,
customConfigService: undefined,
defaultServiceName: 'service_undefined',
envVarsService: expect.any(EnvironmentVariablesService),
logEvent: false,
logFormatter: expect.any(PowertoolLogFormatter),
Expand All @@ -138,7 +141,7 @@ describe('Helper: createLogger function', () => {

});

test('when a custom logFormatter is passed, returns a Logger instance with the correct proprieties', () => {
test('when a custom logFormatter is passed, returns a Logger instance with the correct properties', () => {

// Prepare
const loggerOptions:ConstructorOptions = {
Expand Down Expand Up @@ -166,7 +169,7 @@ describe('Helper: createLogger function', () => {
}));
});

test('when a custom serviceName is passed, returns a Logger instance with the correct proprieties', () => {
test('when a custom serviceName is passed, returns a Logger instance with the correct properties', () => {

// Prepare
const loggerOptions:ConstructorOptions = {
Expand Down Expand Up @@ -194,7 +197,7 @@ describe('Helper: createLogger function', () => {
}));
});

test('when a custom logLevel is passed, returns a Logger instance with the correct proprieties', () => {
test('when a custom logLevel is passed, returns a Logger instance with the correct properties', () => {

// Prepare
const loggerOptions:ConstructorOptions = {
Expand Down Expand Up @@ -236,6 +239,7 @@ describe('Helper: createLogger function', () => {
expect(logger).toEqual({
coldStart: true,
customConfigService: undefined,
defaultServiceName: 'service_undefined',
envVarsService: expect.any(EnvironmentVariablesService),
logEvent: false,
logFormatter: expect.any(PowertoolLogFormatter),
Expand All @@ -258,7 +262,7 @@ describe('Helper: createLogger function', () => {
});
});

test('when a custom sampleRateValue is passed, returns a Logger instance with the correct proprieties', () => {
test('when a custom sampleRateValue is passed, returns a Logger instance with the correct properties', () => {

// Prepare
const loggerOptions:ConstructorOptions = {
Expand Down Expand Up @@ -286,7 +290,7 @@ describe('Helper: createLogger function', () => {
}));
});

test('when a custom customConfigService is passed, returns a Logger instance with the correct proprieties', () => {
test('when a custom customConfigService is passed, returns a Logger instance with the correct properties', () => {

const configService: ConfigServiceInterface = {
get(name: string): string {
Expand Down Expand Up @@ -335,7 +339,7 @@ describe('Helper: createLogger function', () => {
}));
});

test('when custom persistentLogAttributes is passed, returns a Logger instance with the correct proprieties', () => {
test('when custom persistentLogAttributes is passed, returns a Logger instance with the correct properties', () => {

// Prepare
const loggerOptions:ConstructorOptions = {
Expand Down Expand Up @@ -377,7 +381,7 @@ describe('Helper: createLogger function', () => {
}));
});

test('when A custom environment is passed, returns a Logger instance with the correct proprieties', () => {
test('when a custom environment is passed, returns a Logger instance with the correct properties', () => {

// Prepare
const loggerOptions:ConstructorOptions = {
Expand Down
18 changes: 9 additions & 9 deletions packages/metrics/tests/unit/Metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Class: Metrics', () => {
metrics.addDimension(additionalDimension.name, additionalDimension.value);
const loggedData = metrics.serializeMetrics();

expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(1);
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(2);
expect(loggedData[additionalDimension.name]).toEqual(additionalDimension.value);
});

Expand Down Expand Up @@ -104,15 +104,15 @@ describe('Class: Metrics', () => {

expect(console.log).toBeCalledTimes(2);
expect(loggedData[0][dimensionItem.name]).toEqual(dimensionItem.value);
expect(loggedData[0]._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(1);
expect(loggedData[0]._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(2);
expect(loggedData[1][dimensionItem.name]).toBeUndefined();
expect(loggedData[1]._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(0);
expect(loggedData[1]._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(1);
});

test('Adding more than max dimensions should throw error', () => {
expect.assertions(1);
const metrics = new Metrics();
for (let x = 0; x < MAX_DIMENSION_COUNT; x++) {
for (let x = 1; x < MAX_DIMENSION_COUNT; x++) {
metrics.addDimension(`Dimension-${x}`, `value-${x}`);
}
try {
Expand All @@ -130,7 +130,7 @@ describe('Class: Metrics', () => {
metrics.addDimensions(additionalDimensions);
const loggedData = metrics.serializeMetrics();

expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(2);
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(3);
Object.keys(additionalDimensions).forEach((key) => {
expect(loggedData[key]).toEqual(additionalDimensions[key]);
});
Expand Down Expand Up @@ -249,7 +249,7 @@ describe('Class: Metrics', () => {
metrics.addMetric('test_name', MetricUnits.Seconds, 10);
metrics.addDimension(additionalDimension.name, additionalDimension.value);
const loggedData = metrics.serializeMetrics();
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(2);
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(3);
expect(loggedData[additionalDimension.name]).toEqual(additionalDimension.value);
metrics.clearDimensions();
}
Expand All @@ -259,7 +259,7 @@ describe('Class: Metrics', () => {
const loggedData = JSON.parse(consoleSpy.mock.calls[0][0]);

expect(console.log).toBeCalledTimes(1);
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(1);
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(2);
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0]).toContain('default');
expect(loggedData.default).toContain('defaultValue');
});
Expand Down Expand Up @@ -661,7 +661,7 @@ describe('Class: Metrics', () => {
metrics.addMetric('test_name', MetricUnits.Seconds, 10);
metrics.addDimension(additionalDimension.name, additionalDimension.value);
const loggedData = metrics.serializeMetrics();
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(2);
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(3);
expect(loggedData[additionalDimension.name]).toEqual(additionalDimension.value);
metrics.clearDimensions();

Expand All @@ -673,7 +673,7 @@ describe('Class: Metrics', () => {
const loggedData = JSON.parse(consoleSpy.mock.calls[0][0]);

expect(console.log).toBeCalledTimes(1);
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(1);
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0].length).toEqual(2);
expect(loggedData._aws.CloudWatchMetrics[0].Dimensions[0]).toContain('default');
expect(loggedData.default).toContain('defaultValue');
});
Expand Down
8 changes: 4 additions & 4 deletions packages/tracer/tests/unit/Tracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ describe('Class: Tracer', () => {
expect(putAnnotation).toBeCalledWith('Service', 'foo');

});
test('when called when a serviceName has not been set in the constructor or environment variables, it adds the default service name as an annotation', () => {

test('when called while a serviceName has not been set, it does nothing', () => {

process.env = { ...ENVIRONMENT_VARIABLES, POWERTOOLS_SERVICE_NAME : undefined };
// Prepare
delete process.env.POWERTOOLS_SERVICE_NAME;
const tracer: Tracer = new Tracer();
const putAnnotation = jest.spyOn(tracer, 'putAnnotation').mockImplementation(() => null);

// Act
tracer.addServiceNameAnnotation();

// Assess
expect(putAnnotation).toBeCalledTimes(0);
expect(putAnnotation).toBeCalledTimes(1);
expect(putAnnotation).toBeCalledWith('Service', 'service_undefined');

});

Expand Down