@onelog-sdk/node 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var b=Object.create;var c=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var o in t)c(e,o,{get:t[o],enumerable:!0})},h=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of M(t))!I.call(e,n)&&n!==o&&c(e,n,{get:()=>t[n],enumerable:!(r=w(t,n))||r.enumerable});return e};var D=(e,t,o)=>(o=e!=null?b(S(e)):{},h(t||!e||!e.__esModule?c(o,"default",{value:e,enumerable:!0}):o,e)),H=e=>h(c({},"__esModule",{value:!0}),e);var j={};C(j,{createLogger:()=>_,errorMiddleware:()=>O,httpCall:()=>R,instrumentApp:()=>L,sdkStartPromise:()=>x});module.exports=H(j);var i=require("@opentelemetry/api"),E=require("@opentelemetry/sdk-node"),y=require("@opentelemetry/resources"),v=require("@opentelemetry/exporter-trace-otlp-http"),g=require("@opentelemetry/auto-instrumentations-node"),m=require("undici");i.diag.setLogger(new i.DiagConsoleLogger,i.DiagLogLevel.WARN);var k=process.env.OTEL_SERVICE_NAME||process.env.MAIN_MODULE||"unknown-service",F=process.env.OTEL_NAMESPACE||process.env.OTEL_SERVICE_NAMESPACE||process.env.MAIN_APP||"app",U=process.env.MAIN_ENV||process.env.NODE_ENV||"development",T=process.env.MAIN_MODULE||"unknown-module",$=(process.env.OTEL_EXPORTER_OTLP_ENDPOINT||"http://localhost:4318").replace(/\/$/,""),q=(process.env.ONELOG_EXPRESS_LAYERS||"").toLowerCase()==="true",f=[process.env.HTTPS_PROXY,process.env.https_proxy,process.env.HTTP_PROXY,process.env.http_proxy].find(e=>e&&e.trim().length>0);if(f)try{(0,m.setGlobalDispatcher)(new m.ProxyAgent(f)),console.log(`[onelog] Proxy enabled for outbound traffic: ${f}`)}catch(e){console.error("[onelog] Failed to configure proxy agent:",e.message)}var G=y.Resource.default().merge(new y.Resource({"service.name":k,"service.namespace":F,"deployment.environment":U,"module.name":T})),V=(0,g.getNodeAutoInstrumentations)({"@opentelemetry/instrumentation-http":{enabled:!0},"@opentelemetry/instrumentation-express":{enabled:!0,ignoreLayersType:q?[]:["middleware","request_handler"]},"@opentelemetry/instrumentation-undici":{enabled:!0},"@opentelemetry/instrumentation-ioredis":{enabled:!1},"@opentelemetry/instrumentation-redis":{enabled:!1},"@opentelemetry/instrumentation-fs":{enabled:!1},"@opentelemetry/instrumentation-dns":{enabled:!1},"@opentelemetry/instrumentation-net":{enabled:!1}}),N=new E.NodeSDK({traceExporter:new v.OTLPTraceExporter({url:`${$}/v1/traces`}),resource:G,instrumentations:[V]}),x=Promise.resolve(N.start()).catch(e=>(console.error("Failed to start OpenTelemetry SDK",e),Promise.resolve())),A=async()=>{try{await N.shutdown()}catch(e){console.error("Error shutting down OpenTelemetry SDK",e)}};process.on("SIGTERM",A);process.on("SIGINT",A);var L=(e,t,o)=>{let r=o||process.env.MAIN_MODULE||T;e.use((n,a,s)=>{let p=i.trace.getActiveSpan();p&&(p.setAttribute("module.name",r),p.updateName(`[${r}] ${n.method} ${n.path}`)),t&&t.info({method:n.method,path:n.path,ip:n.ip},"Incoming request"),s()})};var P=D(require("pino"),1);function _(){let e=process.env.MAIN_ENV||"development",t=process.env.MAIN_APP||"app",o=process.env.MAIN_MODULE||"unknown-module";return(0,P.default)({transport:{targets:[{target:"pino-opentelemetry-transport",level:"info",options:{resourceAttributes:{"service.name":t,"service.namespace":e,"deployment.environment":e,"module.name":o,"host.name":require("os").hostname()}}},{target:"pino-pretty",level:"debug",options:{colorize:!0,translateTime:"HH:MM:ss Z",ignore:"pid,hostname"}}]}}).child({env:e,app:t,module:o})}var l=require("@opentelemetry/api"),O=e=>(t,o,r,n)=>{e&&e.error({error:t.message,stack:t.stack,path:o.path},"Unhandled error");let a=l.trace.getActiveSpan();if(a&&(a.recordException(t),a.setStatus({code:l.SpanStatusCode.ERROR,message:t.message})),r.headersSent)return n(t);r.status(500).json({error:t.message,module:process.env.MAIN_MODULE||"unknown-module"})};async function R(e,t={},o,r={}){let n={...t},a=(n.method||"GET").toString().toUpperCase();n.body&&typeof n.body!="string"&&!(n.body instanceof Buffer)&&!(n.body instanceof ArrayBuffer)&&(n.body=JSON.stringify(n.body),n.headers={"Content-Type":"application/json",...n.headers||{}}),o&&o.info({...r,url:e,method:a},"HTTP call start");try{let s=await fetch(e,n),u=(s.headers.get("content-type")||"").includes("application/json")?await s.json().catch(()=>null):await s.text().catch(()=>null);if(!s.ok){let d=new Error(`HTTP ${s.status} ${s.statusText||""}`.trim());throw d.status=s.status,d.data=u,o&&o.error({...r,url:e,method:a,status:s.status,data:u},"HTTP call failed"),d}return o&&o.info({...r,url:e,method:a,status:s.status},"HTTP call success"),u}catch(s){throw o&&o.error({...r,url:e,method:a,error:s.message},"HTTP call error"),s}}0&&(module.exports={createLogger,errorMiddleware,httpCall,instrumentApp,sdkStartPromise});
1
+ "use strict";var w=Object.create;var c=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var o in t)c(e,o,{get:t[o],enumerable:!0})},v=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of I(t))!D.call(e,n)&&n!==o&&c(e,n,{get:()=>t[n],enumerable:!(r=M(t,n))||r.enumerable});return e};var k=(e,t,o)=>(o=e!=null?w(C(e)):{},v(t||!e||!e.__esModule?c(o,"default",{value:e,enumerable:!0}):o,e)),$=e=>v(c({},"__esModule",{value:!0}),e);var J={};H(J,{createLogger:()=>b,errorMiddleware:()=>O,httpCall:()=>R,instrumentApp:()=>S,sdkStartPromise:()=>x});module.exports=$(J);var i=require("@opentelemetry/api"),E=require("@opentelemetry/sdk-node"),y=require("@opentelemetry/resources"),N=require("@opentelemetry/exporter-trace-otlp-http"),g=require("@opentelemetry/auto-instrumentations-node"),m=require("undici");i.diag.setLogger(new i.DiagConsoleLogger,i.DiagLogLevel.WARN);var F=process.env.OTEL_SERVICE_NAME||process.env.MAIN_MODULE||"unknown-service",U=process.env.OTEL_NAMESPACE||process.env.OTEL_SERVICE_NAMESPACE||process.env.MAIN_APP||"app",q=process.env.MAIN_ENV||process.env.NODE_ENV||"development",T=process.env.MAIN_MODULE||"unknown-module",G=(process.env.OTEL_EXPORTER_OTLP_ENDPOINT||"http://localhost:4318").replace(/\/$/,""),V=(process.env.ONELOG_EXPRESS_LAYERS||"").toLowerCase()==="true",A=process.env.MAIN_MODULE||T,f=[process.env.HTTPS_PROXY,process.env.https_proxy,process.env.HTTP_PROXY,process.env.http_proxy].find(e=>e&&e.trim().length>0);if(f)try{(0,m.setGlobalDispatcher)(new m.ProxyAgent(f)),console.log(`[onelog] Proxy enabled for outbound traffic: ${f}`)}catch(e){console.error("[onelog] Failed to configure proxy agent:",e.message)}var j=y.Resource.default().merge(new y.Resource({"service.name":F,"service.namespace":U,"deployment.environment":q,"module.name":A})),h=class{constructor(t){this.moduleName=t}onStart(t){if(!t)return;let o=t.name||t._name||"";this.moduleName&&!o.startsWith(`[${this.moduleName}] `)&&t.updateName(`[${this.moduleName}] ${o}`),this.moduleName&&t.setAttribute("module.name",this.moduleName)}onEnd(t){}shutdown(){return Promise.resolve()}forceFlush(){return Promise.resolve()}},X=(0,g.getNodeAutoInstrumentations)({"@opentelemetry/instrumentation-http":{enabled:!0},"@opentelemetry/instrumentation-express":{enabled:!0,ignoreLayersType:V?[]:["middleware","request_handler"]},"@opentelemetry/instrumentation-undici":{enabled:!0},"@opentelemetry/instrumentation-ioredis":{enabled:!1},"@opentelemetry/instrumentation-redis":{enabled:!1},"@opentelemetry/instrumentation-fs":{enabled:!1},"@opentelemetry/instrumentation-dns":{enabled:!1},"@opentelemetry/instrumentation-net":{enabled:!1}}),P=new E.NodeSDK({traceExporter:new N.OTLPTraceExporter({url:`${G}/v1/traces`}),resource:j,instrumentations:[X],spanProcessor:new h(A)}),x=Promise.resolve(P.start()).catch(e=>(console.error("Failed to start OpenTelemetry SDK",e),Promise.resolve())),L=async()=>{try{await P.shutdown()}catch(e){console.error("Error shutting down OpenTelemetry SDK",e)}};process.on("SIGTERM",L);process.on("SIGINT",L);var S=(e,t,o)=>{let r=o||process.env.MAIN_MODULE||T;e.use((n,a,s)=>{let p=i.trace.getActiveSpan();p&&(p.setAttribute("module.name",r),p.updateName(`[${r}] ${n.method} ${n.path}`)),t&&t.info({method:n.method,path:n.path,ip:n.ip},"Incoming request"),s()})};var _=k(require("pino"),1);function b(){let e=process.env.MAIN_ENV||"development",t=process.env.MAIN_APP||"app",o=process.env.MAIN_MODULE||"unknown-module";return(0,_.default)({transport:{targets:[{target:"pino-opentelemetry-transport",level:"info",options:{resourceAttributes:{"service.name":t,"service.namespace":e,"deployment.environment":e,"module.name":o,"host.name":require("os").hostname()}}},{target:"pino-pretty",level:"debug",options:{colorize:!0,translateTime:"HH:MM:ss Z",ignore:"pid,hostname"}}]}}).child({env:e,app:t,module:o})}var l=require("@opentelemetry/api"),O=e=>(t,o,r,n)=>{e&&e.error({error:t.message,stack:t.stack,path:o.path},"Unhandled error");let a=l.trace.getActiveSpan();if(a&&(a.recordException(t),a.setStatus({code:l.SpanStatusCode.ERROR,message:t.message})),r.headersSent)return n(t);r.status(500).json({error:t.message,module:process.env.MAIN_MODULE||"unknown-module"})};async function R(e,t={},o,r={}){let n={...t},a=(n.method||"GET").toString().toUpperCase();n.body&&typeof n.body!="string"&&!(n.body instanceof Buffer)&&!(n.body instanceof ArrayBuffer)&&(n.body=JSON.stringify(n.body),n.headers={"Content-Type":"application/json",...n.headers||{}}),o&&o.info({...r,url:e,method:a},"HTTP call start");try{let s=await fetch(e,n),u=(s.headers.get("content-type")||"").includes("application/json")?await s.json().catch(()=>null):await s.text().catch(()=>null);if(!s.ok){let d=new Error(`HTTP ${s.status} ${s.statusText||""}`.trim());throw d.status=s.status,d.data=u,o&&o.error({...r,url:e,method:a,status:s.status,data:u},"HTTP call failed"),d}return o&&o.info({...r,url:e,method:a,status:s.status},"HTTP call success"),u}catch(s){throw o&&o.error({...r,url:e,method:a,error:s.message},"HTTP call error"),s}}0&&(module.exports={createLogger,errorMiddleware,httpCall,instrumentApp,sdkStartPromise});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/tracing.ts","../src/logger.ts","../src/exceptions.ts","../src/http-caller.ts"],"sourcesContent":["export { sdkStartPromise, instrumentApp } from './tracing.js';\nexport { createLogger } from './logger.js';\nexport { errorMiddleware } from './exceptions.js';\nexport { httpCall } from './http-caller.js';\n","import { diag, DiagConsoleLogger, DiagLogLevel, trace } from '@opentelemetry/api';\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport { Resource } from '@opentelemetry/resources';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport { ProxyAgent, setGlobalDispatcher } from 'undici';\nimport type { Application, Request, Response, NextFunction } from 'express';\nimport type { Logger } from 'pino';\n\ndiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.WARN);\n\nconst serviceName =\n process.env.OTEL_SERVICE_NAME ||\n process.env.MAIN_MODULE ||\n 'unknown-service';\nconst serviceNamespace =\n process.env.OTEL_NAMESPACE ||\n process.env.OTEL_SERVICE_NAMESPACE ||\n process.env.MAIN_APP ||\n 'app';\nconst environment = process.env.MAIN_ENV || process.env.NODE_ENV || 'development';\nconst moduleName = process.env.MAIN_MODULE || 'unknown-module';\nconst otlpEndpoint = (process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318').replace(/\\/$/, '');\nconst expressLayersEnabled = (process.env.ONELOG_EXPRESS_LAYERS || '').toLowerCase() === 'true';\n\n// Optional proxy support for environments with HTTP(S)_PROXY set\nconst proxyUrl = [process.env.HTTPS_PROXY, process.env.https_proxy, process.env.HTTP_PROXY, process.env.http_proxy]\n .find((v) => v && v.trim().length > 0);\n\nif (proxyUrl) {\n try {\n setGlobalDispatcher(new ProxyAgent(proxyUrl));\n // eslint-disable-next-line no-console\n console.log(`[onelog] Proxy enabled for outbound traffic: ${proxyUrl}`);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error('[onelog] Failed to configure proxy agent:', (err as Error).message);\n }\n}\n\nconst resource = Resource.default().merge(\n new Resource({\n 'service.name': serviceName,\n 'service.namespace': serviceNamespace,\n 'deployment.environment': environment,\n 'module.name': moduleName,\n }),\n);\n\nconst instrumentations = getNodeAutoInstrumentations({\n '@opentelemetry/instrumentation-http': {\n enabled: true,\n },\n '@opentelemetry/instrumentation-express': {\n enabled: true,\n ignoreLayersType: expressLayersEnabled ? [] : (['middleware', 'request_handler'] as any),\n },\n '@opentelemetry/instrumentation-undici': {\n enabled: true,\n },\n // Redis instrumentation is noisy in our workloads; keep it off by default\n '@opentelemetry/instrumentation-ioredis': { enabled: false },\n '@opentelemetry/instrumentation-redis': { enabled: false },\n '@opentelemetry/instrumentation-fs': { enabled: false },\n '@opentelemetry/instrumentation-dns': { enabled: false },\n '@opentelemetry/instrumentation-net': { enabled: false },\n});\n\nconst sdk = new NodeSDK({\n traceExporter: new OTLPTraceExporter({\n url: `${otlpEndpoint}/v1/traces`,\n }),\n resource,\n instrumentations: [instrumentations],\n});\n\nexport const sdkStartPromise = Promise.resolve(sdk.start()).catch((error) => {\n console.error('Failed to start OpenTelemetry SDK', error);\n return Promise.resolve();\n});\n\nconst shutdown = async () => {\n try {\n await sdk.shutdown();\n } catch (error) {\n console.error('Error shutting down OpenTelemetry SDK', error);\n }\n};\n\nprocess.on('SIGTERM', shutdown);\nprocess.on('SIGINT', shutdown);\n\nexport const instrumentApp = (app: Application, logger?: Logger, customModuleName?: string) => {\n const moduleLabel = customModuleName || process.env.MAIN_MODULE || moduleName;\n app.use((req: Request, _res: Response, next: NextFunction) => {\n const span = trace.getActiveSpan();\n if (span) {\n span.setAttribute('module.name', moduleLabel);\n span.updateName(`[${moduleLabel}] ${req.method} ${req.path}`);\n }\n if (logger) {\n logger.info(\n {\n method: req.method,\n path: req.path,\n ip: req.ip,\n },\n 'Incoming request',\n );\n }\n next();\n });\n};\n","import pino from 'pino';\n\nexport function createLogger() {\n const mainEnv = process.env.MAIN_ENV || 'development';\n const mainApp = process.env.MAIN_APP || 'app';\n const mainModule = process.env.MAIN_MODULE || 'unknown-module';\n\n const logger = pino({\n transport: {\n targets: [\n {\n target: 'pino-opentelemetry-transport',\n level: 'info',\n options: {\n resourceAttributes: {\n 'service.name': mainApp,\n 'service.namespace': mainEnv,\n 'deployment.environment': mainEnv,\n 'module.name': mainModule,\n 'host.name': require('os').hostname(),\n },\n },\n },\n {\n target: 'pino-pretty',\n level: 'debug',\n options: {\n colorize: true,\n translateTime: 'HH:MM:ss Z',\n ignore: 'pid,hostname',\n },\n },\n ],\n },\n });\n\n return logger.child({\n env: mainEnv,\n app: mainApp,\n module: mainModule,\n });\n}\n","import { trace, SpanStatusCode } from '@opentelemetry/api';\nimport type { Request, Response, NextFunction } from 'express';\nimport type { Logger } from 'pino';\n\nexport const errorMiddleware =\n (logger?: Logger) =>\n (err: Error, req: Request, res: Response, next: NextFunction) => {\n if (logger) {\n logger.error(\n {\n error: err.message,\n stack: err.stack,\n path: req.path,\n },\n 'Unhandled error',\n );\n }\n\n const span = trace.getActiveSpan();\n if (span) {\n span.recordException(err);\n span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });\n }\n\n if (res.headersSent) {\n return next(err);\n }\n\n res.status(500).json({\n error: err.message,\n module: process.env.MAIN_MODULE || 'unknown-module',\n });\n };\n","export interface HttpCallContext {\n [key: string]: any;\n}\n\nexport interface HttpCallOptions extends RequestInit {\n body?: any;\n}\n\nexport async function httpCall(\n url: string,\n options: HttpCallOptions = {},\n logger?: { info: Function; error: Function },\n logContext: HttpCallContext = {},\n) {\n const fetchOptions: RequestInit = { ...options };\n const method = (fetchOptions.method || 'GET').toString().toUpperCase();\n\n if (\n fetchOptions.body &&\n typeof fetchOptions.body !== 'string' &&\n !(fetchOptions.body instanceof Buffer) &&\n !(fetchOptions.body instanceof ArrayBuffer)\n ) {\n fetchOptions.body = JSON.stringify(fetchOptions.body);\n fetchOptions.headers = {\n 'Content-Type': 'application/json',\n ...(fetchOptions.headers || {}),\n };\n }\n\n if (logger) {\n logger.info({ ...logContext, url, method }, 'HTTP call start');\n }\n\n try {\n const res = await fetch(url, fetchOptions);\n const contentType = res.headers.get('content-type') || '';\n const isJson = contentType.includes('application/json');\n const data = isJson ? await res.json().catch(() => null) : await res.text().catch(() => null);\n\n if (!res.ok) {\n const error = new Error(`HTTP ${res.status} ${res.statusText || ''}`.trim());\n (error as any).status = res.status;\n (error as any).data = data;\n if (logger) {\n logger.error({ ...logContext, url, method, status: res.status, data }, 'HTTP call failed');\n }\n throw error;\n }\n\n if (logger) {\n logger.info({ ...logContext, url, method, status: res.status }, 'HTTP call success');\n }\n\n return data;\n } catch (err: any) {\n if (logger) {\n logger.error({ ...logContext, url, method, error: err.message }, 'HTTP call error');\n }\n throw err;\n }\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,oBAAAC,EAAA,aAAAC,EAAA,kBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAP,GCAA,IAAAQ,EAA6D,8BAC7DC,EAAwB,mCACxBC,EAAyB,oCACzBC,EAAkC,mDAClCC,EAA4C,qDAC5CC,EAAgD,kBAIhD,OAAK,UAAU,IAAI,oBAAqB,eAAa,IAAI,EAEzD,IAAMC,EACJ,QAAQ,IAAI,mBACZ,QAAQ,IAAI,aACZ,kBACIC,EACJ,QAAQ,IAAI,gBACZ,QAAQ,IAAI,wBACZ,QAAQ,IAAI,UACZ,MACIC,EAAc,QAAQ,IAAI,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F,EAAI,OAC3BE,EAAc,KAAOD,EAClBL,GACFA,EAAO,MAAM,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,OAAQC,EAAI,OAAQ,KAAAC,CAAK,EAAG,kBAAkB,EAErFC,CACR,CAEA,OAAIN,GACFA,EAAO,KAAK,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,OAAQC,EAAI,MAAO,EAAG,mBAAmB,EAG9EC,CACT,OAASE,EAAU,CACjB,MAAIP,GACFA,EAAO,MAAM,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,MAAOI,EAAI,OAAQ,EAAG,iBAAiB,EAE9EA,CACR,CACF","names":["index_exports","__export","createLogger","errorMiddleware","httpCall","instrumentApp","sdkStartPromise","__toCommonJS","import_api","import_sdk_node","import_resources","import_exporter_trace_otlp_http","import_auto_instrumentations_node","import_undici","serviceName","serviceNamespace","environment","moduleName","otlpEndpoint","expressLayersEnabled","proxyUrl","v","err","resource","instrumentations","sdk","sdkStartPromise","error","shutdown","instrumentApp","app","logger","customModuleName","moduleLabel","req","_res","next","span","import_pino","createLogger","mainEnv","mainApp","mainModule","pino","import_api","errorMiddleware","logger","err","req","res","next","span","httpCall","url","options","logger","logContext","fetchOptions","method","res","data","error","err"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/tracing.ts","../src/logger.ts","../src/exceptions.ts","../src/http-caller.ts"],"sourcesContent":["export { sdkStartPromise, instrumentApp } from './tracing.js';\nexport { createLogger } from './logger.js';\nexport { errorMiddleware } from './exceptions.js';\nexport { httpCall } from './http-caller.js';\n","import { diag, DiagConsoleLogger, DiagLogLevel, trace, Span } from '@opentelemetry/api';\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport { SpanProcessor, ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport { Resource } from '@opentelemetry/resources';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport { ProxyAgent, setGlobalDispatcher } from 'undici';\nimport type { Application, Request, Response, NextFunction } from 'express';\nimport type { Logger } from 'pino';\n\ndiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.WARN);\n\nconst serviceName =\n process.env.OTEL_SERVICE_NAME ||\n process.env.MAIN_MODULE ||\n 'unknown-service';\nconst serviceNamespace =\n process.env.OTEL_NAMESPACE ||\n process.env.OTEL_SERVICE_NAMESPACE ||\n process.env.MAIN_APP ||\n 'app';\nconst environment = process.env.MAIN_ENV || process.env.NODE_ENV || 'development';\nconst moduleName = process.env.MAIN_MODULE || 'unknown-module';\nconst otlpEndpoint = (process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318').replace(/\\/$/, '');\nconst expressLayersEnabled = (process.env.ONELOG_EXPRESS_LAYERS || '').toLowerCase() === 'true';\nconst moduleLabel = process.env.MAIN_MODULE || moduleName;\n\n// Optional proxy support for environments with HTTP(S)_PROXY set\nconst proxyUrl = [process.env.HTTPS_PROXY, process.env.https_proxy, process.env.HTTP_PROXY, process.env.http_proxy]\n .find((v) => v && v.trim().length > 0);\n\nif (proxyUrl) {\n try {\n setGlobalDispatcher(new ProxyAgent(proxyUrl));\n // eslint-disable-next-line no-console\n console.log(`[onelog] Proxy enabled for outbound traffic: ${proxyUrl}`);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error('[onelog] Failed to configure proxy agent:', (err as Error).message);\n }\n}\n\nconst resource = Resource.default().merge(\n new Resource({\n 'service.name': serviceName,\n 'service.namespace': serviceNamespace,\n 'deployment.environment': environment,\n 'module.name': moduleLabel,\n }),\n);\n\nclass ModuleNameSpanProcessor implements SpanProcessor {\n constructor(private readonly moduleName: string) {}\n onStart(span: Span): void {\n if (!span) return;\n const currentName = (span as any).name || (span as any)._name || '';\n if (this.moduleName && !currentName.startsWith(`[${this.moduleName}] `)) {\n span.updateName(`[${this.moduleName}] ${currentName}`);\n }\n if (this.moduleName) {\n span.setAttribute('module.name', this.moduleName);\n }\n }\n onEnd(_span: ReadableSpan): void {\n // no-op\n }\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n\nconst instrumentations = getNodeAutoInstrumentations({\n '@opentelemetry/instrumentation-http': {\n enabled: true,\n },\n '@opentelemetry/instrumentation-express': {\n enabled: true,\n ignoreLayersType: expressLayersEnabled ? [] : (['middleware', 'request_handler'] as any),\n },\n '@opentelemetry/instrumentation-undici': {\n enabled: true,\n },\n // Redis instrumentation is noisy in our workloads; keep it off by default\n '@opentelemetry/instrumentation-ioredis': { enabled: false },\n '@opentelemetry/instrumentation-redis': { enabled: false },\n '@opentelemetry/instrumentation-fs': { enabled: false },\n '@opentelemetry/instrumentation-dns': { enabled: false },\n '@opentelemetry/instrumentation-net': { enabled: false },\n});\n\nconst sdk = new NodeSDK({\n traceExporter: new OTLPTraceExporter({\n url: `${otlpEndpoint}/v1/traces`,\n }),\n resource,\n instrumentations: [instrumentations],\n spanProcessor: new ModuleNameSpanProcessor(moduleLabel),\n});\n\nexport const sdkStartPromise = Promise.resolve(sdk.start()).catch((error) => {\n console.error('Failed to start OpenTelemetry SDK', error);\n return Promise.resolve();\n});\n\nconst shutdown = async () => {\n try {\n await sdk.shutdown();\n } catch (error) {\n console.error('Error shutting down OpenTelemetry SDK', error);\n }\n};\n\nprocess.on('SIGTERM', shutdown);\nprocess.on('SIGINT', shutdown);\n\nexport const instrumentApp = (app: Application, logger?: Logger, customModuleName?: string) => {\n const moduleLabel = customModuleName || process.env.MAIN_MODULE || moduleName;\n app.use((req: Request, _res: Response, next: NextFunction) => {\n const span = trace.getActiveSpan();\n if (span) {\n span.setAttribute('module.name', moduleLabel);\n span.updateName(`[${moduleLabel}] ${req.method} ${req.path}`);\n }\n if (logger) {\n logger.info(\n {\n method: req.method,\n path: req.path,\n ip: req.ip,\n },\n 'Incoming request',\n );\n }\n next();\n });\n};\n","import pino from 'pino';\n\nexport function createLogger() {\n const mainEnv = process.env.MAIN_ENV || 'development';\n const mainApp = process.env.MAIN_APP || 'app';\n const mainModule = process.env.MAIN_MODULE || 'unknown-module';\n\n const logger = pino({\n transport: {\n targets: [\n {\n target: 'pino-opentelemetry-transport',\n level: 'info',\n options: {\n resourceAttributes: {\n 'service.name': mainApp,\n 'service.namespace': mainEnv,\n 'deployment.environment': mainEnv,\n 'module.name': mainModule,\n 'host.name': require('os').hostname(),\n },\n },\n },\n {\n target: 'pino-pretty',\n level: 'debug',\n options: {\n colorize: true,\n translateTime: 'HH:MM:ss Z',\n ignore: 'pid,hostname',\n },\n },\n ],\n },\n });\n\n return logger.child({\n env: mainEnv,\n app: mainApp,\n module: mainModule,\n });\n}\n","import { trace, SpanStatusCode } from '@opentelemetry/api';\nimport type { Request, Response, NextFunction } from 'express';\nimport type { Logger } from 'pino';\n\nexport const errorMiddleware =\n (logger?: Logger) =>\n (err: Error, req: Request, res: Response, next: NextFunction) => {\n if (logger) {\n logger.error(\n {\n error: err.message,\n stack: err.stack,\n path: req.path,\n },\n 'Unhandled error',\n );\n }\n\n const span = trace.getActiveSpan();\n if (span) {\n span.recordException(err);\n span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });\n }\n\n if (res.headersSent) {\n return next(err);\n }\n\n res.status(500).json({\n error: err.message,\n module: process.env.MAIN_MODULE || 'unknown-module',\n });\n };\n","export interface HttpCallContext {\n [key: string]: any;\n}\n\nexport interface HttpCallOptions extends RequestInit {\n body?: any;\n}\n\nexport async function httpCall(\n url: string,\n options: HttpCallOptions = {},\n logger?: { info: Function; error: Function },\n logContext: HttpCallContext = {},\n) {\n const fetchOptions: RequestInit = { ...options };\n const method = (fetchOptions.method || 'GET').toString().toUpperCase();\n\n if (\n fetchOptions.body &&\n typeof fetchOptions.body !== 'string' &&\n !(fetchOptions.body instanceof Buffer) &&\n !(fetchOptions.body instanceof ArrayBuffer)\n ) {\n fetchOptions.body = JSON.stringify(fetchOptions.body);\n fetchOptions.headers = {\n 'Content-Type': 'application/json',\n ...(fetchOptions.headers || {}),\n };\n }\n\n if (logger) {\n logger.info({ ...logContext, url, method }, 'HTTP call start');\n }\n\n try {\n const res = await fetch(url, fetchOptions);\n const contentType = res.headers.get('content-type') || '';\n const isJson = contentType.includes('application/json');\n const data = isJson ? await res.json().catch(() => null) : await res.text().catch(() => null);\n\n if (!res.ok) {\n const error = new Error(`HTTP ${res.status} ${res.statusText || ''}`.trim());\n (error as any).status = res.status;\n (error as any).data = data;\n if (logger) {\n logger.error({ ...logContext, url, method, status: res.status, data }, 'HTTP call failed');\n }\n throw error;\n }\n\n if (logger) {\n logger.info({ ...logContext, url, method, status: res.status }, 'HTTP call success');\n }\n\n return data;\n } catch (err: any) {\n if (logger) {\n logger.error({ ...logContext, url, method, error: err.message }, 'HTTP call error');\n }\n throw err;\n }\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,oBAAAC,EAAA,aAAAC,EAAA,kBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAP,GCAA,IAAAQ,EAAmE,8BACnEC,EAAwB,mCAExBC,EAAyB,oCACzBC,EAAkC,mDAClCC,EAA4C,qDAC5CC,EAAgD,kBAIhD,OAAK,UAAU,IAAI,oBAAqB,eAAa,IAAI,EAEzD,IAAMC,EACJ,QAAQ,IAAI,mBACZ,QAAQ,IAAI,aACZ,kBACIC,EACJ,QAAQ,IAAI,gBACZ,QAAQ,IAAI,wBACZ,QAAQ,IAAI,UACZ,MACIC,EAAc,QAAQ,IAAI,UAAY,QAAQ,IAAI,UAAY,cAC9DC,EAAa,QAAQ,IAAI,aAAe,iBACxCC,GAAgB,QAAQ,IAAI,6BAA+B,yBAAyB,QAAQ,MAAO,EAAE,EACrGC,GAAwB,QAAQ,IAAI,uBAAyB,IAAI,YAAY,IAAM,OACnFC,EAAc,QAAQ,IAAI,aAAeH,EAGzCI,EAAW,CAAC,QAAQ,IAAI,YAAa,QAAQ,IAAI,YAAa,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B,EAChC,MAAMA,EAAI,KAAK,EAAE,MAAM,IAAM,IAAI,EAAI,MAAMA,EAAI,KAAK,EAAE,MAAM,IAAM,IAAI,EAE5F,GAAI,CAACA,EAAI,GAAI,CACX,IAAME,EAAQ,IAAI,MAAM,QAAQF,EAAI,MAAM,IAAIA,EAAI,YAAc,EAAE,GAAG,KAAK,CAAC,EAC3E,MAACE,EAAc,OAASF,EAAI,OAC3BE,EAAc,KAAOD,EAClBL,GACFA,EAAO,MAAM,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,OAAQC,EAAI,OAAQ,KAAAC,CAAK,EAAG,kBAAkB,EAErFC,CACR,CAEA,OAAIN,GACFA,EAAO,KAAK,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,OAAQC,EAAI,MAAO,EAAG,mBAAmB,EAG9EC,CACT,OAASE,EAAU,CACjB,MAAIP,GACFA,EAAO,MAAM,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,MAAOI,EAAI,OAAQ,EAAG,iBAAiB,EAE9EA,CACR,CACF","names":["index_exports","__export","createLogger","errorMiddleware","httpCall","instrumentApp","sdkStartPromise","__toCommonJS","import_api","import_sdk_node","import_resources","import_exporter_trace_otlp_http","import_auto_instrumentations_node","import_undici","serviceName","serviceNamespace","environment","moduleName","otlpEndpoint","expressLayersEnabled","moduleLabel","proxyUrl","v","err","resource","ModuleNameSpanProcessor","span","currentName","_span","instrumentations","sdk","sdkStartPromise","error","shutdown","instrumentApp","app","logger","customModuleName","req","_res","next","import_pino","createLogger","mainEnv","mainApp","mainModule","pino","import_api","errorMiddleware","logger","err","req","res","next","span","httpCall","url","options","logger","logContext","fetchOptions","method","res","data","error","err"]}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var y=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(n,o)=>(typeof require<"u"?require:n)[o]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import{diag as h,DiagConsoleLogger as E,DiagLogLevel as v,trace as g}from"@opentelemetry/api";import{NodeSDK as T}from"@opentelemetry/sdk-node";import{Resource as l}from"@opentelemetry/resources";import{OTLPTraceExporter as N}from"@opentelemetry/exporter-trace-otlp-http";import{getNodeAutoInstrumentations as x}from"@opentelemetry/auto-instrumentations-node";import{ProxyAgent as A,setGlobalDispatcher as L}from"undici";h.setLogger(new E,v.WARN);var P=process.env.OTEL_SERVICE_NAME||process.env.MAIN_MODULE||"unknown-service",_=process.env.OTEL_NAMESPACE||process.env.OTEL_SERVICE_NAMESPACE||process.env.MAIN_APP||"app",O=process.env.MAIN_ENV||process.env.NODE_ENV||"development",u=process.env.MAIN_MODULE||"unknown-module",R=(process.env.OTEL_EXPORTER_OTLP_ENDPOINT||"http://localhost:4318").replace(/\/$/,""),b=(process.env.ONELOG_EXPRESS_LAYERS||"").toLowerCase()==="true",m=[process.env.HTTPS_PROXY,process.env.https_proxy,process.env.HTTP_PROXY,process.env.http_proxy].find(e=>e&&e.trim().length>0);if(m)try{L(new A(m)),console.log(`[onelog] Proxy enabled for outbound traffic: ${m}`)}catch(e){console.error("[onelog] Failed to configure proxy agent:",e.message)}var w=l.default().merge(new l({"service.name":P,"service.namespace":_,"deployment.environment":O,"module.name":u})),M=x({"@opentelemetry/instrumentation-http":{enabled:!0},"@opentelemetry/instrumentation-express":{enabled:!0,ignoreLayersType:b?[]:["middleware","request_handler"]},"@opentelemetry/instrumentation-undici":{enabled:!0},"@opentelemetry/instrumentation-ioredis":{enabled:!1},"@opentelemetry/instrumentation-redis":{enabled:!1},"@opentelemetry/instrumentation-fs":{enabled:!1},"@opentelemetry/instrumentation-dns":{enabled:!1},"@opentelemetry/instrumentation-net":{enabled:!1}}),d=new T({traceExporter:new N({url:`${R}/v1/traces`}),resource:w,instrumentations:[M]}),S=Promise.resolve(d.start()).catch(e=>(console.error("Failed to start OpenTelemetry SDK",e),Promise.resolve())),f=async()=>{try{await d.shutdown()}catch(e){console.error("Error shutting down OpenTelemetry SDK",e)}};process.on("SIGTERM",f);process.on("SIGINT",f);var I=(e,n,o)=>{let s=o||process.env.MAIN_MODULE||u;e.use((t,a,r)=>{let i=g.getActiveSpan();i&&(i.setAttribute("module.name",s),i.updateName(`[${s}] ${t.method} ${t.path}`)),n&&n.info({method:t.method,path:t.path,ip:t.ip},"Incoming request"),r()})};import C from"pino";function D(){let e=process.env.MAIN_ENV||"development",n=process.env.MAIN_APP||"app",o=process.env.MAIN_MODULE||"unknown-module";return C({transport:{targets:[{target:"pino-opentelemetry-transport",level:"info",options:{resourceAttributes:{"service.name":n,"service.namespace":e,"deployment.environment":e,"module.name":o,"host.name":y("os").hostname()}}},{target:"pino-pretty",level:"debug",options:{colorize:!0,translateTime:"HH:MM:ss Z",ignore:"pid,hostname"}}]}}).child({env:e,app:n,module:o})}import{trace as H,SpanStatusCode as k}from"@opentelemetry/api";var F=e=>(n,o,s,t)=>{e&&e.error({error:n.message,stack:n.stack,path:o.path},"Unhandled error");let a=H.getActiveSpan();if(a&&(a.recordException(n),a.setStatus({code:k.ERROR,message:n.message})),s.headersSent)return t(n);s.status(500).json({error:n.message,module:process.env.MAIN_MODULE||"unknown-module"})};async function U(e,n={},o,s={}){let t={...n},a=(t.method||"GET").toString().toUpperCase();t.body&&typeof t.body!="string"&&!(t.body instanceof Buffer)&&!(t.body instanceof ArrayBuffer)&&(t.body=JSON.stringify(t.body),t.headers={"Content-Type":"application/json",...t.headers||{}}),o&&o.info({...s,url:e,method:a},"HTTP call start");try{let r=await fetch(e,t),p=(r.headers.get("content-type")||"").includes("application/json")?await r.json().catch(()=>null):await r.text().catch(()=>null);if(!r.ok){let c=new Error(`HTTP ${r.status} ${r.statusText||""}`.trim());throw c.status=r.status,c.data=p,o&&o.error({...s,url:e,method:a,status:r.status,data:p},"HTTP call failed"),c}return o&&o.info({...s,url:e,method:a,status:r.status},"HTTP call success"),p}catch(r){throw o&&o.error({...s,url:e,method:a,error:r.message},"HTTP call error"),r}}export{D as createLogger,F as errorMiddleware,U as httpCall,I as instrumentApp,S as sdkStartPromise};
1
+ var v=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,o)=>(typeof require<"u"?require:t)[o]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import{diag as E,DiagConsoleLogger as N,DiagLogLevel as g,trace as T}from"@opentelemetry/api";import{NodeSDK as A}from"@opentelemetry/sdk-node";import{Resource as u}from"@opentelemetry/resources";import{OTLPTraceExporter as P}from"@opentelemetry/exporter-trace-otlp-http";import{getNodeAutoInstrumentations as x}from"@opentelemetry/auto-instrumentations-node";import{ProxyAgent as L,setGlobalDispatcher as S}from"undici";E.setLogger(new N,g.WARN);var _=process.env.OTEL_SERVICE_NAME||process.env.MAIN_MODULE||"unknown-service",b=process.env.OTEL_NAMESPACE||process.env.OTEL_SERVICE_NAMESPACE||process.env.MAIN_APP||"app",O=process.env.MAIN_ENV||process.env.NODE_ENV||"development",d=process.env.MAIN_MODULE||"unknown-module",R=(process.env.OTEL_EXPORTER_OTLP_ENDPOINT||"http://localhost:4318").replace(/\/$/,""),w=(process.env.ONELOG_EXPRESS_LAYERS||"").toLowerCase()==="true",f=process.env.MAIN_MODULE||d,m=[process.env.HTTPS_PROXY,process.env.https_proxy,process.env.HTTP_PROXY,process.env.http_proxy].find(e=>e&&e.trim().length>0);if(m)try{S(new L(m)),console.log(`[onelog] Proxy enabled for outbound traffic: ${m}`)}catch(e){console.error("[onelog] Failed to configure proxy agent:",e.message)}var M=u.default().merge(new u({"service.name":_,"service.namespace":b,"deployment.environment":O,"module.name":f})),l=class{constructor(t){this.moduleName=t}onStart(t){if(!t)return;let o=t.name||t._name||"";this.moduleName&&!o.startsWith(`[${this.moduleName}] `)&&t.updateName(`[${this.moduleName}] ${o}`),this.moduleName&&t.setAttribute("module.name",this.moduleName)}onEnd(t){}shutdown(){return Promise.resolve()}forceFlush(){return Promise.resolve()}},I=x({"@opentelemetry/instrumentation-http":{enabled:!0},"@opentelemetry/instrumentation-express":{enabled:!0,ignoreLayersType:w?[]:["middleware","request_handler"]},"@opentelemetry/instrumentation-undici":{enabled:!0},"@opentelemetry/instrumentation-ioredis":{enabled:!1},"@opentelemetry/instrumentation-redis":{enabled:!1},"@opentelemetry/instrumentation-fs":{enabled:!1},"@opentelemetry/instrumentation-dns":{enabled:!1},"@opentelemetry/instrumentation-net":{enabled:!1}}),y=new A({traceExporter:new P({url:`${R}/v1/traces`}),resource:M,instrumentations:[I],spanProcessor:new l(f)}),C=Promise.resolve(y.start()).catch(e=>(console.error("Failed to start OpenTelemetry SDK",e),Promise.resolve())),h=async()=>{try{await y.shutdown()}catch(e){console.error("Error shutting down OpenTelemetry SDK",e)}};process.on("SIGTERM",h);process.on("SIGINT",h);var D=(e,t,o)=>{let s=o||process.env.MAIN_MODULE||d;e.use((n,a,r)=>{let i=T.getActiveSpan();i&&(i.setAttribute("module.name",s),i.updateName(`[${s}] ${n.method} ${n.path}`)),t&&t.info({method:n.method,path:n.path,ip:n.ip},"Incoming request"),r()})};import H from"pino";function k(){let e=process.env.MAIN_ENV||"development",t=process.env.MAIN_APP||"app",o=process.env.MAIN_MODULE||"unknown-module";return H({transport:{targets:[{target:"pino-opentelemetry-transport",level:"info",options:{resourceAttributes:{"service.name":t,"service.namespace":e,"deployment.environment":e,"module.name":o,"host.name":v("os").hostname()}}},{target:"pino-pretty",level:"debug",options:{colorize:!0,translateTime:"HH:MM:ss Z",ignore:"pid,hostname"}}]}}).child({env:e,app:t,module:o})}import{trace as $,SpanStatusCode as F}from"@opentelemetry/api";var U=e=>(t,o,s,n)=>{e&&e.error({error:t.message,stack:t.stack,path:o.path},"Unhandled error");let a=$.getActiveSpan();if(a&&(a.recordException(t),a.setStatus({code:F.ERROR,message:t.message})),s.headersSent)return n(t);s.status(500).json({error:t.message,module:process.env.MAIN_MODULE||"unknown-module"})};async function q(e,t={},o,s={}){let n={...t},a=(n.method||"GET").toString().toUpperCase();n.body&&typeof n.body!="string"&&!(n.body instanceof Buffer)&&!(n.body instanceof ArrayBuffer)&&(n.body=JSON.stringify(n.body),n.headers={"Content-Type":"application/json",...n.headers||{}}),o&&o.info({...s,url:e,method:a},"HTTP call start");try{let r=await fetch(e,n),p=(r.headers.get("content-type")||"").includes("application/json")?await r.json().catch(()=>null):await r.text().catch(()=>null);if(!r.ok){let c=new Error(`HTTP ${r.status} ${r.statusText||""}`.trim());throw c.status=r.status,c.data=p,o&&o.error({...s,url:e,method:a,status:r.status,data:p},"HTTP call failed"),c}return o&&o.info({...s,url:e,method:a,status:r.status},"HTTP call success"),p}catch(r){throw o&&o.error({...s,url:e,method:a,error:r.message},"HTTP call error"),r}}export{k as createLogger,U as errorMiddleware,q as httpCall,D as instrumentApp,C as sdkStartPromise};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tracing.ts","../src/logger.ts","../src/exceptions.ts","../src/http-caller.ts"],"sourcesContent":["import { diag, DiagConsoleLogger, DiagLogLevel, trace } from '@opentelemetry/api';\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport { Resource } from '@opentelemetry/resources';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport { ProxyAgent, setGlobalDispatcher } from 'undici';\nimport type { Application, Request, Response, NextFunction } from 'express';\nimport type { Logger } from 'pino';\n\ndiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.WARN);\n\nconst serviceName =\n process.env.OTEL_SERVICE_NAME ||\n process.env.MAIN_MODULE ||\n 'unknown-service';\nconst serviceNamespace =\n process.env.OTEL_NAMESPACE ||\n process.env.OTEL_SERVICE_NAMESPACE ||\n process.env.MAIN_APP ||\n 'app';\nconst environment = process.env.MAIN_ENV || process.env.NODE_ENV || 'development';\nconst moduleName = process.env.MAIN_MODULE || 'unknown-module';\nconst otlpEndpoint = (process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318').replace(/\\/$/, '');\nconst expressLayersEnabled = (process.env.ONELOG_EXPRESS_LAYERS || '').toLowerCase() === 'true';\n\n// Optional proxy support for environments with HTTP(S)_PROXY set\nconst proxyUrl = [process.env.HTTPS_PROXY, process.env.https_proxy, process.env.HTTP_PROXY, process.env.http_proxy]\n .find((v) => v && v.trim().length > 0);\n\nif (proxyUrl) {\n try {\n setGlobalDispatcher(new ProxyAgent(proxyUrl));\n // eslint-disable-next-line no-console\n console.log(`[onelog] Proxy enabled for outbound traffic: ${proxyUrl}`);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error('[onelog] Failed to configure proxy agent:', (err as Error).message);\n }\n}\n\nconst resource = Resource.default().merge(\n new Resource({\n 'service.name': serviceName,\n 'service.namespace': serviceNamespace,\n 'deployment.environment': environment,\n 'module.name': moduleName,\n }),\n);\n\nconst instrumentations = getNodeAutoInstrumentations({\n '@opentelemetry/instrumentation-http': {\n enabled: true,\n },\n '@opentelemetry/instrumentation-express': {\n enabled: true,\n ignoreLayersType: expressLayersEnabled ? [] : (['middleware', 'request_handler'] as any),\n },\n '@opentelemetry/instrumentation-undici': {\n enabled: true,\n },\n // Redis instrumentation is noisy in our workloads; keep it off by default\n '@opentelemetry/instrumentation-ioredis': { enabled: false },\n '@opentelemetry/instrumentation-redis': { enabled: false },\n '@opentelemetry/instrumentation-fs': { enabled: false },\n '@opentelemetry/instrumentation-dns': { enabled: false },\n '@opentelemetry/instrumentation-net': { enabled: false },\n});\n\nconst sdk = new NodeSDK({\n traceExporter: new OTLPTraceExporter({\n url: `${otlpEndpoint}/v1/traces`,\n }),\n resource,\n instrumentations: [instrumentations],\n});\n\nexport const sdkStartPromise = Promise.resolve(sdk.start()).catch((error) => {\n console.error('Failed to start OpenTelemetry SDK', error);\n return Promise.resolve();\n});\n\nconst shutdown = async () => {\n try {\n await sdk.shutdown();\n } catch (error) {\n console.error('Error shutting down OpenTelemetry SDK', error);\n }\n};\n\nprocess.on('SIGTERM', shutdown);\nprocess.on('SIGINT', shutdown);\n\nexport const instrumentApp = (app: Application, logger?: Logger, customModuleName?: string) => {\n const moduleLabel = customModuleName || process.env.MAIN_MODULE || moduleName;\n app.use((req: Request, _res: Response, next: NextFunction) => {\n const span = trace.getActiveSpan();\n if (span) {\n span.setAttribute('module.name', moduleLabel);\n span.updateName(`[${moduleLabel}] ${req.method} ${req.path}`);\n }\n if (logger) {\n logger.info(\n {\n method: req.method,\n path: req.path,\n ip: req.ip,\n },\n 'Incoming request',\n );\n }\n next();\n });\n};\n","import pino from 'pino';\n\nexport function createLogger() {\n const mainEnv = process.env.MAIN_ENV || 'development';\n const mainApp = process.env.MAIN_APP || 'app';\n const mainModule = process.env.MAIN_MODULE || 'unknown-module';\n\n const logger = pino({\n transport: {\n targets: [\n {\n target: 'pino-opentelemetry-transport',\n level: 'info',\n options: {\n resourceAttributes: {\n 'service.name': mainApp,\n 'service.namespace': mainEnv,\n 'deployment.environment': mainEnv,\n 'module.name': mainModule,\n 'host.name': require('os').hostname(),\n },\n },\n },\n {\n target: 'pino-pretty',\n level: 'debug',\n options: {\n colorize: true,\n translateTime: 'HH:MM:ss Z',\n ignore: 'pid,hostname',\n },\n },\n ],\n },\n });\n\n return logger.child({\n env: mainEnv,\n app: mainApp,\n module: mainModule,\n });\n}\n","import { trace, SpanStatusCode } from '@opentelemetry/api';\nimport type { Request, Response, NextFunction } from 'express';\nimport type { Logger } from 'pino';\n\nexport const errorMiddleware =\n (logger?: Logger) =>\n (err: Error, req: Request, res: Response, next: NextFunction) => {\n if (logger) {\n logger.error(\n {\n error: err.message,\n stack: err.stack,\n path: req.path,\n },\n 'Unhandled error',\n );\n }\n\n const span = trace.getActiveSpan();\n if (span) {\n span.recordException(err);\n span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });\n }\n\n if (res.headersSent) {\n return next(err);\n }\n\n res.status(500).json({\n error: err.message,\n module: process.env.MAIN_MODULE || 'unknown-module',\n });\n };\n","export interface HttpCallContext {\n [key: string]: any;\n}\n\nexport interface HttpCallOptions extends RequestInit {\n body?: any;\n}\n\nexport async function httpCall(\n url: string,\n options: HttpCallOptions = {},\n logger?: { info: Function; error: Function },\n logContext: HttpCallContext = {},\n) {\n const fetchOptions: RequestInit = { ...options };\n const method = (fetchOptions.method || 'GET').toString().toUpperCase();\n\n if (\n fetchOptions.body &&\n typeof fetchOptions.body !== 'string' &&\n !(fetchOptions.body instanceof Buffer) &&\n !(fetchOptions.body instanceof ArrayBuffer)\n ) {\n fetchOptions.body = JSON.stringify(fetchOptions.body);\n fetchOptions.headers = {\n 'Content-Type': 'application/json',\n ...(fetchOptions.headers || {}),\n };\n }\n\n if (logger) {\n logger.info({ ...logContext, url, method }, 'HTTP call start');\n }\n\n try {\n const res = await fetch(url, fetchOptions);\n const contentType = res.headers.get('content-type') || '';\n const isJson = contentType.includes('application/json');\n const data = isJson ? await res.json().catch(() => null) : await res.text().catch(() => null);\n\n if (!res.ok) {\n const error = new Error(`HTTP ${res.status} ${res.statusText || ''}`.trim());\n (error as any).status = res.status;\n (error as any).data = data;\n if (logger) {\n logger.error({ ...logContext, url, method, status: res.status, data }, 'HTTP call failed');\n }\n throw error;\n }\n\n if (logger) {\n logger.info({ ...logContext, url, method, status: res.status }, 'HTTP call success');\n }\n\n return data;\n } catch (err: any) {\n if (logger) {\n logger.error({ ...logContext, url, method, error: err.message }, 'HTTP call error');\n }\n throw err;\n }\n}\n"],"mappings":"yPAAA,OAAS,QAAAA,EAAM,qBAAAC,EAAmB,gBAAAC,EAAc,SAAAC,MAAa,qBAC7D,OAAS,WAAAC,MAAe,0BACxB,OAAS,YAAAC,MAAgB,2BACzB,OAAS,qBAAAC,MAAyB,0CAClC,OAAS,+BAAAC,MAAmC,4CAC5C,OAAS,cAAAC,EAAY,uBAAAC,MAA2B,SAIhDT,EAAK,UAAU,IAAIC,EAAqBC,EAAa,IAAI,EAEzD,I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,EAAI,KAAK,EAAE,MAAM,IAAM,IAAI,EAE5F,GAAI,CAACA,EAAI,GAAI,CACX,IAAME,EAAQ,IAAI,MAAM,QAAQF,EAAI,MAAM,IAAIA,EAAI,YAAc,EAAE,GAAG,KAAK,CAAC,EAC3E,MAACE,EAAc,OAASF,EAAI,OAC3BE,EAAc,KAAOD,EAClBL,GACFA,EAAO,MAAM,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,OAAQC,EAAI,OAAQ,KAAAC,CAAK,EAAG,kBAAkB,EAErFC,CACR,CAEA,OAAIN,GACFA,EAAO,KAAK,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,OAAQC,EAAI,MAAO,EAAG,mBAAmB,EAG9EC,CACT,OAASE,EAAU,CACjB,MAAIP,GACFA,EAAO,MAAM,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,MAAOI,EAAI,OAAQ,EAAG,iBAAiB,EAE9EA,CACR,CACF","names":["diag","DiagConsoleLogger","DiagLogLevel","trace","NodeSDK","Resource","OTLPTraceExporter","getNodeAutoInstrumentations","ProxyAgent","setGlobalDispatcher","serviceName","serviceNamespace","environment","moduleName","otlpEndpoint","expressLayersEnabled","proxyUrl","v","err","resource","instrumentations","sdk","sdkStartPromise","error","shutdown","instrumentApp","app","logger","customModuleName","moduleLabel","req","_res","next","span","pino","createLogger","mainEnv","mainApp","mainModule","trace","SpanStatusCode","errorMiddleware","logger","err","req","res","next","span","httpCall","url","options","logger","logContext","fetchOptions","method","res","data","error","err"]}
1
+ {"version":3,"sources":["../src/tracing.ts","../src/logger.ts","../src/exceptions.ts","../src/http-caller.ts"],"sourcesContent":["import { diag, DiagConsoleLogger, DiagLogLevel, trace, Span } from '@opentelemetry/api';\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport { SpanProcessor, ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport { Resource } from '@opentelemetry/resources';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport { ProxyAgent, setGlobalDispatcher } from 'undici';\nimport type { Application, Request, Response, NextFunction } from 'express';\nimport type { Logger } from 'pino';\n\ndiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.WARN);\n\nconst serviceName =\n process.env.OTEL_SERVICE_NAME ||\n process.env.MAIN_MODULE ||\n 'unknown-service';\nconst serviceNamespace =\n process.env.OTEL_NAMESPACE ||\n process.env.OTEL_SERVICE_NAMESPACE ||\n process.env.MAIN_APP ||\n 'app';\nconst environment = process.env.MAIN_ENV || process.env.NODE_ENV || 'development';\nconst moduleName = process.env.MAIN_MODULE || 'unknown-module';\nconst otlpEndpoint = (process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318').replace(/\\/$/, '');\nconst expressLayersEnabled = (process.env.ONELOG_EXPRESS_LAYERS || '').toLowerCase() === 'true';\nconst moduleLabel = process.env.MAIN_MODULE || moduleName;\n\n// Optional proxy support for environments with HTTP(S)_PROXY set\nconst proxyUrl = [process.env.HTTPS_PROXY, process.env.https_proxy, process.env.HTTP_PROXY, process.env.http_proxy]\n .find((v) => v && v.trim().length > 0);\n\nif (proxyUrl) {\n try {\n setGlobalDispatcher(new ProxyAgent(proxyUrl));\n // eslint-disable-next-line no-console\n console.log(`[onelog] Proxy enabled for outbound traffic: ${proxyUrl}`);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error('[onelog] Failed to configure proxy agent:', (err as Error).message);\n }\n}\n\nconst resource = Resource.default().merge(\n new Resource({\n 'service.name': serviceName,\n 'service.namespace': serviceNamespace,\n 'deployment.environment': environment,\n 'module.name': moduleLabel,\n }),\n);\n\nclass ModuleNameSpanProcessor implements SpanProcessor {\n constructor(private readonly moduleName: string) {}\n onStart(span: Span): void {\n if (!span) return;\n const currentName = (span as any).name || (span as any)._name || '';\n if (this.moduleName && !currentName.startsWith(`[${this.moduleName}] `)) {\n span.updateName(`[${this.moduleName}] ${currentName}`);\n }\n if (this.moduleName) {\n span.setAttribute('module.name', this.moduleName);\n }\n }\n onEnd(_span: ReadableSpan): void {\n // no-op\n }\n shutdown(): Promise<void> {\n return Promise.resolve();\n }\n forceFlush(): Promise<void> {\n return Promise.resolve();\n }\n}\n\nconst instrumentations = getNodeAutoInstrumentations({\n '@opentelemetry/instrumentation-http': {\n enabled: true,\n },\n '@opentelemetry/instrumentation-express': {\n enabled: true,\n ignoreLayersType: expressLayersEnabled ? [] : (['middleware', 'request_handler'] as any),\n },\n '@opentelemetry/instrumentation-undici': {\n enabled: true,\n },\n // Redis instrumentation is noisy in our workloads; keep it off by default\n '@opentelemetry/instrumentation-ioredis': { enabled: false },\n '@opentelemetry/instrumentation-redis': { enabled: false },\n '@opentelemetry/instrumentation-fs': { enabled: false },\n '@opentelemetry/instrumentation-dns': { enabled: false },\n '@opentelemetry/instrumentation-net': { enabled: false },\n});\n\nconst sdk = new NodeSDK({\n traceExporter: new OTLPTraceExporter({\n url: `${otlpEndpoint}/v1/traces`,\n }),\n resource,\n instrumentations: [instrumentations],\n spanProcessor: new ModuleNameSpanProcessor(moduleLabel),\n});\n\nexport const sdkStartPromise = Promise.resolve(sdk.start()).catch((error) => {\n console.error('Failed to start OpenTelemetry SDK', error);\n return Promise.resolve();\n});\n\nconst shutdown = async () => {\n try {\n await sdk.shutdown();\n } catch (error) {\n console.error('Error shutting down OpenTelemetry SDK', error);\n }\n};\n\nprocess.on('SIGTERM', shutdown);\nprocess.on('SIGINT', shutdown);\n\nexport const instrumentApp = (app: Application, logger?: Logger, customModuleName?: string) => {\n const moduleLabel = customModuleName || process.env.MAIN_MODULE || moduleName;\n app.use((req: Request, _res: Response, next: NextFunction) => {\n const span = trace.getActiveSpan();\n if (span) {\n span.setAttribute('module.name', moduleLabel);\n span.updateName(`[${moduleLabel}] ${req.method} ${req.path}`);\n }\n if (logger) {\n logger.info(\n {\n method: req.method,\n path: req.path,\n ip: req.ip,\n },\n 'Incoming request',\n );\n }\n next();\n });\n};\n","import pino from 'pino';\n\nexport function createLogger() {\n const mainEnv = process.env.MAIN_ENV || 'development';\n const mainApp = process.env.MAIN_APP || 'app';\n const mainModule = process.env.MAIN_MODULE || 'unknown-module';\n\n const logger = pino({\n transport: {\n targets: [\n {\n target: 'pino-opentelemetry-transport',\n level: 'info',\n options: {\n resourceAttributes: {\n 'service.name': mainApp,\n 'service.namespace': mainEnv,\n 'deployment.environment': mainEnv,\n 'module.name': mainModule,\n 'host.name': require('os').hostname(),\n },\n },\n },\n {\n target: 'pino-pretty',\n level: 'debug',\n options: {\n colorize: true,\n translateTime: 'HH:MM:ss Z',\n ignore: 'pid,hostname',\n },\n },\n ],\n },\n });\n\n return logger.child({\n env: mainEnv,\n app: mainApp,\n module: mainModule,\n });\n}\n","import { trace, SpanStatusCode } from '@opentelemetry/api';\nimport type { Request, Response, NextFunction } from 'express';\nimport type { Logger } from 'pino';\n\nexport const errorMiddleware =\n (logger?: Logger) =>\n (err: Error, req: Request, res: Response, next: NextFunction) => {\n if (logger) {\n logger.error(\n {\n error: err.message,\n stack: err.stack,\n path: req.path,\n },\n 'Unhandled error',\n );\n }\n\n const span = trace.getActiveSpan();\n if (span) {\n span.recordException(err);\n span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });\n }\n\n if (res.headersSent) {\n return next(err);\n }\n\n res.status(500).json({\n error: err.message,\n module: process.env.MAIN_MODULE || 'unknown-module',\n });\n };\n","export interface HttpCallContext {\n [key: string]: any;\n}\n\nexport interface HttpCallOptions extends RequestInit {\n body?: any;\n}\n\nexport async function httpCall(\n url: string,\n options: HttpCallOptions = {},\n logger?: { info: Function; error: Function },\n logContext: HttpCallContext = {},\n) {\n const fetchOptions: RequestInit = { ...options };\n const method = (fetchOptions.method || 'GET').toString().toUpperCase();\n\n if (\n fetchOptions.body &&\n typeof fetchOptions.body !== 'string' &&\n !(fetchOptions.body instanceof Buffer) &&\n !(fetchOptions.body instanceof ArrayBuffer)\n ) {\n fetchOptions.body = JSON.stringify(fetchOptions.body);\n fetchOptions.headers = {\n 'Content-Type': 'application/json',\n ...(fetchOptions.headers || {}),\n };\n }\n\n if (logger) {\n logger.info({ ...logContext, url, method }, 'HTTP call start');\n }\n\n try {\n const res = await fetch(url, fetchOptions);\n const contentType = res.headers.get('content-type') || '';\n const isJson = contentType.includes('application/json');\n const data = isJson ? await res.json().catch(() => null) : await res.text().catch(() => null);\n\n if (!res.ok) {\n const error = new Error(`HTTP ${res.status} ${res.statusText || ''}`.trim());\n (error as any).status = res.status;\n (error as any).data = data;\n if (logger) {\n logger.error({ ...logContext, url, method, status: res.status, data }, 'HTTP call failed');\n }\n throw error;\n }\n\n if (logger) {\n logger.info({ ...logContext, url, method, status: res.status }, 'HTTP call success');\n }\n\n return data;\n } catch (err: any) {\n if (logger) {\n logger.error({ ...logContext, url, method, error: err.message }, 'HTTP call error');\n }\n throw err;\n }\n}\n"],"mappings":"yPAAA,OAAS,QAAAA,EAAM,qBAAAC,EAAmB,gBAAAC,EAAc,SAAAC,MAAmB,qBACnE,OAAS,WAAAC,MAAe,0BAExB,OAAS,YAAAC,MAAgB,2BACzB,OAAS,qBAAAC,MAAyB,0CAClC,OAAS,+BAAAC,MAAmC,4CAC5C,OAAS,cAAAC,EAAY,uBAAAC,MAA2B,SAIhDT,EAAK,UAAU,IAAIC,EAAqBC,EAAa,IAAI,EAEzD,IAAMQ,EACJ,QAAQ,IAAI,mBACZ,QAAQ,IAAI,aACZ,kBACIC,EACJ,QAAQ,IAAI,gBACZ,QAAQ,IAAI,wBACZ,QAAQ,IAAI,UACZ,MACIC,EAAc,QAAQ,IAAI,UAAY,QAAQ,IAAI,UAAY,cAC9DC,EAAa,QAAQ,IAAI,aAAe,iBACxCC,GAAgB,QAAQ,IAAI,6BAA+B,yBAAyB,QAAQ,MAAO,EAAE,EACrGC,GAAwB,QAAQ,IAAI,uBAAyB,IAAI,YAAY,IAAM,OACnFC,EAAc,QAAQ,IAAI,aAAeH,EAGzCI,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,EAAKI,CAAY,EAGnCG,GAFcD,EAAI,QAAQ,IAAI,cAAc,GAAK,IAC5B,SAAS,kBAAkB,EAChC,MAAMA,EAAI,KAAK,EAAE,MAAM,IAAM,IAAI,EAAI,MAAMA,EAAI,KAAK,EAAE,MAAM,IAAM,IAAI,EAE5F,GAAI,CAACA,EAAI,GAAI,CACX,IAAME,EAAQ,IAAI,MAAM,QAAQF,EAAI,MAAM,IAAIA,EAAI,YAAc,EAAE,GAAG,KAAK,CAAC,EAC3E,MAACE,EAAc,OAASF,EAAI,OAC3BE,EAAc,KAAOD,EAClBL,GACFA,EAAO,MAAM,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,OAAQC,EAAI,OAAQ,KAAAC,CAAK,EAAG,kBAAkB,EAErFC,CACR,CAEA,OAAIN,GACFA,EAAO,KAAK,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,OAAQC,EAAI,MAAO,EAAG,mBAAmB,EAG9EC,CACT,OAASE,EAAU,CACjB,MAAIP,GACFA,EAAO,MAAM,CAAE,GAAGC,EAAY,IAAAH,EAAK,OAAAK,EAAQ,MAAOI,EAAI,OAAQ,EAAG,iBAAiB,EAE9EA,CACR,CACF","names":["diag","DiagConsoleLogger","DiagLogLevel","trace","NodeSDK","Resource","OTLPTraceExporter","getNodeAutoInstrumentations","ProxyAgent","setGlobalDispatcher","serviceName","serviceNamespace","environment","moduleName","otlpEndpoint","expressLayersEnabled","moduleLabel","proxyUrl","v","err","resource","ModuleNameSpanProcessor","span","currentName","_span","instrumentations","sdk","sdkStartPromise","error","shutdown","instrumentApp","app","logger","customModuleName","req","_res","next","pino","createLogger","mainEnv","mainApp","mainModule","trace","SpanStatusCode","errorMiddleware","logger","err","req","res","next","span","httpCall","url","options","logger","logContext","fetchOptions","method","res","data","error","err"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onelog-sdk/node",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "OneLog Node SDK for unified tracing, logging, and error handling.",
5
5
  "license": "MIT",
6
6
  "type": "module",