1- // import ' ./polyfills/compression'
1+ import " ./polyfills/compression" ;
22
3+ import { opentelemetry } from "@elysiajs/opentelemetry" ;
4+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto" ;
5+ import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-node" ;
36import { Elysia } from "elysia" ;
47import { logger } from "./lib/logger" ;
5- // import stripeRouter from './routes/stripe';
68import { getProducerStats } from "./lib/producer" ;
79import basketRouter from "./routes/basket" ;
810import emailRouter from "./routes/email" ;
9- import "./polyfills/compression" ;
1011
1112function getKafkaHealth ( ) {
1213 const stats = getProducerStats ( ) ;
@@ -34,16 +35,31 @@ function getKafkaHealth() {
3435 lastErrorTime : stats . lastErrorTime ,
3536 } ;
3637}
37- // import { checkBotId } from "botid/server";
3838
3939const app = new Elysia ( )
40- . onError ( ( { error, code } ) => {
40+ . use (
41+ opentelemetry ( {
42+ serviceName : "basket" ,
43+ spanProcessors : [
44+ new BatchSpanProcessor (
45+ new OTLPTraceExporter ( {
46+ url : "https://api.axiom.co/v1/traces" ,
47+ headers : {
48+ Authorization : `Bearer ${ process . env . AXIOM_TOKEN } ` ,
49+ "X-Axiom-Dataset" : process . env . AXIOM_DATASET ?? "basket" ,
50+ } ,
51+ } )
52+ ) ,
53+ ] ,
54+ } )
55+ )
56+ . onError ( function handleError ( { error, code } ) {
4157 if ( code === "NOT_FOUND" ) {
4258 return new Response ( null , { status : 404 } ) ;
4359 }
4460 logger . error ( { error } , "Error in basket service" ) ;
4561 } )
46- . onBeforeHandle ( ( { request, set } ) => {
62+ . onBeforeHandle ( function handleCors ( { request, set } ) {
4763 const origin = request . headers . get ( "origin" ) ;
4864 if ( origin ) {
4965 set . headers ??= { } ;
@@ -58,17 +74,18 @@ const app = new Elysia()
5874 . options ( "*" , ( ) => new Response ( null , { status : 204 } ) )
5975 . use ( basketRouter )
6076 . use ( emailRouter )
61- . get ( "/health" , ( ) => ( {
62- status : "ok" ,
63- version : "1.0.0" ,
64- producer_stats : getProducerStats ( ) ,
65- kafka : getKafkaHealth ( ) ,
66- } ) ) ;
77+ . get ( "/health" , function healthCheck ( ) {
78+ return {
79+ status : "ok" ,
80+ version : "1.0.0" ,
81+ producer_stats : getProducerStats ( ) ,
82+ kafka : getKafkaHealth ( ) ,
83+ } ;
84+ } ) ;
6785
6886const port = process . env . PORT || 4000 ;
6987
7088console . log ( `Starting basket service on port ${ port } ` ) ;
71- console . log ( `Basket service running on http://localhost:${ port } ` ) ;
7289
7390export default {
7491 fetch : app . fetch ,
0 commit comments