Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
chore(logging): update to remove no longer needed patches (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
10xLaCroixDrinker authored Oct 24, 2023
1 parent 746df6b commit f937670
Show file tree
Hide file tree
Showing 10 changed files with 638 additions and 275 deletions.
87 changes: 70 additions & 17 deletions __tests__/server/utils/logging/config/otel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ jest.mock('node:os', () => ({
jest.spyOn(pino, 'transport');

describe('OpenTelemetry logging', () => {
beforeEach(() => jest.clearAllMocks());
const originalNodeEnv = process.env.NODE_ENV;

beforeEach(() => {
process.env.NODE_ENV = 'production';
jest.clearAllMocks();
});

afterAll(() => {
process.env.NODE_ENV = originalNodeEnv;
});

describe('config', () => {
it('should serialize errors', () => {
Expand All @@ -49,10 +58,6 @@ describe('OpenTelemetry logging', () => {
`);
});

it('should set the error key', () => {
expect(otelConfig.errorKey).toBe('error');
});

it('should coerce "log" level to "info" level', () => {
expect(otelConfig.formatters.level('log', 35)).toEqual({ level: 30 });
});
Expand Down Expand Up @@ -97,19 +102,14 @@ describe('OpenTelemetry logging', () => {
process.env.OTEL_RESOURCE_ATTRIBUTES = 'service.custom.id=XXXXX;deployment.env=qa';
const transport = createOtelTransport();
expect(pino.transport).toHaveBeenCalledTimes(1);
expect(pino.transport.mock.calls[0][0]).toMatchInlineSnapshot(`
expect(pino.transport.mock.calls[0][0].options.resourceAttributes).toMatchInlineSnapshot(`
{
"options": {
"resourceAttributes": {
"deployment.env": "qa",
"service.custom.id": "XXXXX",
"service.instance.id": "mockHostName",
"service.name": "Mock Service Name",
"service.namespace": "Mock Service Namespace",
"service.version": "X.X.X",
},
},
"target": "pino-opentelemetry-transport",
"deployment.env": "qa",
"service.custom.id": "XXXXX",
"service.instance.id": "mockHostName",
"service.name": "Mock Service Name",
"service.namespace": "Mock Service Namespace",
"service.version": "X.X.X",
}
`);
expect(pino.transport.mock.results[0].value).toBe(transport);
Expand All @@ -125,17 +125,70 @@ describe('OpenTelemetry logging', () => {
expect(pino.transport.mock.calls[0][0]).toMatchInlineSnapshot(`
{
"options": {
"logRecordProcessorOptions": [
{
"exporterOptions": {
"protocol": "grpc",
},
"recordProcessorType": "batch",
},
],
"loggerName": "Mock Service Name",
"messageKey": "message",
"resourceAttributes": {
"service.instance.id": "mockHostName",
"service.name": "Mock Service Name",
"service.namespace": "Mock Service Namespace",
"service.version": "X.X.X",
},
"serviceVersion": "X.X.X",
},
"target": "pino-opentelemetry-transport",
}
`);
expect(pino.transport.mock.results[0].value).toBe(transport);
});
});

it('should include the console exporter in development', () => {
process.env.NODE_ENV = 'development';
const transport = createOtelTransport();
expect(pino.transport).toHaveBeenCalledTimes(1);
expect(pino.transport.mock.calls[0][0].options.logRecordProcessorOptions)
.toMatchInlineSnapshot(`
[
{
"exporterOptions": {
"protocol": "grpc",
},
"recordProcessorType": "batch",
},
{
"exporterOptions": {
"protocol": "console",
},
"recordProcessorType": "simple",
},
]
`);
expect(pino.transport.mock.results[0].value).toBe(transport);
});

it('should not include the console exporter in production', () => {
process.env.NODE_ENV = 'production';
const transport = createOtelTransport();
expect(pino.transport).toHaveBeenCalledTimes(1);
expect(pino.transport.mock.calls[0][0].options.logRecordProcessorOptions)
.toMatchInlineSnapshot(`
[
{
"exporterOptions": {
"protocol": "grpc",
},
"recordProcessorType": "batch",
},
]
`);
expect(pino.transport.mock.results[0].value).toBe(transport);
});
});
19 changes: 0 additions & 19 deletions __tests__/server/utils/logging/logger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import developmentStream from '../../../../src/server/utils/logging/config/devel
import otelConfig, { createOtelTransport } from '../../../../src/server/utils/logging/config/otel';

jest.spyOn(pino, 'pino');
jest.spyOn(pino, 'multistream');

jest.mock('yargs', () => ({
argv: {
Expand Down Expand Up @@ -95,23 +94,5 @@ describe('logger', () => {
deepmerge(baseConfig, otelConfig),
createOtelTransport()
);
expect(pino.multistream).not.toHaveBeenCalled();
});

it('uses both OpenTlemetry config and development config when OTEL_EXPORTER_OTLP_LOGS_ENDPOINT is set in development', () => {
process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://0.0.0.0:4317/v1/logs';
process.env.NODE_ENV = 'development';
const logger = createLogger();
expect(pino.pino).toHaveBeenCalledTimes(1);
expect(pino.pino.mock.results[0].value).toBe(logger);
expect(pino.multistream).toHaveBeenCalledTimes(1);
expect(pino.multistream).toHaveBeenCalledWith([
{ stream: developmentStream },
createOtelTransport(),
]);
expect(pino.pino).toHaveBeenCalledWith(
deepmerge(baseConfig, otelConfig),
pino.multistream.mock.results[0].value
);
});
});
Loading

0 comments on commit f937670

Please sign in to comment.