Skip to content

Commit

Permalink
feat(telemetry): typescript minification (#20)
Browse files Browse the repository at this point in the history
Signed-off-by: GALLLASMILAN <gallas.milan@gmail.com>
  • Loading branch information
GALLLASMILAN authored Jan 2, 2025
1 parent 9076e38 commit f7226f6
Show file tree
Hide file tree
Showing 33 changed files with 981 additions and 609 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
"name": "bee-observe",
"packageManager": "yarn@4.3.1",
"version": "0.0.5",
"author": "IBM Corp.",
"contributors": [
"Milan Gallas <milan.gallas@ibm.com>"
],
"license": "Apache-2.0",
"description": "Observability API server for bee-agent-framework",
"type": "module",
"scripts": {
"build": "rm -rf dist && tsc && cp -R src/protos dist/protos",
"proto:generate": "proto-loader-gen-types --defaults --oneofs --longs=Number --enums=String --grpcLib=@grpc/grpc-js --outDir=./src/types/generated ./src/protos/*.proto && node scripts/add_js_extensions.js",
"proto:generate": "./scripts/open_telemetry_generate_protos/generate_protos.sh",
"start:infra": "docker compose -f compose-before.yml up -d mongo redis mlflow",
"start:dev": "tsx watch ./src/index.ts | pino-pretty --singleLine",
"stop:infra": "docker compose -f compose-before.yml down",
Expand Down Expand Up @@ -54,6 +58,7 @@
"prettier": "^3.3.2",
"release-it": "^17.6.0",
"ts-node": "^10.9.2",
"tsup": "^8.3.5",
"tsx": "^4.11.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.13.0",
Expand Down
24 changes: 22 additions & 2 deletions scripts/copyright.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@

set -e

TARGETS=(${TARGETS:-src scripts})

# Path to the package.json file
PACKAGE_JSON_PATH="./package.json"

# Check if the package.json file exists
if [[ ! -f "$PACKAGE_JSON_PATH" ]]; then
echo "Error: package.json file not found at $PACKAGE_JSON_PATH"
exit 1
fi

# Retrieve the author property using jq
AUTHOR=$(jq -r '.author' "$PACKAGE_JSON_PATH")

# Check if the author property is not null or empty
if [[ -z "$AUTHOR" ]]; then
echo "Error: author property not found in package.json"
exit 1
fi

# Check if 'nwa' command is not available and 'go' is available, then install 'nwa'
if ! command -v nwa &> /dev/null && command -v go &> /dev/null; then
echo "Installing 'nwa' via 'go' (https://github.com/B1NARY-GR0UP/nwa)"
Expand All @@ -24,9 +44,9 @@ if ! command -v nwa &> /dev/null && command -v go &> /dev/null; then
fi

if command -v nwa &> /dev/null; then
nwa add -l apache -c "IBM Corp." scripts/**/*.{js,sh} src/**/*.{ts,js}
nwa add -l apache -c "$AUTHOR" "${TARGETS[@]}"
elif command -v docker &> /dev/null; then
docker run -it -v "${PWD}:/src" ghcr.io/b1nary-gr0up/nwa:main add -l apache -c "IBM Corp." scripts src
docker run --rm -v "${PWD}:/src" ghcr.io/b1nary-gr0up/nwa:main add -l apache -c "$AUTHOR" "${TARGETS[@]}"
else
echo "Error: 'nwa' is not available. Either install it manually or install go/docker."
exit 1
Expand Down
52 changes: 52 additions & 0 deletions scripts/open_telemetry_generate_protos/generate_protos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
# Copyright 2024 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

GRPC_PROTO_PATH="./src/protos"
GRPC_TYPES_PATH="./src/types/open-telemetry/generated.ts"

SCRIPT_DIR="$(dirname "$0")"
OUTPUT_RELATIVE_PATH="dist/merged.d.ts"
GRPC_TYPES_TMP_PATH="types"

rm -f "$GRPC_TYPES_PATH"

rm -rf "${SCRIPT_DIR}"/{dist,dts,types}


yarn run proto-loader-gen-types \
--defaults \
--oneofs \
--longs=Number \
--enums=String \
--grpcLib=@grpc/grpc-js \
--"outDir=${SCRIPT_DIR}/${GRPC_TYPES_TMP_PATH}" \
"${GRPC_PROTO_PATH}"/*.proto


cd "$SCRIPT_DIR"
ENTRY="$(basename "$OUTPUT_RELATIVE_PATH" ".d.ts")" tsup --dts-only
sed -i.bak '$ d' "$OUTPUT_RELATIVE_PATH"
sed -i.bak -E "s/^interface/export interface/" "$OUTPUT_RELATIVE_PATH"
sed -i.bak -E "s/^type/export type/" "$OUTPUT_RELATIVE_PATH"
cd -

mv "$SCRIPT_DIR/$OUTPUT_RELATIVE_PATH" "$GRPC_TYPES_PATH"
rm -rf "${SCRIPT_DIR}"/{dist,dts,types}

yarn run lint:fix "${GRPC_TYPES_PATH}"
yarn prettier --write "${GRPC_TYPES_PATH}"
TARGETS="$GRPC_TYPES_PATH" yarn copyright
6 changes: 6 additions & 0 deletions scripts/open_telemetry_generate_protos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "ibm-vllm-proto-types",
"type": "module",
"version": "1.0.0",
"typings": "./types/generation.d.ts"
}
14 changes: 14 additions & 0 deletions scripts/open_telemetry_generate_protos/tsconfig.proto.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"moduleResolution": "node",
"rootDir": ".",
"baseUrl": ".",
"target": "ESNext",
"module": "ESNext",
"outDir": "dist",
"declaration": true,
"emitDeclarationOnly": true,
"skipLibCheck": true,
"sourceMap": false
}
}
42 changes: 42 additions & 0 deletions scripts/open_telemetry_generate_protos/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright 2024 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { defineConfig } from 'tsup';
import fs from 'node:fs';

if (!process.env.ENTRY) {
throw new Error(`Entry file was not provided!`);
}
const target = `types/${process.env.ENTRY}.ts`;
await fs.promises.writeFile(
target,
[`export { ProtoGrpcType } from './trace_service.js'`].join('\n')
);

export default defineConfig({
entry: [target],
tsconfig: './tsconfig.proto.json',
sourcemap: false,
dts: true,
format: ['esm'],
treeshake: true,
legacyOutput: false,
skipNodeModulesBundle: true,
bundle: true,
splitting: false,
silent: false,
clean: true
});
3 changes: 1 addition & 2 deletions src/span/span.document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import { ObjectId } from '@mikro-orm/mongodb';

import { BaseDocument } from '../utils/base.document.js';
import { Trace } from '../trace/trace.document.js';
import type { Span__Output } from '../types/generated/opentelemetry/proto/trace/v1/Span.js';
import { _opentelemetry_proto_trace_v1_Status_StatusCode } from '../types/generated/opentelemetry/proto/trace/v1/Status.js';
import type { Span__Output } from '../types/open-telemetry/generated.js';

import { SpanDto } from './span.dto.js';
import { getAttributeValue, uint8ArrayToHexString, unixNanoToDate } from './utilt.js';
Expand Down
2 changes: 1 addition & 1 deletion src/span/utilt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import { Long } from '@grpc/proto-loader';

import { Span__Output } from '../types/generated/opentelemetry/proto/trace/v1/Span.js';
import { MainSpan } from '../types/internal/span.js';
import type { Span__Output } from '../types/open-telemetry/generated.js';

import { Span } from './span.document.js';

Expand Down
3 changes: 1 addition & 2 deletions src/trace/trace.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import { FastifyPluginAsyncJsonSchemaToTs } from '@fastify/type-provider-json-sc
import { StatusCodes } from 'http-status-codes';

import { withResultsResponse, withResultResponse, Tags } from '../utils/swagger.js';
import { ExportTraceServiceRequest__Output } from '../types/generated/opentelemetry/proto/collector/trace/v1/ExportTraceServiceRequest.js';
import { getModuleLogger } from '../utils/logger-factories.js';
import { constants } from '../utils/constants.js';
import type { ExportTraceServiceRequest__Output } from '../types/open-telemetry/generated.js';

import {
traceSchema,
Expand Down
2 changes: 1 addition & 1 deletion src/trace/trace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { ORM } from '../utils/db.js';
import { ErrorWithProps, ErrorWithPropsCodes } from '../utils/error.js';
import { addMlflowTraceToQueue } from '../mlflow/queue/mlflow-trace-create.queue.js';
import { Span } from '../span/span.document.js';
import { ExportTraceServiceRequest__Output } from '../types/generated/opentelemetry/proto/collector/trace/v1/ExportTraceServiceRequest.js';
import { findMainSpan } from '../span/utilt.js';
import { getServiceLogger } from '../utils/logger-factories.js';
import { constants } from '../utils/constants.js';
import type { ExportTraceServiceRequest__Output } from '../types/open-telemetry/generated.js';

import { TraceDto, TraceGetOneQuery, TraceGetQuery } from './trace.dto.js';
import { assemblyTrace } from './utils/assembly-trace.js';
Expand Down
22 changes: 0 additions & 22 deletions src/types/generated/common.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f7226f6

Please sign in to comment.