@onelog-sdk/node 0.1.0
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/README.md +69 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @onelog/node
|
|
2
|
+
|
|
3
|
+
Unified Node.js SDK for tracing, logging, HTTP calls, and exception capture. Drop it into any Express-based service to get consistent telemetry with one import.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
```bash
|
|
7
|
+
npm install @onelog/node
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Quickstart
|
|
11
|
+
```ts
|
|
12
|
+
import express from 'express';
|
|
13
|
+
import { sdkStartPromise, instrumentApp, createLogger, errorMiddleware, httpCall } from '@onelog/node';
|
|
14
|
+
|
|
15
|
+
const logger = createLogger();
|
|
16
|
+
const app = express();
|
|
17
|
+
const PORT = process.env.PORT || 8700;
|
|
18
|
+
|
|
19
|
+
app.use(express.json());
|
|
20
|
+
instrumentApp(app, logger, process.env.MAIN_MODULE);
|
|
21
|
+
|
|
22
|
+
app.get('/health', (_req, res) => res.json({ status: 'ok', module: process.env.MAIN_MODULE }));
|
|
23
|
+
|
|
24
|
+
app.post('/do', async (req, res, next) => {
|
|
25
|
+
try {
|
|
26
|
+
const reply = await httpCall(
|
|
27
|
+
process.env.PEER_URL || 'http://localhost:3001/work',
|
|
28
|
+
{ method: 'POST', body: req.body },
|
|
29
|
+
logger,
|
|
30
|
+
{ flow: 'demo' }
|
|
31
|
+
);
|
|
32
|
+
res.json({ ok: true, reply });
|
|
33
|
+
} catch (err) { next(err); }
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
app.use(errorMiddleware(logger));
|
|
37
|
+
|
|
38
|
+
sdkStartPromise.finally(() => {
|
|
39
|
+
app.listen(PORT, () => logger.info({ port: PORT }, 'Service started'));
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## What’s inside
|
|
44
|
+
- **Tracing** (`sdkStartPromise`, `instrumentApp`) — boots OpenTelemetry Node SDK with HTTP/Express/undici auto-instrumentation and renames spans to `[module] METHOD /path` while adding `module.name`.
|
|
45
|
+
- **Logging** (`createLogger`) — Pino with dual transports: OTLP-friendly output plus pretty console, pre-tagged with env/app/module.
|
|
46
|
+
- **Exceptions** (`errorMiddleware`) — records exceptions on the active span, sets span status to ERROR, logs details, and returns JSON.
|
|
47
|
+
- **HTTP calls** (`httpCall`) — fetch wrapper with consistent logging, JSON handling, and error propagation.
|
|
48
|
+
|
|
49
|
+
## Environment variables
|
|
50
|
+
- `PORT` — HTTP port for your service.
|
|
51
|
+
- `MAIN_MODULE` — logical module name (shown in spans and logs).
|
|
52
|
+
- `MAIN_APP` — application/system name.
|
|
53
|
+
- `MAIN_ENV` — environment (production/staging/dev).
|
|
54
|
+
- `OTEL_EXPORTER_OTLP_ENDPOINT` — OTLP HTTP endpoint (e.g., `http://localhost:4318`, no trailing slash).
|
|
55
|
+
- `OTEL_SERVICE_NAME` — service name for tracing.
|
|
56
|
+
- `OTEL_NAMESPACE` / `OTEL_SERVICE_NAMESPACE` — optional namespace.
|
|
57
|
+
- Downstream URLs as needed: `PEER_URL`, etc.
|
|
58
|
+
- `ONELOG_EXPRESS_LAYERS` — set to `true` to include middleware/request_handler spans (defaults to lean mode without them).
|
|
59
|
+
- `HTTP_PROXY` / `HTTPS_PROXY` (also lowercase variants) — if present, outbound HTTP (including OTLP export) uses the proxy.
|
|
60
|
+
|
|
61
|
+
## Build (for contributors)
|
|
62
|
+
```bash
|
|
63
|
+
npm install
|
|
64
|
+
npm run build # tsup → dist/index.{mjs,cjs} + types, minified
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Notes
|
|
68
|
+
- Requires Node 18+.
|
|
69
|
+
- Auto-instrumentation is focused on HTTP/Express/undici; noisy instrumentations are off by default.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var w=Object.create;var c=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var b=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 S(t))!I.call(e,n)&&n!==o&&c(e,n,{get:()=>t[n],enumerable:!(r=M(t,n))||r.enumerable});return e};var D=(e,t,o)=>(o=e!=null?w(b(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 p=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");p.diag.setLogger(new p.DiagConsoleLogger,p.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-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 i=p.trace.getActiveSpan();i&&(i.setAttribute("module.name",r),i.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});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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 '@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,mCACxB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,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","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"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Application, Request, Response, NextFunction } from 'express';
|
|
2
|
+
import pino, { Logger } from 'pino';
|
|
3
|
+
|
|
4
|
+
declare const sdkStartPromise: Promise<void>;
|
|
5
|
+
declare const instrumentApp: (app: Application, logger?: Logger, customModuleName?: string) => void;
|
|
6
|
+
|
|
7
|
+
declare function createLogger(): pino.Logger<never, boolean>;
|
|
8
|
+
|
|
9
|
+
declare const errorMiddleware: (logger?: Logger) => (err: Error, req: Request, res: Response, next: NextFunction) => void;
|
|
10
|
+
|
|
11
|
+
interface HttpCallContext {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
interface HttpCallOptions extends RequestInit {
|
|
15
|
+
body?: any;
|
|
16
|
+
}
|
|
17
|
+
declare function httpCall(url: string, options?: HttpCallOptions, logger?: {
|
|
18
|
+
info: Function;
|
|
19
|
+
error: Function;
|
|
20
|
+
}, logContext?: HttpCallContext): Promise<any>;
|
|
21
|
+
|
|
22
|
+
export { createLogger, errorMiddleware, httpCall, instrumentApp, sdkStartPromise };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Application, Request, Response, NextFunction } from 'express';
|
|
2
|
+
import pino, { Logger } from 'pino';
|
|
3
|
+
|
|
4
|
+
declare const sdkStartPromise: Promise<void>;
|
|
5
|
+
declare const instrumentApp: (app: Application, logger?: Logger, customModuleName?: string) => void;
|
|
6
|
+
|
|
7
|
+
declare function createLogger(): pino.Logger<never, boolean>;
|
|
8
|
+
|
|
9
|
+
declare const errorMiddleware: (logger?: Logger) => (err: Error, req: Request, res: Response, next: NextFunction) => void;
|
|
10
|
+
|
|
11
|
+
interface HttpCallContext {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
interface HttpCallOptions extends RequestInit {
|
|
15
|
+
body?: any;
|
|
16
|
+
}
|
|
17
|
+
declare function httpCall(url: string, options?: HttpCallOptions, logger?: {
|
|
18
|
+
info: Function;
|
|
19
|
+
error: Function;
|
|
20
|
+
}, logContext?: HttpCallContext): Promise<any>;
|
|
21
|
+
|
|
22
|
+
export { createLogger, errorMiddleware, httpCall, instrumentApp, sdkStartPromise };
|
package/dist/index.js
ADDED
|
@@ -0,0 +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(/\/$/,""),w=(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 M=l.default().merge(new l({"service.name":P,"service.namespace":_,"deployment.environment":O,"module.name":u})),S=x({"@opentelemetry/instrumentation-http":{enabled:!0},"@opentelemetry/instrumentation-express":{enabled:!0,ignoreLayersType:w?[]:["middleware","request_handler"]},"@opentelemetry/instrumentation-undici":{enabled:!0},"@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:M,instrumentations:[S]}),b=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 p=g.getActiveSpan();p&&(p.setAttribute("module.name",s),p.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),i=(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=i,o&&o.error({...s,url:e,method:a,status:r.status,data:i},"HTTP call failed"),c}return o&&o.info({...s,url:e,method:a,status:r.status},"HTTP call success"),i}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,b as sdkStartPromise};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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 '@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,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,OAGnFC,EAAW,CAAC,QAAQ,IAAI,YAAa,QAAQ,IAAI,YAAa,QAAQ,IAAI,WAAY,QAAQ,IAAI,UAAU,EAC/G,KAAMC,GAAMA,GAAKA,EAAE,KAAK,EAAE,OAAS,CAAC,EAEvC,GAAID,EAC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,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"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onelog-sdk/node",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OneLog Node SDK for unified tracing, logging, and error handling.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.cjs",
|
|
8
|
+
"module": "dist/index.mjs",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup",
|
|
15
|
+
"clean": "rm -rf dist",
|
|
16
|
+
"dev": "tsup --watch",
|
|
17
|
+
"lint": "echo \"No lint configured\"",
|
|
18
|
+
"test": "echo \"No tests yet\""
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"observability",
|
|
22
|
+
"otel",
|
|
23
|
+
"tracing",
|
|
24
|
+
"logging",
|
|
25
|
+
"pino",
|
|
26
|
+
"express"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@opentelemetry/api": "^1.9.0",
|
|
33
|
+
"@opentelemetry/auto-instrumentations-node": "^0.67.3",
|
|
34
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.55.0",
|
|
35
|
+
"@opentelemetry/resources": "^1.24.1",
|
|
36
|
+
"@opentelemetry/sdk-node": "^0.55.0",
|
|
37
|
+
"pino": "^10.1.0",
|
|
38
|
+
"pino-opentelemetry-transport": "^2.0.0",
|
|
39
|
+
"pino-pretty": "^13.1.3",
|
|
40
|
+
"undici": "^6.13.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/express": "^4.17.21",
|
|
44
|
+
"ts-node": "^10.9.2",
|
|
45
|
+
"tsup": "^8.0.2",
|
|
46
|
+
"typescript": "^5.4.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"express": ">=4",
|
|
50
|
+
"pino": ">=8"
|
|
51
|
+
}
|
|
52
|
+
}
|