-
Before using telemetry:
bun:/workspaces/backend-boilerplate$ time bun run start
$ bun run src/index.ts
{"level":20,"time":1727344749180,"pid":22433,"hostname":"boilerplate-backend","name":"backend-boilerplate","msg":"[ElysiaRoutes]: ASSIGN: healthCheckRoutes"}
{"level":20,"time":1727344749180,"pid":22433,"hostname":"boilerplate-backend","name":"backend-boilerplate","msg":"[ElysiaRoutes]: ASSIGN: roleRoutes"}
{"level":30,"time":1727344749183,"pid":22433,"hostname":"boilerplate-backend","name":"backend-boilerplate","msg":"[ElysiaWebServer]: API is running at localhost:5000"}
real 0m0.081s
user 0m0.108s
sys 0m0.045s After using telemetry:
bun:/workspaces/backend-boilerplate$ time bun run start
$ bun run src/index.ts
{"level":20,"time":1727344894412,"pid":23617,"hostname":"boilerplate-backend","name":"backend-boilerplate","msg":"[ElysiaRoutes]: ASSIGN: healthCheckRoutes"}
{"level":20,"time":1727344894412,"pid":23617,"hostname":"boilerplate-backend","name":"backend-boilerplate","msg":"[ElysiaRoutes]: ASSIGN: roleRoutes"}
{"level":30,"time":1727344894415,"pid":23617,"hostname":"boilerplate-backend","name":"backend-boilerplate","msg":"[ElysiaWebServer]: API is running at localhost:5000"}
real 0m0.383s
user 0m0.403s
sys 0m0.079s I know it doesn't significant increase, maybe some delay for 300~400ms, but still.. i don't know if this is on purpose or it could be more enchanced this is the implementation: export const app = new Elysia({
precompile: true,
});
app.use(ip());
app.use(cors());
// NOTE: Use openTelemetry for distributed tracing
// FIXME: This is adding some startup time
app.use(
opentelemetry({
serviceName: APP_NAME,
spanProcessors: [
new BatchSpanProcessor(
new OTLPTraceExporter({
url: `http://${OTEL_BACKEND_HOST}/v1/traces`,
})
),
],
})
);
export async function startServer(port: number) {
// NOTE: Assigning routes
logger.debug("[ElysiaRoutes]: ASSIGN: healthCheckRoutes");
app.use(import("../health-check/health-check.route"));
logger.debug("[ElysiaRoutes]: ASSIGN: roleRoutes");
app.use(import("../role/role.route"));
app.listen(port);
logger.info(
`[ElysiaWebServer]: API is running at ${app.server?.hostname}:${app.server?.port}`
);
process.exit();
} |
Beta Was this translation helpful? Give feedback.
Answered by
askareija
Oct 1, 2024
Replies: 1 comment
-
I've resolved it by using another instance and use lazy load module. in app.use(import("./otel")); then create new Elysia instance import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { APP_NAME, OTEL_BACKEND_HOST } from "../utils/constants";
import Elysia from "elysia";
import { opentelemetry } from "@elysiajs/opentelemetry";
const spanProcessor = new BatchSpanProcessor(
new OTLPTraceExporter({
url: `http://${OTEL_BACKEND_HOST}/v1/traces`,
})
);
const otelModule = new Elysia({
prefix: "otel",
});
otelModule.use(
opentelemetry({
serviceName: APP_NAME,
spanProcessors: [spanProcessor],
})
);
export default otelModule; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
askareija
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've resolved it by using another instance and use lazy load module.
in
main.ts
:then create new Elysia instance
otel.ts
: