Skip to content

Commit

Permalink
feat(otlp): add protobuf compression (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: GALLLASMILAN <gallas.milan@gmail.com>
  • Loading branch information
GALLLASMILAN authored Dec 16, 2024
1 parent 91e37fa commit eb1160d
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 196 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:
jobs:
main:
timeout-minutes: 20
name: Lint & Build & Test
name: Lint & Format & CommitLint & Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
.vscode/
.next/
.yarn/
pnpm-lock.yaml
CHANGELOG.md
schema.d.ts
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@commitlint/types": "^19.5.0",
"@fastify/type-provider-json-schema-to-ts": "^3.0.0",
"@fastify/type-provider-json-schema-to-ts": "^4.0.1",
"@opentelemetry/exporter-trace-otlp-proto": "^0.55.0",
"@opentelemetry/instrumentation": "^0.55.0",
"@opentelemetry/sdk-node": "^0.55.0",
Expand Down Expand Up @@ -60,10 +60,11 @@
"vitest": "^2.1.3"
},
"dependencies": {
"@fastify/auth": "^4.6.1",
"@fastify/request-context": "^5.1.0",
"@fastify/swagger": "^8.14.0",
"@fastify/swagger-ui": "^3.0.0",
"@fastify/auth": "^5.0.1",
"@fastify/compress": "^8.0.1",
"@fastify/request-context": "^6.0.1",
"@fastify/swagger": "^9.0.4",
"@fastify/swagger-ui": "^5.2.0",
"@godaddy/terminus": "^4.12.1",
"@grpc/grpc-js": "^1.12.2",
"@grpc/proto-loader": "^0.7.13",
Expand All @@ -75,8 +76,8 @@
"bullmq": "^5.8.2",
"dotenv": "^16.4.5",
"dotenv-safe": "^9.1.0",
"fastify": "^4.27.0",
"fastify-plugin": "^4.5.1",
"fastify": "^5.1.0",
"fastify-plugin": "^5.0.1",
"http-status-codes": "^2.3.0",
"ioredis": "^5.4.1",
"json-schema-to-ts": "^3.1.0",
Expand Down
4 changes: 4 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import './utils/load-config.js';
import Fastify from 'fastify';
import { RequestContext } from '@mikro-orm/core';
import { JsonSchemaToTsProvider } from '@fastify/type-provider-json-schema-to-ts';
import compressPlugin from '@fastify/compress';

import { initTerminus } from './utils/terminus.js';
import { authPlugin } from './utils/auth.js';
Expand Down Expand Up @@ -66,6 +67,9 @@ export async function bootstrap({ port }: BootstrapOptions) {
timeout: 25000 // 25s
});

// compress gzip (followed by https://opentelemetry.io/docs/specs/otlp/#protocol-details)
app.register(compressPlugin, { encodings: ['gzip'], customTypes: /x-protobuf$/ });

// error
app.register(errorPlugin);

Expand Down
2 changes: 1 addition & 1 deletion src/trace/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('trace module', () => {
expect(res.status).toBe(200);
});

it.skip('should return the `bad request` response when the invalid result is sent', async () => {
it('should return the `bad request` response when the invalid result is sent', async () => {
const { status, statusText } = await sendCustomProtobuf({
invalidSpanKey: 4200,
secondInvalidSpanKey: 3000
Expand Down
12 changes: 6 additions & 6 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import { FastifyReply, FastifyRequest } from 'fastify';
import { Logger, LoggerOptions, pino } from 'pino';
import { requestContext } from '@fastify/request-context';

export function createLogger(
export function createLoggerConfig(
options?: Omit<LoggerOptions, 'name' | 'level' | 'timestamp'>
): Logger {
return pino({
): LoggerOptions {
return {
...options,
name: 'bee-observe',
level: process.env.LOG_LEVEL || 'info',
Expand All @@ -37,10 +37,10 @@ export function createLogger(
},
...options?.formatters
}
});
};
}

export const fastifyLogger = createLogger({
export const fastifyLogger = createLoggerConfig({
serializers: {
req(request: FastifyRequest) {
return {
Expand Down Expand Up @@ -72,7 +72,7 @@ export const LogLabels = {
CORRELATION_ID: 'correlationId'
} as const;

const log = createLogger();
const log = pino(createLoggerConfig());

export const getLogger = () => {
const request = requestContext.get('request');
Expand Down
Loading

0 comments on commit eb1160d

Please sign in to comment.