@geekmidas/telescope 1.1.1 → 9.0.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/CHANGELOG.md +21 -0
- package/dist/{hono-Bz9PQQzj.mjs → hono-Bw-ey6CT.mjs} +2 -2
- package/dist/{hono-Bz9PQQzj.mjs.map → hono-Bw-ey6CT.mjs.map} +1 -1
- package/dist/{hono-Z_JIICmt.cjs → hono-CPHX7FAm.cjs} +2 -2
- package/dist/{hono-Z_JIICmt.cjs.map → hono-CPHX7FAm.cjs.map} +1 -1
- package/dist/{http-Crsriv32.mjs → http-BIvr0YdI.mjs} +1 -1
- package/dist/{http-Crsriv32.mjs.map → http-BIvr0YdI.mjs.map} +1 -1
- package/dist/{http-JycFRfSe.cjs → http-BsqmhurZ.cjs} +1 -1
- package/dist/{http-JycFRfSe.cjs.map → http-BsqmhurZ.cjs.map} +1 -1
- package/dist/instrumentation/hono.cjs +2 -2
- package/dist/instrumentation/hono.mjs +2 -2
- package/dist/instrumentation/http.cjs +1 -1
- package/dist/instrumentation/http.mjs +1 -1
- package/dist/instrumentation/index.cjs +5 -5
- package/dist/instrumentation/index.mjs +5 -5
- package/dist/instrumentation/middleware.cjs +2 -2
- package/dist/instrumentation/middleware.mjs +2 -2
- package/dist/instrumentation/otel.cjs +2 -2
- package/dist/instrumentation/otel.mjs +2 -2
- package/dist/instrumentation/setup.cjs +1 -1
- package/dist/instrumentation/setup.mjs +1 -1
- package/dist/logger/console.d.mts.map +1 -1
- package/dist/logger/pino.d.cts +2 -2
- package/dist/{middleware-Dy1ctr2N.mjs → middleware-4-GrQlOT.mjs} +2 -2
- package/dist/{middleware-Dy1ctr2N.mjs.map → middleware-4-GrQlOT.mjs.map} +1 -1
- package/dist/{middleware-D3v5SnSs.cjs → middleware-DqPQpcup.cjs} +2 -2
- package/dist/{middleware-D3v5SnSs.cjs.map → middleware-DqPQpcup.cjs.map} +1 -1
- package/dist/{otel-DPKNyJ0t.mjs → otel-40udNP5g.mjs} +2 -2
- package/dist/{otel-DPKNyJ0t.mjs.map → otel-40udNP5g.mjs.map} +1 -1
- package/dist/{otel-DuiBeBPU.cjs → otel-COrpz_GZ.cjs} +2 -2
- package/dist/{otel-DuiBeBPU.cjs.map → otel-COrpz_GZ.cjs.map} +1 -1
- package/dist/otlp/hono.cjs +3 -3
- package/dist/otlp/hono.mjs +3 -3
- package/dist/otlp/index.cjs +3 -3
- package/dist/otlp/index.mjs +3 -3
- package/dist/otlp/receiver.cjs +3 -3
- package/dist/otlp/receiver.mjs +3 -3
- package/dist/otlp/transformer.cjs +2 -2
- package/dist/otlp/transformer.mjs +2 -2
- package/dist/otlp/types.cjs +1 -1
- package/dist/otlp/types.mjs +1 -1
- package/dist/{receiver-q4f7eirs.mjs → receiver-D46dfkYI.mjs} +2 -2
- package/dist/{receiver-q4f7eirs.mjs.map → receiver-D46dfkYI.mjs.map} +1 -1
- package/dist/{receiver-BW_4go_X.cjs → receiver-slCoAFat.cjs} +2 -2
- package/dist/{receiver-BW_4go_X.cjs.map → receiver-slCoAFat.cjs.map} +1 -1
- package/dist/{setup-BhCp2LUp.mjs → setup-DC9JMEYZ.mjs} +1 -1
- package/dist/{setup-BhCp2LUp.mjs.map → setup-DC9JMEYZ.mjs.map} +1 -1
- package/dist/{setup-_uT4L_x5.cjs → setup-DufxQpi9.cjs} +1 -1
- package/dist/{setup-_uT4L_x5.cjs.map → setup-DufxQpi9.cjs.map} +1 -1
- package/dist/tracing-PnECEbEu.d.mts.map +1 -1
- package/dist/{transformer-CFrJQkUg.mjs → transformer-CFQ4WFk6.mjs} +2 -2
- package/dist/{transformer-CFrJQkUg.mjs.map → transformer-CFQ4WFk6.mjs.map} +1 -1
- package/dist/{transformer-DvDYyFRQ.cjs → transformer-Csl6fbgv.cjs} +2 -2
- package/dist/{transformer-DvDYyFRQ.cjs.map → transformer-Csl6fbgv.cjs.map} +1 -1
- package/dist/{types-BBeTDpHr.cjs → types-BMiHgsi4.cjs} +1 -1
- package/dist/{types-BBeTDpHr.cjs.map → types-BMiHgsi4.cjs.map} +1 -1
- package/dist/{types-CXYLhG_G.mjs → types-Cj59nqy7.mjs} +1 -1
- package/dist/{types-CXYLhG_G.mjs.map → types-Cj59nqy7.mjs.map} +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHttpServerSpan, endHttpSpan, extractTraceContext } from "./http-
|
|
1
|
+
import { createHttpServerSpan, endHttpSpan, extractTraceContext } from "./http-BIvr0YdI.mjs";
|
|
2
2
|
import { trace } from "@opentelemetry/api";
|
|
3
3
|
|
|
4
4
|
//#region src/instrumentation/otel.ts
|
|
@@ -127,4 +127,4 @@ function normalizeHeaders(headers) {
|
|
|
127
127
|
|
|
128
128
|
//#endregion
|
|
129
129
|
export { OTelTelemetry };
|
|
130
|
-
//# sourceMappingURL=otel-
|
|
130
|
+
//# sourceMappingURL=otel-40udNP5g.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel-DPKNyJ0t.mjs","names":["options: OTelTelemetryOptions","request: TelemetryRequest","ctx: TelemetryContext","response: TelemetryResponse","error: Error","event: any","lambdaContext: any","route: string | undefined","host: string | undefined","scheme: 'http' | 'https' | undefined","userAgent: string | undefined","clientIp: string | undefined","requestId: string | undefined","attrs: HttpSpanAttributes","headers: Record<string, string | string[] | undefined>","normalized: Record<string, string | string[] | undefined>"],"sources":["../src/instrumentation/otel.ts"],"sourcesContent":["/**\n * OpenTelemetry implementation of the Telemetry interface\n *\n * This provides automatic span creation for Lambda handlers using\n * OpenTelemetry. Works with any OTel-compatible backend (Jaeger, Zipkin,\n * Datadog, Honeycomb, etc.)\n */\nimport { type Span, trace } from '@opentelemetry/api';\nimport type { Context as LambdaContext } from 'aws-lambda';\n\n/**\n * Context object returned by onRequestStart, passed to subsequent hooks.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryContext {\n\t[key: string]: unknown;\n}\n\n/**\n * Request information passed to telemetry hooks.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryRequest {\n\tevent: any;\n\tcontext: LambdaContext;\n}\n\n/**\n * Response information passed to onRequestEnd.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryResponse {\n\tstatusCode: number;\n\tbody?: string;\n\theaders?: Record<string, string>;\n}\n\n/**\n * Telemetry interface for instrumenting endpoint requests.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface Telemetry {\n\tonRequestStart(request: TelemetryRequest): TelemetryContext;\n\tonRequestEnd(ctx: TelemetryContext, response: TelemetryResponse): void;\n\tonRequestError(ctx: TelemetryContext, error: Error): void;\n}\n\nimport {\n\tcreateHttpServerSpan,\n\tendHttpSpan,\n\textractTraceContext,\n\ttype HttpSpanAttributes,\n} from './http';\n\n/**\n * Options for OTelTelemetry\n */\nexport interface OTelTelemetryOptions {\n\t/**\n\t * Whether to record request body as span attribute\n\t * @default false\n\t */\n\trecordBody?: boolean;\n\n\t/**\n\t * Whether to record response body as span attribute\n\t * @default false\n\t */\n\trecordResponseBody?: boolean;\n\n\t/**\n\t * Custom function to extract user ID from event\n\t */\n\tgetUserId?: (event: any) => string | undefined;\n\n\t/**\n\t * Custom function to extract endpoint name from event\n\t */\n\tgetEndpointName?: (event: any) => string | undefined;\n\n\t/**\n\t * Custom function to extract operation ID from event\n\t */\n\tgetOperationId?: (event: any) => string | undefined;\n}\n\n/**\n * Telemetry context with span reference\n */\ninterface OTelContext extends TelemetryContext {\n\tspan: Span;\n\totelContext: any;\n}\n\n/**\n * OpenTelemetry implementation of the Telemetry interface\n *\n * @example\n * ```typescript\n * import { OTelTelemetry } from '@geekmidas/telescope/instrumentation';\n *\n * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n * telemetry: new OTelTelemetry(),\n * });\n * ```\n *\n * @example With options\n * ```typescript\n * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n * telemetry: new OTelTelemetry({\n * recordBody: true,\n * getUserId: (event) => event.requestContext?.authorizer?.userId,\n * }),\n * });\n * ```\n */\nexport class OTelTelemetry implements Telemetry {\n\tconstructor(private options: OTelTelemetryOptions = {}) {}\n\n\tonRequestStart(request: TelemetryRequest): TelemetryContext {\n\t\tconst { event, context: lambdaContext } = request;\n\n\t\t// Extract trace context from headers\n\t\tconst headers = normalizeHeaders(event.headers || {});\n\t\tconst parentContext = extractTraceContext(headers);\n\n\t\t// Build span attributes from event\n\t\tconst attrs = this.buildSpanAttributes(event, lambdaContext);\n\n\t\t// Create the span\n\t\tconst span = createHttpServerSpan(attrs, parentContext);\n\t\tconst otelContext = trace.setSpan(parentContext, span);\n\n\t\t// Add Lambda-specific attributes\n\t\tspan.setAttribute('faas.invocation_id', lambdaContext.awsRequestId);\n\t\tspan.setAttribute('faas.name', lambdaContext.functionName);\n\n\t\t// Record body if requested\n\t\tif (this.options.recordBody && event.body) {\n\t\t\tconst bodyStr =\n\t\t\t\ttypeof event.body === 'string'\n\t\t\t\t\t? event.body\n\t\t\t\t\t: JSON.stringify(event.body);\n\t\t\tspan.setAttribute(\n\t\t\t\t'http.request.body',\n\t\t\t\tbodyStr.length > 4096 ? `${bodyStr.slice(0, 4096)}...` : bodyStr,\n\t\t\t);\n\t\t}\n\n\t\treturn { span, otelContext } as OTelContext;\n\t}\n\n\tonRequestEnd(ctx: TelemetryContext, response: TelemetryResponse): void {\n\t\tconst { span } = ctx as OTelContext;\n\n\t\tif (this.options.recordResponseBody && response.body) {\n\t\t\tspan.setAttribute(\n\t\t\t\t'http.response.body',\n\t\t\t\tresponse.body.length > 4096\n\t\t\t\t\t? `${response.body.slice(0, 4096)}...`\n\t\t\t\t\t: response.body,\n\t\t\t);\n\t\t}\n\n\t\tendHttpSpan(span, { statusCode: response.statusCode });\n\t}\n\n\tonRequestError(ctx: TelemetryContext, error: Error): void {\n\t\tconst { span } = ctx as OTelContext;\n\t\tendHttpSpan(span, { statusCode: 500 }, error);\n\t}\n\n\t/**\n\t * Build span attributes from Lambda event\n\t */\n\tprivate buildSpanAttributes(\n\t\tevent: any,\n\t\tlambdaContext: any,\n\t): HttpSpanAttributes {\n\t\t// Detect event type (API Gateway v1, v2, ALB, or direct invoke)\n\t\tconst isV2 =\n\t\t\t'requestContext' in event && 'http' in (event.requestContext || {});\n\t\tconst isV1 =\n\t\t\t'requestContext' in event &&\n\t\t\t'httpMethod' in event &&\n\t\t\t!('http' in (event.requestContext || {}));\n\n\t\tlet method = 'INVOKE';\n\t\tlet path = '/';\n\t\tlet route: string | undefined;\n\t\tlet host: string | undefined;\n\t\tlet scheme: 'http' | 'https' | undefined;\n\t\tlet userAgent: string | undefined;\n\t\tlet clientIp: string | undefined;\n\t\tlet requestId: string | undefined;\n\n\t\tif (isV2) {\n\t\t\t// API Gateway v2 (HTTP API)\n\t\t\tconst http = event.requestContext.http;\n\t\t\tmethod = http.method;\n\t\t\tpath = event.rawPath || http.path;\n\t\t\troute = event.routeKey?.replace(/^[A-Z]+\\s+/, ''); // Remove HTTP method prefix\n\t\t\thost = event.headers?.host;\n\t\t\tscheme = 'https';\n\t\t\tuserAgent = http.userAgent;\n\t\t\tclientIp = http.sourceIp;\n\t\t\trequestId = event.requestContext.requestId;\n\t\t} else if (isV1) {\n\t\t\t// API Gateway v1 (REST API)\n\t\t\tmethod = event.httpMethod;\n\t\t\tpath = event.path;\n\t\t\troute = event.resource;\n\t\t\thost = event.headers?.Host || event.headers?.host;\n\t\t\tscheme = 'https';\n\t\t\tuserAgent =\n\t\t\t\tevent.headers?.['User-Agent'] || event.headers?.['user-agent'];\n\t\t\tclientIp = event.requestContext?.identity?.sourceIp;\n\t\t\trequestId = event.requestContext?.requestId;\n\t\t} else if ('httpMethod' in event) {\n\t\t\t// ALB event\n\t\t\tmethod = event.httpMethod;\n\t\t\tpath = event.path;\n\t\t\thost = event.headers?.host;\n\t\t\tuserAgent =\n\t\t\t\tevent.headers?.['user-agent'] || event.headers?.['User-Agent'];\n\t\t\tclientIp = event.headers?.['x-forwarded-for']?.split(',')[0]?.trim();\n\t\t}\n\n\t\tconst attrs: HttpSpanAttributes = {\n\t\t\tmethod,\n\t\t\tpath,\n\t\t\troute,\n\t\t\thost,\n\t\t\tscheme,\n\t\t\tuserAgent,\n\t\t\tclientIp,\n\t\t\trequestId: requestId || lambdaContext.awsRequestId,\n\t\t};\n\n\t\t// Add endpoint metadata if extractors provided\n\t\tif (this.options.getEndpointName || this.options.getOperationId) {\n\t\t\tattrs.endpoint = {\n\t\t\t\tname: this.options.getEndpointName?.(event),\n\t\t\t\toperationId: this.options.getOperationId?.(event),\n\t\t\t};\n\t\t}\n\n\t\t// Add user metadata if extractor provided\n\t\tif (this.options.getUserId) {\n\t\t\tconst userId = this.options.getUserId(event);\n\t\t\tif (userId) {\n\t\t\t\tattrs.user = { userId };\n\t\t\t}\n\t\t}\n\n\t\treturn attrs;\n\t}\n}\n\n/**\n * Normalize headers to lowercase keys\n */\nfunction normalizeHeaders(\n\theaders: Record<string, string | string[] | undefined>,\n): Record<string, string | string[] | undefined> {\n\tconst normalized: Record<string, string | string[] | undefined> = {};\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tnormalized[key.toLowerCase()] = value;\n\t}\n\treturn normalized;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,IAAa,gBAAb,MAAgD;CAC/C,YAAoBA,UAAgC,CAAE,GAAE;EAApC;CAAsC;CAE1D,eAAeC,SAA6C;EAC3D,MAAM,EAAE,OAAO,SAAS,eAAe,GAAG;EAG1C,MAAM,UAAU,iBAAiB,MAAM,WAAW,CAAE,EAAC;EACrD,MAAM,gBAAgB,oBAAoB,QAAQ;EAGlD,MAAM,QAAQ,KAAK,oBAAoB,OAAO,cAAc;EAG5D,MAAM,OAAO,qBAAqB,OAAO,cAAc;EACvD,MAAM,cAAc,MAAM,QAAQ,eAAe,KAAK;AAGtD,OAAK,aAAa,sBAAsB,cAAc,aAAa;AACnE,OAAK,aA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AM;AACd,UAAO,MAAM,SAAS,QAAQ,MAAM,SAAS;AAC7C,YAAS;AACT,eACC,MAAM,UAAU,iBAAiB,MAAM,UAAU;AAClD,cAAW,MAAM,gBAAgB,UAAU;AAC3C,eAAY,MAAM,gBAAgB;EAClC,WAAU,gBAAgB,OAAO;AAEjC,YAAS,MAAM;AACf,UAAO,MAAM;AACb,UAAO,MAAM,SAAS;AACtB,eACC,MAAM,UAAU,iBAAiB,MAAM,UAAU;AAClD,cAAW,MAAM,UAAU,oBAAoB,MAAM,IAAI,CAAC,IAAI,MAAM;EACpE;EAED,MAAMC,QAA4B;GACjC;GACA;GACA;GACA;GACA;GACA;GACA;GACA,WAAW,aAAa,cAAc;EACtC;AAGD,MAAI,KAAK,QAAQ,mBAAmB,KAAK,QAAQ,eAChD,OAAM,WAAW;GAChB,MAAM,KAAK,QAAQ,kBAAkB,MAAM;GAC3C,aAAa,KAAK,QAAQ,iBAAiB,MAAM;EACjD;AAIF,MAAI,KAAK,QAAQ,WAAW;GAC3B,MAAM,SAAS,KAAK,QAAQ,UAAU,MAAM;AAC5C,OAAI,OACH,OAAM,OAAO,EAAE,OAAQ;EAExB;AAED,SAAO;CACP;AACD;;;;AAKD,SAAS,iBACRC,SACgD;CAChD,MAAMC,aAA4D,CAAE;AACpE,MAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,QAAQ,CACjD,YAAW,IAAI,aAAa,IAAI;AAEjC,QAAO;AACP"}
|
|
1
|
+
{"version":3,"file":"otel-40udNP5g.mjs","names":["options: OTelTelemetryOptions","request: TelemetryRequest","ctx: TelemetryContext","response: TelemetryResponse","error: Error","event: any","lambdaContext: any","route: string | undefined","host: string | undefined","scheme: 'http' | 'https' | undefined","userAgent: string | undefined","clientIp: string | undefined","requestId: string | undefined","attrs: HttpSpanAttributes","headers: Record<string, string | string[] | undefined>","normalized: Record<string, string | string[] | undefined>"],"sources":["../src/instrumentation/otel.ts"],"sourcesContent":["/**\n * OpenTelemetry implementation of the Telemetry interface\n *\n * This provides automatic span creation for Lambda handlers using\n * OpenTelemetry. Works with any OTel-compatible backend (Jaeger, Zipkin,\n * Datadog, Honeycomb, etc.)\n */\nimport { type Span, trace } from '@opentelemetry/api';\nimport type { Context as LambdaContext } from 'aws-lambda';\n\n/**\n * Context object returned by onRequestStart, passed to subsequent hooks.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryContext {\n\t[key: string]: unknown;\n}\n\n/**\n * Request information passed to telemetry hooks.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryRequest {\n\tevent: any;\n\tcontext: LambdaContext;\n}\n\n/**\n * Response information passed to onRequestEnd.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryResponse {\n\tstatusCode: number;\n\tbody?: string;\n\theaders?: Record<string, string>;\n}\n\n/**\n * Telemetry interface for instrumenting endpoint requests.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface Telemetry {\n\tonRequestStart(request: TelemetryRequest): TelemetryContext;\n\tonRequestEnd(ctx: TelemetryContext, response: TelemetryResponse): void;\n\tonRequestError(ctx: TelemetryContext, error: Error): void;\n}\n\nimport {\n\tcreateHttpServerSpan,\n\tendHttpSpan,\n\textractTraceContext,\n\ttype HttpSpanAttributes,\n} from './http';\n\n/**\n * Options for OTelTelemetry\n */\nexport interface OTelTelemetryOptions {\n\t/**\n\t * Whether to record request body as span attribute\n\t * @default false\n\t */\n\trecordBody?: boolean;\n\n\t/**\n\t * Whether to record response body as span attribute\n\t * @default false\n\t */\n\trecordResponseBody?: boolean;\n\n\t/**\n\t * Custom function to extract user ID from event\n\t */\n\tgetUserId?: (event: any) => string | undefined;\n\n\t/**\n\t * Custom function to extract endpoint name from event\n\t */\n\tgetEndpointName?: (event: any) => string | undefined;\n\n\t/**\n\t * Custom function to extract operation ID from event\n\t */\n\tgetOperationId?: (event: any) => string | undefined;\n}\n\n/**\n * Telemetry context with span reference\n */\ninterface OTelContext extends TelemetryContext {\n\tspan: Span;\n\totelContext: any;\n}\n\n/**\n * OpenTelemetry implementation of the Telemetry interface\n *\n * @example\n * ```typescript\n * import { OTelTelemetry } from '@geekmidas/telescope/instrumentation';\n *\n * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n * telemetry: new OTelTelemetry(),\n * });\n * ```\n *\n * @example With options\n * ```typescript\n * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n * telemetry: new OTelTelemetry({\n * recordBody: true,\n * getUserId: (event) => event.requestContext?.authorizer?.userId,\n * }),\n * });\n * ```\n */\nexport class OTelTelemetry implements Telemetry {\n\tconstructor(private options: OTelTelemetryOptions = {}) {}\n\n\tonRequestStart(request: TelemetryRequest): TelemetryContext {\n\t\tconst { event, context: lambdaContext } = request;\n\n\t\t// Extract trace context from headers\n\t\tconst headers = normalizeHeaders(event.headers || {});\n\t\tconst parentContext = extractTraceContext(headers);\n\n\t\t// Build span attributes from event\n\t\tconst attrs = this.buildSpanAttributes(event, lambdaContext);\n\n\t\t// Create the span\n\t\tconst span = createHttpServerSpan(attrs, parentContext);\n\t\tconst otelContext = trace.setSpan(parentContext, span);\n\n\t\t// Add Lambda-specific attributes\n\t\tspan.setAttribute('faas.invocation_id', lambdaContext.awsRequestId);\n\t\tspan.setAttribute('faas.name', lambdaContext.functionName);\n\n\t\t// Record body if requested\n\t\tif (this.options.recordBody && event.body) {\n\t\t\tconst bodyStr =\n\t\t\t\ttypeof event.body === 'string'\n\t\t\t\t\t? event.body\n\t\t\t\t\t: JSON.stringify(event.body);\n\t\t\tspan.setAttribute(\n\t\t\t\t'http.request.body',\n\t\t\t\tbodyStr.length > 4096 ? `${bodyStr.slice(0, 4096)}...` : bodyStr,\n\t\t\t);\n\t\t}\n\n\t\treturn { span, otelContext } as OTelContext;\n\t}\n\n\tonRequestEnd(ctx: TelemetryContext, response: TelemetryResponse): void {\n\t\tconst { span } = ctx as OTelContext;\n\n\t\tif (this.options.recordResponseBody && response.body) {\n\t\t\tspan.setAttribute(\n\t\t\t\t'http.response.body',\n\t\t\t\tresponse.body.length > 4096\n\t\t\t\t\t? `${response.body.slice(0, 4096)}...`\n\t\t\t\t\t: response.body,\n\t\t\t);\n\t\t}\n\n\t\tendHttpSpan(span, { statusCode: response.statusCode });\n\t}\n\n\tonRequestError(ctx: TelemetryContext, error: Error): void {\n\t\tconst { span } = ctx as OTelContext;\n\t\tendHttpSpan(span, { statusCode: 500 }, error);\n\t}\n\n\t/**\n\t * Build span attributes from Lambda event\n\t */\n\tprivate buildSpanAttributes(\n\t\tevent: any,\n\t\tlambdaContext: any,\n\t): HttpSpanAttributes {\n\t\t// Detect event type (API Gateway v1, v2, ALB, or direct invoke)\n\t\tconst isV2 =\n\t\t\t'requestContext' in event && 'http' in (event.requestContext || {});\n\t\tconst isV1 =\n\t\t\t'requestContext' in event &&\n\t\t\t'httpMethod' in event &&\n\t\t\t!('http' in (event.requestContext || {}));\n\n\t\tlet method = 'INVOKE';\n\t\tlet path = '/';\n\t\tlet route: string | undefined;\n\t\tlet host: string | undefined;\n\t\tlet scheme: 'http' | 'https' | undefined;\n\t\tlet userAgent: string | undefined;\n\t\tlet clientIp: string | undefined;\n\t\tlet requestId: string | undefined;\n\n\t\tif (isV2) {\n\t\t\t// API Gateway v2 (HTTP API)\n\t\t\tconst http = event.requestContext.http;\n\t\t\tmethod = http.method;\n\t\t\tpath = event.rawPath || http.path;\n\t\t\troute = event.routeKey?.replace(/^[A-Z]+\\s+/, ''); // Remove HTTP method prefix\n\t\t\thost = event.headers?.host;\n\t\t\tscheme = 'https';\n\t\t\tuserAgent = http.userAgent;\n\t\t\tclientIp = http.sourceIp;\n\t\t\trequestId = event.requestContext.requestId;\n\t\t} else if (isV1) {\n\t\t\t// API Gateway v1 (REST API)\n\t\t\tmethod = event.httpMethod;\n\t\t\tpath = event.path;\n\t\t\troute = event.resource;\n\t\t\thost = event.headers?.Host || event.headers?.host;\n\t\t\tscheme = 'https';\n\t\t\tuserAgent =\n\t\t\t\tevent.headers?.['User-Agent'] || event.headers?.['user-agent'];\n\t\t\tclientIp = event.requestContext?.identity?.sourceIp;\n\t\t\trequestId = event.requestContext?.requestId;\n\t\t} else if ('httpMethod' in event) {\n\t\t\t// ALB event\n\t\t\tmethod = event.httpMethod;\n\t\t\tpath = event.path;\n\t\t\thost = event.headers?.host;\n\t\t\tuserAgent =\n\t\t\t\tevent.headers?.['user-agent'] || event.headers?.['User-Agent'];\n\t\t\tclientIp = event.headers?.['x-forwarded-for']?.split(',')[0]?.trim();\n\t\t}\n\n\t\tconst attrs: HttpSpanAttributes = {\n\t\t\tmethod,\n\t\t\tpath,\n\t\t\troute,\n\t\t\thost,\n\t\t\tscheme,\n\t\t\tuserAgent,\n\t\t\tclientIp,\n\t\t\trequestId: requestId || lambdaContext.awsRequestId,\n\t\t};\n\n\t\t// Add endpoint metadata if extractors provided\n\t\tif (this.options.getEndpointName || this.options.getOperationId) {\n\t\t\tattrs.endpoint = {\n\t\t\t\tname: this.options.getEndpointName?.(event),\n\t\t\t\toperationId: this.options.getOperationId?.(event),\n\t\t\t};\n\t\t}\n\n\t\t// Add user metadata if extractor provided\n\t\tif (this.options.getUserId) {\n\t\t\tconst userId = this.options.getUserId(event);\n\t\t\tif (userId) {\n\t\t\t\tattrs.user = { userId };\n\t\t\t}\n\t\t}\n\n\t\treturn attrs;\n\t}\n}\n\n/**\n * Normalize headers to lowercase keys\n */\nfunction normalizeHeaders(\n\theaders: Record<string, string | string[] | undefined>,\n): Record<string, string | string[] | undefined> {\n\tconst normalized: Record<string, string | string[] | undefined> = {};\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tnormalized[key.toLowerCase()] = value;\n\t}\n\treturn normalized;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,IAAa,gBAAb,MAAgD;CAC/C,YAAoBA,UAAgC,CAAE,GAAE;EAApC;CAAsC;CAE1D,eAAeC,SAA6C;EAC3D,MAAM,EAAE,OAAO,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
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_http = require('./http-
|
|
2
|
+
const require_http = require('./http-BsqmhurZ.cjs');
|
|
3
3
|
const __opentelemetry_api = require_chunk.__toESM(require("@opentelemetry/api"));
|
|
4
4
|
|
|
5
5
|
//#region src/instrumentation/otel.ts
|
|
@@ -133,4 +133,4 @@ Object.defineProperty(exports, 'OTelTelemetry', {
|
|
|
133
133
|
return OTelTelemetry;
|
|
134
134
|
}
|
|
135
135
|
});
|
|
136
|
-
//# sourceMappingURL=otel-
|
|
136
|
+
//# sourceMappingURL=otel-COrpz_GZ.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel-DuiBeBPU.cjs","names":["options: OTelTelemetryOptions","request: TelemetryRequest","ctx: TelemetryContext","response: TelemetryResponse","error: Error","event: any","lambdaContext: any","route: string | undefined","host: string | undefined","scheme: 'http' | 'https' | undefined","userAgent: string | undefined","clientIp: string | undefined","requestId: string | undefined","attrs: HttpSpanAttributes","headers: Record<string, string | string[] | undefined>","normalized: Record<string, string | string[] | undefined>"],"sources":["../src/instrumentation/otel.ts"],"sourcesContent":["/**\n * OpenTelemetry implementation of the Telemetry interface\n *\n * This provides automatic span creation for Lambda handlers using\n * OpenTelemetry. Works with any OTel-compatible backend (Jaeger, Zipkin,\n * Datadog, Honeycomb, etc.)\n */\nimport { type Span, trace } from '@opentelemetry/api';\nimport type { Context as LambdaContext } from 'aws-lambda';\n\n/**\n * Context object returned by onRequestStart, passed to subsequent hooks.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryContext {\n\t[key: string]: unknown;\n}\n\n/**\n * Request information passed to telemetry hooks.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryRequest {\n\tevent: any;\n\tcontext: LambdaContext;\n}\n\n/**\n * Response information passed to onRequestEnd.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryResponse {\n\tstatusCode: number;\n\tbody?: string;\n\theaders?: Record<string, string>;\n}\n\n/**\n * Telemetry interface for instrumenting endpoint requests.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface Telemetry {\n\tonRequestStart(request: TelemetryRequest): TelemetryContext;\n\tonRequestEnd(ctx: TelemetryContext, response: TelemetryResponse): void;\n\tonRequestError(ctx: TelemetryContext, error: Error): void;\n}\n\nimport {\n\tcreateHttpServerSpan,\n\tendHttpSpan,\n\textractTraceContext,\n\ttype HttpSpanAttributes,\n} from './http';\n\n/**\n * Options for OTelTelemetry\n */\nexport interface OTelTelemetryOptions {\n\t/**\n\t * Whether to record request body as span attribute\n\t * @default false\n\t */\n\trecordBody?: boolean;\n\n\t/**\n\t * Whether to record response body as span attribute\n\t * @default false\n\t */\n\trecordResponseBody?: boolean;\n\n\t/**\n\t * Custom function to extract user ID from event\n\t */\n\tgetUserId?: (event: any) => string | undefined;\n\n\t/**\n\t * Custom function to extract endpoint name from event\n\t */\n\tgetEndpointName?: (event: any) => string | undefined;\n\n\t/**\n\t * Custom function to extract operation ID from event\n\t */\n\tgetOperationId?: (event: any) => string | undefined;\n}\n\n/**\n * Telemetry context with span reference\n */\ninterface OTelContext extends TelemetryContext {\n\tspan: Span;\n\totelContext: any;\n}\n\n/**\n * OpenTelemetry implementation of the Telemetry interface\n *\n * @example\n * ```typescript\n * import { OTelTelemetry } from '@geekmidas/telescope/instrumentation';\n *\n * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n * telemetry: new OTelTelemetry(),\n * });\n * ```\n *\n * @example With options\n * ```typescript\n * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n * telemetry: new OTelTelemetry({\n * recordBody: true,\n * getUserId: (event) => event.requestContext?.authorizer?.userId,\n * }),\n * });\n * ```\n */\nexport class OTelTelemetry implements Telemetry {\n\tconstructor(private options: OTelTelemetryOptions = {}) {}\n\n\tonRequestStart(request: TelemetryRequest): TelemetryContext {\n\t\tconst { event, context: lambdaContext } = request;\n\n\t\t// Extract trace context from headers\n\t\tconst headers = normalizeHeaders(event.headers || {});\n\t\tconst parentContext = extractTraceContext(headers);\n\n\t\t// Build span attributes from event\n\t\tconst attrs = this.buildSpanAttributes(event, lambdaContext);\n\n\t\t// Create the span\n\t\tconst span = createHttpServerSpan(attrs, parentContext);\n\t\tconst otelContext = trace.setSpan(parentContext, span);\n\n\t\t// Add Lambda-specific attributes\n\t\tspan.setAttribute('faas.invocation_id', lambdaContext.awsRequestId);\n\t\tspan.setAttribute('faas.name', lambdaContext.functionName);\n\n\t\t// Record body if requested\n\t\tif (this.options.recordBody && event.body) {\n\t\t\tconst bodyStr =\n\t\t\t\ttypeof event.body === 'string'\n\t\t\t\t\t? event.body\n\t\t\t\t\t: JSON.stringify(event.body);\n\t\t\tspan.setAttribute(\n\t\t\t\t'http.request.body',\n\t\t\t\tbodyStr.length > 4096 ? `${bodyStr.slice(0, 4096)}...` : bodyStr,\n\t\t\t);\n\t\t}\n\n\t\treturn { span, otelContext } as OTelContext;\n\t}\n\n\tonRequestEnd(ctx: TelemetryContext, response: TelemetryResponse): void {\n\t\tconst { span } = ctx as OTelContext;\n\n\t\tif (this.options.recordResponseBody && response.body) {\n\t\t\tspan.setAttribute(\n\t\t\t\t'http.response.body',\n\t\t\t\tresponse.body.length > 4096\n\t\t\t\t\t? `${response.body.slice(0, 4096)}...`\n\t\t\t\t\t: response.body,\n\t\t\t);\n\t\t}\n\n\t\tendHttpSpan(span, { statusCode: response.statusCode });\n\t}\n\n\tonRequestError(ctx: TelemetryContext, error: Error): void {\n\t\tconst { span } = ctx as OTelContext;\n\t\tendHttpSpan(span, { statusCode: 500 }, error);\n\t}\n\n\t/**\n\t * Build span attributes from Lambda event\n\t */\n\tprivate buildSpanAttributes(\n\t\tevent: any,\n\t\tlambdaContext: any,\n\t): HttpSpanAttributes {\n\t\t// Detect event type (API Gateway v1, v2, ALB, or direct invoke)\n\t\tconst isV2 =\n\t\t\t'requestContext' in event && 'http' in (event.requestContext || {});\n\t\tconst isV1 =\n\t\t\t'requestContext' in event &&\n\t\t\t'httpMethod' in event &&\n\t\t\t!('http' in (event.requestContext || {}));\n\n\t\tlet method = 'INVOKE';\n\t\tlet path = '/';\n\t\tlet route: string | undefined;\n\t\tlet host: string | undefined;\n\t\tlet scheme: 'http' | 'https' | undefined;\n\t\tlet userAgent: string | undefined;\n\t\tlet clientIp: string | undefined;\n\t\tlet requestId: string | undefined;\n\n\t\tif (isV2) {\n\t\t\t// API Gateway v2 (HTTP API)\n\t\t\tconst http = event.requestContext.http;\n\t\t\tmethod = http.method;\n\t\t\tpath = event.rawPath || http.path;\n\t\t\troute = event.routeKey?.replace(/^[A-Z]+\\s+/, ''); // Remove HTTP method prefix\n\t\t\thost = event.headers?.host;\n\t\t\tscheme = 'https';\n\t\t\tuserAgent = http.userAgent;\n\t\t\tclientIp = http.sourceIp;\n\t\t\trequestId = event.requestContext.requestId;\n\t\t} else if (isV1) {\n\t\t\t// API Gateway v1 (REST API)\n\t\t\tmethod = event.httpMethod;\n\t\t\tpath = event.path;\n\t\t\troute = event.resource;\n\t\t\thost = event.headers?.Host || event.headers?.host;\n\t\t\tscheme = 'https';\n\t\t\tuserAgent =\n\t\t\t\tevent.headers?.['User-Agent'] || event.headers?.['user-agent'];\n\t\t\tclientIp = event.requestContext?.identity?.sourceIp;\n\t\t\trequestId = event.requestContext?.requestId;\n\t\t} else if ('httpMethod' in event) {\n\t\t\t// ALB event\n\t\t\tmethod = event.httpMethod;\n\t\t\tpath = event.path;\n\t\t\thost = event.headers?.host;\n\t\t\tuserAgent =\n\t\t\t\tevent.headers?.['user-agent'] || event.headers?.['User-Agent'];\n\t\t\tclientIp = event.headers?.['x-forwarded-for']?.split(',')[0]?.trim();\n\t\t}\n\n\t\tconst attrs: HttpSpanAttributes = {\n\t\t\tmethod,\n\t\t\tpath,\n\t\t\troute,\n\t\t\thost,\n\t\t\tscheme,\n\t\t\tuserAgent,\n\t\t\tclientIp,\n\t\t\trequestId: requestId || lambdaContext.awsRequestId,\n\t\t};\n\n\t\t// Add endpoint metadata if extractors provided\n\t\tif (this.options.getEndpointName || this.options.getOperationId) {\n\t\t\tattrs.endpoint = {\n\t\t\t\tname: this.options.getEndpointName?.(event),\n\t\t\t\toperationId: this.options.getOperationId?.(event),\n\t\t\t};\n\t\t}\n\n\t\t// Add user metadata if extractor provided\n\t\tif (this.options.getUserId) {\n\t\t\tconst userId = this.options.getUserId(event);\n\t\t\tif (userId) {\n\t\t\t\tattrs.user = { userId };\n\t\t\t}\n\t\t}\n\n\t\treturn attrs;\n\t}\n}\n\n/**\n * Normalize headers to lowercase keys\n */\nfunction normalizeHeaders(\n\theaders: Record<string, string | string[] | undefined>,\n): Record<string, string | string[] | undefined> {\n\tconst normalized: Record<string, string | string[] | undefined> = {};\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tnormalized[key.toLowerCase()] = value;\n\t}\n\treturn normalized;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,IAAa,gBAAb,MAAgD;CAC/C,YAAoBA,UAAgC,CAAE,GAAE;EAApC;CAAsC;CAE1D,eAAeC,SAA6C;EAC3D,MAAM,EAAE,OAAO,SAAS,eAAe,GAAG;EAG1C,MAAM,UAAU,iBAAiB,MAAM,WAAW,CAAE,EAAC;EACrD,MAAM,gBAAgB,iCAAoB,QAAQ;EAGlD,MAAM,QAAQ,KAAK,oBAAoB,OAAO,cAAc;EAG5D,MAAM,OAAO,kCAAqB,OAAO,cAAc;EACvD,MAAM,cAAc,0BAAM,QAAQ,eAAe,KAAK;AAGtD,OAAK,aAAa,sBAAsB,cAAc,aAAa;AACnE,OAAK,aAAa,aAAa,cAAc,aAAa;AAG1D,MAAI,KAAK,QAAQ,cAAc,MAAM,MAAM;GAC1C,MAAM,iBACE,MAAM,SAAS,WACnB,MAAM,OACN,KAAK,UAAU,MAAM,KAAK;AAC9B,QAAK,aACJ,qBACA,QAAQ,SAAS,QAAQ,EAAE,QAAQ,MAA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S,MAAM;AACf,UAAO,MAAM;AACb,UAAO,MAAM,SAAS;AACtB,eACC,MAAM,UAAU,iBAAiB,MAAM,UAAU;AAClD,cAAW,MAAM,UAAU,oBAAoB,MAAM,IAAI,CAAC,IAAI,MAAM;EACpE;EAED,MAAMC,QAA4B;GACjC;GACA;GACA;GACA;GACA;GACA;GACA;GACA,WAAW,aAAa,cAAc;EACtC;AAGD,MAAI,KAAK,QAAQ,mBAAmB,KAAK,QAAQ,eAChD,OAAM,WAAW;GAChB,MAAM,KAAK,QAAQ,kBAAkB,MAAM;GAC3C,aAAa,KAAK,QAAQ,iBAAiB,MAAM;EACjD;AAIF,MAAI,KAAK,QAAQ,WAAW;GAC3B,MAAM,SAAS,KAAK,QAAQ,UAAU,MAAM;AAC5C,OAAI,OACH,OAAM,OAAO,EAAE,OAAQ;EAExB;AAED,SAAO;CACP;AACD;;;;AAKD,SAAS,iBACRC,SACgD;CAChD,MAAMC,aAA4D,CAAE;AACpE,MAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,QAAQ,CACjD,YAAW,IAAI,aAAa,IAAI;AAEjC,QAAO;AACP"}
|
|
1
|
+
{"version":3,"file":"otel-COrpz_GZ.cjs","names":["options: OTelTelemetryOptions","request: TelemetryRequest","ctx: TelemetryContext","response: TelemetryResponse","error: Error","event: any","lambdaContext: any","route: string | undefined","host: string | undefined","scheme: 'http' | 'https' | undefined","userAgent: string | undefined","clientIp: string | undefined","requestId: string | undefined","attrs: HttpSpanAttributes","headers: Record<string, string | string[] | undefined>","normalized: Record<string, string | string[] | undefined>"],"sources":["../src/instrumentation/otel.ts"],"sourcesContent":["/**\n * OpenTelemetry implementation of the Telemetry interface\n *\n * This provides automatic span creation for Lambda handlers using\n * OpenTelemetry. Works with any OTel-compatible backend (Jaeger, Zipkin,\n * Datadog, Honeycomb, etc.)\n */\nimport { type Span, trace } from '@opentelemetry/api';\nimport type { Context as LambdaContext } from 'aws-lambda';\n\n/**\n * Context object returned by onRequestStart, passed to subsequent hooks.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryContext {\n\t[key: string]: unknown;\n}\n\n/**\n * Request information passed to telemetry hooks.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryRequest {\n\tevent: any;\n\tcontext: LambdaContext;\n}\n\n/**\n * Response information passed to onRequestEnd.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface TelemetryResponse {\n\tstatusCode: number;\n\tbody?: string;\n\theaders?: Record<string, string>;\n}\n\n/**\n * Telemetry interface for instrumenting endpoint requests.\n * This matches the Telemetry interface from @geekmidas/constructs.\n */\nexport interface Telemetry {\n\tonRequestStart(request: TelemetryRequest): TelemetryContext;\n\tonRequestEnd(ctx: TelemetryContext, response: TelemetryResponse): void;\n\tonRequestError(ctx: TelemetryContext, error: Error): void;\n}\n\nimport {\n\tcreateHttpServerSpan,\n\tendHttpSpan,\n\textractTraceContext,\n\ttype HttpSpanAttributes,\n} from './http';\n\n/**\n * Options for OTelTelemetry\n */\nexport interface OTelTelemetryOptions {\n\t/**\n\t * Whether to record request body as span attribute\n\t * @default false\n\t */\n\trecordBody?: boolean;\n\n\t/**\n\t * Whether to record response body as span attribute\n\t * @default false\n\t */\n\trecordResponseBody?: boolean;\n\n\t/**\n\t * Custom function to extract user ID from event\n\t */\n\tgetUserId?: (event: any) => string | undefined;\n\n\t/**\n\t * Custom function to extract endpoint name from event\n\t */\n\tgetEndpointName?: (event: any) => string | undefined;\n\n\t/**\n\t * Custom function to extract operation ID from event\n\t */\n\tgetOperationId?: (event: any) => string | undefined;\n}\n\n/**\n * Telemetry context with span reference\n */\ninterface OTelContext extends TelemetryContext {\n\tspan: Span;\n\totelContext: any;\n}\n\n/**\n * OpenTelemetry implementation of the Telemetry interface\n *\n * @example\n * ```typescript\n * import { OTelTelemetry } from '@geekmidas/telescope/instrumentation';\n *\n * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n * telemetry: new OTelTelemetry(),\n * });\n * ```\n *\n * @example With options\n * ```typescript\n * const adaptor = new AmazonApiGatewayV2Endpoint(envParser, endpoint, {\n * telemetry: new OTelTelemetry({\n * recordBody: true,\n * getUserId: (event) => event.requestContext?.authorizer?.userId,\n * }),\n * });\n * ```\n */\nexport class OTelTelemetry implements Telemetry {\n\tconstructor(private options: OTelTelemetryOptions = {}) {}\n\n\tonRequestStart(request: TelemetryRequest): TelemetryContext {\n\t\tconst { event, context: lambdaContext } = request;\n\n\t\t// Extract trace context from headers\n\t\tconst headers = normalizeHeaders(event.headers || {});\n\t\tconst parentContext = extractTraceContext(headers);\n\n\t\t// Build span attributes from event\n\t\tconst attrs = this.buildSpanAttributes(event, lambdaContext);\n\n\t\t// Create the span\n\t\tconst span = createHttpServerSpan(attrs, parentContext);\n\t\tconst otelContext = trace.setSpan(parentContext, span);\n\n\t\t// Add Lambda-specific attributes\n\t\tspan.setAttribute('faas.invocation_id', lambdaContext.awsRequestId);\n\t\tspan.setAttribute('faas.name', lambdaContext.functionName);\n\n\t\t// Record body if requested\n\t\tif (this.options.recordBody && event.body) {\n\t\t\tconst bodyStr =\n\t\t\t\ttypeof event.body === 'string'\n\t\t\t\t\t? event.body\n\t\t\t\t\t: JSON.stringify(event.body);\n\t\t\tspan.setAttribute(\n\t\t\t\t'http.request.body',\n\t\t\t\tbodyStr.length > 4096 ? `${bodyStr.slice(0, 4096)}...` : bodyStr,\n\t\t\t);\n\t\t}\n\n\t\treturn { span, otelContext } as OTelContext;\n\t}\n\n\tonRequestEnd(ctx: TelemetryContext, response: TelemetryResponse): void {\n\t\tconst { span } = ctx as OTelContext;\n\n\t\tif (this.options.recordResponseBody && response.body) {\n\t\t\tspan.setAttribute(\n\t\t\t\t'http.response.body',\n\t\t\t\tresponse.body.length > 4096\n\t\t\t\t\t? `${response.body.slice(0, 4096)}...`\n\t\t\t\t\t: response.body,\n\t\t\t);\n\t\t}\n\n\t\tendHttpSpan(span, { statusCode: response.statusCode });\n\t}\n\n\tonRequestError(ctx: TelemetryContext, error: Error): void {\n\t\tconst { span } = ctx as OTelContext;\n\t\tendHttpSpan(span, { statusCode: 500 }, error);\n\t}\n\n\t/**\n\t * Build span attributes from Lambda event\n\t */\n\tprivate buildSpanAttributes(\n\t\tevent: any,\n\t\tlambdaContext: any,\n\t): HttpSpanAttributes {\n\t\t// Detect event type (API Gateway v1, v2, ALB, or direct invoke)\n\t\tconst isV2 =\n\t\t\t'requestContext' in event && 'http' in (event.requestContext || {});\n\t\tconst isV1 =\n\t\t\t'requestContext' in event &&\n\t\t\t'httpMethod' in event &&\n\t\t\t!('http' in (event.requestContext || {}));\n\n\t\tlet method = 'INVOKE';\n\t\tlet path = '/';\n\t\tlet route: string | undefined;\n\t\tlet host: string | undefined;\n\t\tlet scheme: 'http' | 'https' | undefined;\n\t\tlet userAgent: string | undefined;\n\t\tlet clientIp: string | undefined;\n\t\tlet requestId: string | undefined;\n\n\t\tif (isV2) {\n\t\t\t// API Gateway v2 (HTTP API)\n\t\t\tconst http = event.requestContext.http;\n\t\t\tmethod = http.method;\n\t\t\tpath = event.rawPath || http.path;\n\t\t\troute = event.routeKey?.replace(/^[A-Z]+\\s+/, ''); // Remove HTTP method prefix\n\t\t\thost = event.headers?.host;\n\t\t\tscheme = 'https';\n\t\t\tuserAgent = http.userAgent;\n\t\t\tclientIp = http.sourceIp;\n\t\t\trequestId = event.requestContext.requestId;\n\t\t} else if (isV1) {\n\t\t\t// API Gateway v1 (REST API)\n\t\t\tmethod = event.httpMethod;\n\t\t\tpath = event.path;\n\t\t\troute = event.resource;\n\t\t\thost = event.headers?.Host || event.headers?.host;\n\t\t\tscheme = 'https';\n\t\t\tuserAgent =\n\t\t\t\tevent.headers?.['User-Agent'] || event.headers?.['user-agent'];\n\t\t\tclientIp = event.requestContext?.identity?.sourceIp;\n\t\t\trequestId = event.requestContext?.requestId;\n\t\t} else if ('httpMethod' in event) {\n\t\t\t// ALB event\n\t\t\tmethod = event.httpMethod;\n\t\t\tpath = event.path;\n\t\t\thost = event.headers?.host;\n\t\t\tuserAgent =\n\t\t\t\tevent.headers?.['user-agent'] || event.headers?.['User-Agent'];\n\t\t\tclientIp = event.headers?.['x-forwarded-for']?.split(',')[0]?.trim();\n\t\t}\n\n\t\tconst attrs: HttpSpanAttributes = {\n\t\t\tmethod,\n\t\t\tpath,\n\t\t\troute,\n\t\t\thost,\n\t\t\tscheme,\n\t\t\tuserAgent,\n\t\t\tclientIp,\n\t\t\trequestId: requestId || lambdaContext.awsRequestId,\n\t\t};\n\n\t\t// Add endpoint metadata if extractors provided\n\t\tif (this.options.getEndpointName || this.options.getOperationId) {\n\t\t\tattrs.endpoint = {\n\t\t\t\tname: this.options.getEndpointName?.(event),\n\t\t\t\toperationId: this.options.getOperationId?.(event),\n\t\t\t};\n\t\t}\n\n\t\t// Add user metadata if extractor provided\n\t\tif (this.options.getUserId) {\n\t\t\tconst userId = this.options.getUserId(event);\n\t\t\tif (userId) {\n\t\t\t\tattrs.user = { userId };\n\t\t\t}\n\t\t}\n\n\t\treturn attrs;\n\t}\n}\n\n/**\n * Normalize headers to lowercase keys\n */\nfunction normalizeHeaders(\n\theaders: Record<string, string | string[] | undefined>,\n): Record<string, string | string[] | undefined> {\n\tconst normalized: Record<string, string | string[] | undefined> = {};\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tnormalized[key.toLowerCase()] = value;\n\t}\n\treturn normalized;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,IAAa,gBAAb,MAAgD;CAC/C,YAAoBA,UAAgC,CAAE,GAAE;EAApC;CAAsC;CAE1D,eAAeC,SAA6C;EAC3D,MAAM,EAAE,OAAO,SAAS,eAAe,GAAG;EAG1C,MAAM,UAAU,iBAAiB,MAAM,WAAW,CAAE,EAAC;EACrD,MAAM,gBAAgB,iCAAoB,QAAQ;EAGlD,MAAM,QAAQ,KAAK,oBAAoB,OAAO,cAAc;EAG5D,MAAM,OAAO,kCAAqB,OAAO,cAAc;EAC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KAAK;AAChB,eAAY,MAAM,eAAe;EACjC,WAAU,MAAM;AAEhB,YAAS,MAAM;AACf,UAAO,MAAM;AACb,WAAQ,MAAM;AACd,UAAO,MAAM,SAAS,QAAQ,MAAM,SAAS;AAC7C,YAAS;AACT,eACC,MAAM,UAAU,iBAAiB,MAAM,UAAU;AAClD,cAAW,MAAM,gBAAgB,UAAU;AAC3C,eAAY,MAAM,gBAAgB;EAClC,WAAU,gBAAgB,OAAO;AAEjC,YAAS,MAAM;AACf,UAAO,MAAM;AACb,UAAO,MAAM,SAAS;AACtB,eACC,MAAM,UAAU,iBAAiB,MAAM,UAAU;AAClD,cAAW,MAAM,UAAU,oBAAoB,MAAM,IAAI,CAAC,IAAI,MAAM;EACpE;EAED,MAAMC,QAA4B;GACjC;GACA;GACA;GACA;GACA;GACA;GACA;GACA,WAAW,aAAa,cAAc;EACtC;AAGD,MAAI,KAAK,QAAQ,mBAAmB,KAAK,QAAQ,eAChD,OAAM,WAAW;GAChB,MAAM,KAAK,QAAQ,kBAAkB,MAAM;GAC3C,aAAa,KAAK,QAAQ,iBAAiB,MAAM;EACjD;AAIF,MAAI,KAAK,QAAQ,WAAW;GAC3B,MAAM,SAAS,KAAK,QAAQ,UAAU,MAAM;AAC5C,OAAI,OACH,OAAM,OAAO,EAAE,OAAQ;EAExB;AAED,SAAO;CACP;AACD;;;;AAKD,SAAS,iBACRC,SACgD;CAChD,MAAMC,aAA4D,CAAE;AACpE,MAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,QAAQ,CACjD,YAAW,IAAI,aAAa,IAAI;AAEjC,QAAO;AACP"}
|
package/dist/otlp/hono.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
-
require('../types-
|
|
3
|
-
require('../transformer-
|
|
4
|
-
const require_receiver = require('../receiver-
|
|
2
|
+
require('../types-BMiHgsi4.cjs');
|
|
3
|
+
require('../transformer-Csl6fbgv.cjs');
|
|
4
|
+
const require_receiver = require('../receiver-slCoAFat.cjs');
|
|
5
5
|
const hono = require_chunk.__toESM(require("hono"));
|
|
6
6
|
|
|
7
7
|
//#region src/otlp/hono.ts
|
package/dist/otlp/hono.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import "../transformer-
|
|
3
|
-
import { OTLPReceiver } from "../receiver-
|
|
1
|
+
import "../types-Cj59nqy7.mjs";
|
|
2
|
+
import "../transformer-CFQ4WFk6.mjs";
|
|
3
|
+
import { OTLPReceiver } from "../receiver-D46dfkYI.mjs";
|
|
4
4
|
import { Hono } from "hono";
|
|
5
5
|
|
|
6
6
|
//#region src/otlp/hono.ts
|
package/dist/otlp/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const require_types = require('../types-
|
|
2
|
-
const require_transformer = require('../transformer-
|
|
3
|
-
const require_receiver = require('../receiver-
|
|
1
|
+
const require_types = require('../types-BMiHgsi4.cjs');
|
|
2
|
+
const require_transformer = require('../transformer-Csl6fbgv.cjs');
|
|
3
|
+
const require_receiver = require('../receiver-slCoAFat.cjs');
|
|
4
4
|
|
|
5
5
|
exports.OTLPReceiver = require_receiver.OTLPReceiver;
|
|
6
6
|
exports.SeverityNumber = require_types.SeverityNumber;
|
package/dist/otlp/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SeverityNumber, SpanKind, SpanStatusCode } from "../types-
|
|
2
|
-
import { transformLogs, transformMetrics, transformTraces } from "../transformer-
|
|
3
|
-
import { OTLPReceiver } from "../receiver-
|
|
1
|
+
import { SeverityNumber, SpanKind, SpanStatusCode } from "../types-Cj59nqy7.mjs";
|
|
2
|
+
import { transformLogs, transformMetrics, transformTraces } from "../transformer-CFQ4WFk6.mjs";
|
|
3
|
+
import { OTLPReceiver } from "../receiver-D46dfkYI.mjs";
|
|
4
4
|
|
|
5
5
|
export { OTLPReceiver, SeverityNumber, SpanKind, SpanStatusCode, transformLogs, transformMetrics, transformTraces };
|
package/dist/otlp/receiver.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require('../types-
|
|
2
|
-
require('../transformer-
|
|
3
|
-
const require_receiver = require('../receiver-
|
|
1
|
+
require('../types-BMiHgsi4.cjs');
|
|
2
|
+
require('../transformer-Csl6fbgv.cjs');
|
|
3
|
+
const require_receiver = require('../receiver-slCoAFat.cjs');
|
|
4
4
|
|
|
5
5
|
exports.OTLPReceiver = require_receiver.OTLPReceiver;
|
package/dist/otlp/receiver.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import "../transformer-
|
|
3
|
-
import { OTLPReceiver } from "../receiver-
|
|
1
|
+
import "../types-Cj59nqy7.mjs";
|
|
2
|
+
import "../transformer-CFQ4WFk6.mjs";
|
|
3
|
+
import { OTLPReceiver } from "../receiver-D46dfkYI.mjs";
|
|
4
4
|
|
|
5
5
|
export { OTLPReceiver };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require('../types-
|
|
2
|
-
const require_transformer = require('../transformer-
|
|
1
|
+
require('../types-BMiHgsi4.cjs');
|
|
2
|
+
const require_transformer = require('../transformer-Csl6fbgv.cjs');
|
|
3
3
|
|
|
4
4
|
exports.transformLogs = require_transformer.transformLogs;
|
|
5
5
|
exports.transformMetrics = require_transformer.transformMetrics;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { transformLogs, transformMetrics, transformTraces } from "../transformer-
|
|
1
|
+
import "../types-Cj59nqy7.mjs";
|
|
2
|
+
import { transformLogs, transformMetrics, transformTraces } from "../transformer-CFQ4WFk6.mjs";
|
|
3
3
|
|
|
4
4
|
export { transformLogs, transformMetrics, transformTraces };
|
package/dist/otlp/types.cjs
CHANGED
package/dist/otlp/types.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AggregationTemporality, SeverityNumber, SpanKind, SpanStatusCode } from "../types-
|
|
1
|
+
import { AggregationTemporality, SeverityNumber, SpanKind, SpanStatusCode } from "../types-Cj59nqy7.mjs";
|
|
2
2
|
|
|
3
3
|
export { AggregationTemporality, SeverityNumber, SpanKind, SpanStatusCode };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { transformLogs, transformMetrics, transformTraces } from "./transformer-
|
|
1
|
+
import { transformLogs, transformMetrics, transformTraces } from "./transformer-CFQ4WFk6.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/otlp/receiver.ts
|
|
4
4
|
/**
|
|
@@ -86,4 +86,4 @@ var OTLPReceiver = class {
|
|
|
86
86
|
|
|
87
87
|
//#endregion
|
|
88
88
|
export { OTLPReceiver };
|
|
89
|
-
//# sourceMappingURL=receiver-
|
|
89
|
+
//# sourceMappingURL=receiver-D46dfkYI.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"receiver-
|
|
1
|
+
{"version":3,"file":"receiver-D46dfkYI.mjs","names":["options: OTLPReceiverOptions","request: ExportTraceServiceRequest","request: ExportLogsServiceRequest","request: ExportMetricsServiceRequest"],"sources":["../src/otlp/receiver.ts"],"sourcesContent":["import type { Telescope } from '../Telescope';\nimport {\n\ttype MetricDataPoint,\n\ttransformLogs,\n\ttransformMetrics,\n\ttransformTraces,\n} from './transformer';\nimport type {\n\tExportLogsServiceRequest,\n\tExportLogsServiceResponse,\n\tExportMetricsServiceRequest,\n\tExportMetricsServiceResponse,\n\tExportTraceServiceRequest,\n\tExportTraceServiceResponse,\n} from './types';\n\n/**\n * Callback for handling OTLP metrics\n */\nexport type MetricsHandler = (\n\tpoints: MetricDataPoint[],\n) => void | Promise<void>;\n\n/**\n * Options for OTLPReceiver\n */\nexport interface OTLPReceiverOptions {\n\t/**\n\t * The Telescope instance to record data to\n\t */\n\ttelescope: Telescope;\n\n\t/**\n\t * Optional callback for handling OTLP metrics.\n\t * OTLP metrics are more granular than Telescope's request metrics,\n\t * so a custom handler allows integration with metrics systems like Prometheus.\n\t */\n\tonMetrics?: MetricsHandler;\n\n\t/**\n\t * Whether to also log OTLP metrics to Telescope as log entries.\n\t * Useful for debugging OTLP integration. Default: false\n\t */\n\tlogMetrics?: boolean;\n}\n\n/**\n * OTLP Receiver for ingesting OpenTelemetry data into Telescope.\n *\n * Supports the OTLP/JSON protocol for:\n * - Traces (POST /v1/traces) - HTTP server spans become RequestEntries\n * - Logs (POST /v1/logs) - Log records become LogEntries\n * - Metrics (POST /v1/metrics) - Metrics can be forwarded to custom handlers\n */\nexport class OTLPReceiver {\n\tprivate telescope: Telescope;\n\tprivate onMetrics?: MetricsHandler;\n\tprivate logMetrics: boolean;\n\n\tconstructor(options: OTLPReceiverOptions) {\n\t\tthis.telescope = options.telescope;\n\t\tthis.onMetrics = options.onMetrics;\n\t\tthis.logMetrics = options.logMetrics ?? false;\n\t}\n\n\t/**\n\t * Handle incoming trace data\n\t * Transforms HTTP server spans to Telescope request entries\n\t */\n\tasync receiveTraces(\n\t\trequest: ExportTraceServiceRequest,\n\t): Promise<ExportTraceServiceResponse> {\n\t\tconst entries = transformTraces(request);\n\t\tlet rejected = 0;\n\n\t\tfor (const entry of entries) {\n\t\t\ttry {\n\t\t\t\tawait this.telescope.recordRequest(entry);\n\t\t\t} catch {\n\t\t\t\trejected++;\n\t\t\t}\n\t\t}\n\n\t\treturn rejected > 0\n\t\t\t? { partialSuccess: { rejectedSpans: String(rejected) } }\n\t\t\t: {};\n\t}\n\n\t/**\n\t * Handle incoming log data\n\t * Transforms OTLP log records to Telescope log entries\n\t */\n\tasync receiveLogs(\n\t\trequest: ExportLogsServiceRequest,\n\t): Promise<ExportLogsServiceResponse> {\n\t\tconst entries = transformLogs(request);\n\t\tlet rejected = 0;\n\n\t\t// Batch log entries for efficiency\n\t\tconst batchEntries = entries.map((entry) => ({\n\t\t\tlevel: entry.level,\n\t\t\tmessage: entry.message,\n\t\t\tcontext: entry.context,\n\t\t\trequestId: entry.requestId,\n\t\t}));\n\n\t\ttry {\n\t\t\tawait this.telescope.log(batchEntries);\n\t\t} catch {\n\t\t\trejected = entries.length;\n\t\t}\n\n\t\treturn rejected > 0\n\t\t\t? { partialSuccess: { rejectedLogRecords: String(rejected) } }\n\t\t\t: {};\n\t}\n\n\t/**\n\t * Handle incoming metrics data\n\t * Forwards to custom handler and optionally logs to Telescope\n\t */\n\tasync receiveMetrics(\n\t\trequest: ExportMetricsServiceRequest,\n\t): Promise<ExportMetricsServiceResponse> {\n\t\tconst points = transformMetrics(request);\n\t\tlet rejected = 0;\n\n\t\t// Forward to custom metrics handler\n\t\tif (this.onMetrics) {\n\t\t\ttry {\n\t\t\t\tawait this.onMetrics(points);\n\t\t\t} catch {\n\t\t\t\trejected = points.length;\n\t\t\t}\n\t\t}\n\n\t\t// Optionally log metrics to Telescope for debugging\n\t\tif (this.logMetrics && points.length > 0) {\n\t\t\tconst logEntries = points.map((point) => ({\n\t\t\t\tlevel: 'debug' as const,\n\t\t\t\tmessage: `OTLP Metric: ${point.name}`,\n\t\t\t\tcontext: {\n\t\t\t\t\tname: point.name,\n\t\t\t\t\tvalue: point.value,\n\t\t\t\t\ttype: point.type,\n\t\t\t\t\tunit: point.unit,\n\t\t\t\t\tattributes: point.attributes,\n\t\t\t\t},\n\t\t\t}));\n\n\t\t\ttry {\n\t\t\t\tawait this.telescope.log(logEntries);\n\t\t\t} catch {\n\t\t\t\t// Ignore logging errors\n\t\t\t}\n\t\t}\n\n\t\treturn rejected > 0\n\t\t\t? { partialSuccess: { rejectedDataPoints: String(rejected) } }\n\t\t\t: {};\n\t}\n}\n"],"mappings":";;;;;;;;;;;AAsDA,IAAa,eAAb,MAA0B;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,YAAYA,SAA8B;AACzC,OAAK,YAAY,QAAQ;AACzB,OAAK,YAAY,QAAQ;AACzB,OAAK,aAAa,QAAQ,cAAc;CACxC;;;;;CAMD,MAAM,cACLC,SACsC;EACtC,MAAM,UAAU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./transformer-
|
|
1
|
+
const require_transformer = require('./transformer-Csl6fbgv.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/otlp/receiver.ts
|
|
4
4
|
/**
|
|
@@ -91,4 +91,4 @@ Object.defineProperty(exports, 'OTLPReceiver', {
|
|
|
91
91
|
return OTLPReceiver;
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
|
-
//# sourceMappingURL=receiver-
|
|
94
|
+
//# sourceMappingURL=receiver-slCoAFat.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"receiver-
|
|
1
|
+
{"version":3,"file":"receiver-slCoAFat.cjs","names":["options: OTLPReceiverOptions","request: ExportTraceServiceRequest","request: ExportLogsServiceRequest","request: ExportMetricsServiceRequest"],"sources":["../src/otlp/receiver.ts"],"sourcesContent":["import type { Telescope } from '../Telescope';\nimport {\n\ttype MetricDataPoint,\n\ttransformLogs,\n\ttransformMetrics,\n\ttransformTraces,\n} from './transformer';\nimport type {\n\tExportLogsServiceRequest,\n\tExportLogsServiceResponse,\n\tExportMetricsServiceRequest,\n\tExportMetricsServiceResponse,\n\tExportTraceServiceRequest,\n\tExportTraceServiceResponse,\n} from './types';\n\n/**\n * Callback for handling OTLP metrics\n */\nexport type MetricsHandler = (\n\tpoints: MetricDataPoint[],\n) => void | Promise<void>;\n\n/**\n * Options for OTLPReceiver\n */\nexport interface OTLPReceiverOptions {\n\t/**\n\t * The Telescope instance to record data to\n\t */\n\ttelescope: Telescope;\n\n\t/**\n\t * Optional callback for handling OTLP metrics.\n\t * OTLP metrics are more granular than Telescope's request metrics,\n\t * so a custom handler allows integration with metrics systems like Prometheus.\n\t */\n\tonMetrics?: MetricsHandler;\n\n\t/**\n\t * Whether to also log OTLP metrics to Telescope as log entries.\n\t * Useful for debugging OTLP integration. Default: false\n\t */\n\tlogMetrics?: boolean;\n}\n\n/**\n * OTLP Receiver for ingesting OpenTelemetry data into Telescope.\n *\n * Supports the OTLP/JSON protocol for:\n * - Traces (POST /v1/traces) - HTTP server spans become RequestEntries\n * - Logs (POST /v1/logs) - Log records become LogEntries\n * - Metrics (POST /v1/metrics) - Metrics can be forwarded to custom handlers\n */\nexport class OTLPReceiver {\n\tprivate telescope: Telescope;\n\tprivate onMetrics?: MetricsHandler;\n\tprivate logMetrics: boolean;\n\n\tconstructor(options: OTLPReceiverOptions) {\n\t\tthis.telescope = options.telescope;\n\t\tthis.onMetrics = options.onMetrics;\n\t\tthis.logMetrics = options.logMetrics ?? false;\n\t}\n\n\t/**\n\t * Handle incoming trace data\n\t * Transforms HTTP server spans to Telescope request entries\n\t */\n\tasync receiveTraces(\n\t\trequest: ExportTraceServiceRequest,\n\t): Promise<ExportTraceServiceResponse> {\n\t\tconst entries = transformTraces(request);\n\t\tlet rejected = 0;\n\n\t\tfor (const entry of entries) {\n\t\t\ttry {\n\t\t\t\tawait this.telescope.recordRequest(entry);\n\t\t\t} catch {\n\t\t\t\trejected++;\n\t\t\t}\n\t\t}\n\n\t\treturn rejected > 0\n\t\t\t? { partialSuccess: { rejectedSpans: String(rejected) } }\n\t\t\t: {};\n\t}\n\n\t/**\n\t * Handle incoming log data\n\t * Transforms OTLP log records to Telescope log entries\n\t */\n\tasync receiveLogs(\n\t\trequest: ExportLogsServiceRequest,\n\t): Promise<ExportLogsServiceResponse> {\n\t\tconst entries = transformLogs(request);\n\t\tlet rejected = 0;\n\n\t\t// Batch log entries for efficiency\n\t\tconst batchEntries = entries.map((entry) => ({\n\t\t\tlevel: entry.level,\n\t\t\tmessage: entry.message,\n\t\t\tcontext: entry.context,\n\t\t\trequestId: entry.requestId,\n\t\t}));\n\n\t\ttry {\n\t\t\tawait this.telescope.log(batchEntries);\n\t\t} catch {\n\t\t\trejected = entries.length;\n\t\t}\n\n\t\treturn rejected > 0\n\t\t\t? { partialSuccess: { rejectedLogRecords: String(rejected) } }\n\t\t\t: {};\n\t}\n\n\t/**\n\t * Handle incoming metrics data\n\t * Forwards to custom handler and optionally logs to Telescope\n\t */\n\tasync receiveMetrics(\n\t\trequest: ExportMetricsServiceRequest,\n\t): Promise<ExportMetricsServiceResponse> {\n\t\tconst points = transformMetrics(request);\n\t\tlet rejected = 0;\n\n\t\t// Forward to custom metrics handler\n\t\tif (this.onMetrics) {\n\t\t\ttry {\n\t\t\t\tawait this.onMetrics(points);\n\t\t\t} catch {\n\t\t\t\trejected = points.length;\n\t\t\t}\n\t\t}\n\n\t\t// Optionally log metrics to Telescope for debugging\n\t\tif (this.logMetrics && points.length > 0) {\n\t\t\tconst logEntries = points.map((point) => ({\n\t\t\t\tlevel: 'debug' as const,\n\t\t\t\tmessage: `OTLP Metric: ${point.name}`,\n\t\t\t\tcontext: {\n\t\t\t\t\tname: point.name,\n\t\t\t\t\tvalue: point.value,\n\t\t\t\t\ttype: point.type,\n\t\t\t\t\tunit: point.unit,\n\t\t\t\t\tattributes: point.attributes,\n\t\t\t\t},\n\t\t\t}));\n\n\t\t\ttry {\n\t\t\t\tawait this.telescope.log(logEntries);\n\t\t\t} catch {\n\t\t\t\t// Ignore logging errors\n\t\t\t}\n\t\t}\n\n\t\treturn rejected > 0\n\t\t\t? { partialSuccess: { rejectedDataPoints: String(rejected) } }\n\t\t\t: {};\n\t}\n}\n"],"mappings":";;;;;;;;;;;AAsDA,IAAa,eAAb,MAA0B;CACzB,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,YAAYA,SAA8B;AACzC,OAAK,YAAY,QAAQ;AACzB,OAAK,YAAY,QAAQ;AACzB,OAAK,aAAa,QAAQ,cAAc;CACxC;;;;;CAMD,MAAM,cACLC,SACsC;EACtC,MAAM,UAAU,oCAAgB,QAAQ;EACxC,IAAI,WAAW;AAEf,OAAK,MAAM,SAAS,QACnB,KAAI;AACH,SAAM,KAAK,UAAU,cAAc,MAAM;EACzC,QAAO;AACP;EACA;AAGF,SAAO,WAAW,IACf,EAAE,gBAAgB,EAAE,eAAe,OAAO,SAAS,CAAE,EAAE,IACvD,CAAE;CACL;;;;;CAMD,MAAM,YACLC,SACqC;EACrC,MAAM,UAAU,kCAAc,QAAQ;EACtC,IAAI,WAAW;EAGf,MAAM,eAAe,QAAQ,IAAI,CAAC,WAAW;GAC5C,OAAO,MAAM;GACb,SAAS,MAAM;GACf,SAAS,MAAM;GACf,WAAW,MAAM;EACjB,GAAE;AAEH,MAAI;AACH,SAAM,KAAK,UAAU,IAAI,aAAa;EACtC,QAAO;AACP,cAAW,QAAQ;EACnB;AAED,SAAO,WAAW,IACf,EAAE,gBAAgB,EAAE,oBAAoB,OAAO,SAAS,CAAE,EAAE,IAC5D,CAAE;CACL;;;;;CAMD,MAAM,eACLC,SACwC;EACxC,MAAM,SAAS,qCAAiB,QAAQ;EACxC,IAAI,WAAW;AAGf,MAAI,KAAK,UACR,KAAI;AACH,SAAM,KAAK,UAAU,OAAO;EAC5B,QAAO;AACP,cAAW,OAAO;EAClB;AAIF,MAAI,KAAK,cAAc,OAAO,SAAS,GAAG;GACzC,MAAM,aAAa,OAAO,IAAI,CAAC,WAAW;IACzC,OAAO;IACP,UAAU,eAAe,MAAM,KAAK;IACpC,SAAS;KACR,MAAM,MAAM;KACZ,OAAO,MAAM;KACb,MAAM,MAAM;KACZ,MAAM,MAAM;KACZ,YAAY,MAAM;IAClB;GACD,GAAE;AAEH,OAAI;AACH,UAAM,KAAK,UAAU,IAAI,WAAW;GACpC,QAAO,CAEP;EACD;AAED,SAAO,WAAW,IACf,EAAE,gBAAgB,EAAE,oBAAoB,OAAO,SAAS,CAAE,EAAE,IAC5D,CAAE;CACL;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-
|
|
1
|
+
{"version":3,"file":"setup-DC9JMEYZ.mjs","names":["sdk: NodeSDK | null","options: TelemetryOptions","traceExporter: SpanExporter"],"sources":["../src/instrumentation/setup.ts"],"sourcesContent":["import { DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\nimport { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';\nimport { Resource } from '@opentelemetry/resources';\nimport {\n\tBatchLogRecordProcessor,\n\tLoggerProvider,\n} from '@opentelemetry/sdk-logs';\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport {\n\tConsoleSpanExporter,\n\ttype SpanExporter,\n} from '@opentelemetry/sdk-trace-node';\nimport {\n\tATTR_SERVICE_NAME,\n\tATTR_SERVICE_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport type { SpanProcessorStrategy } from '../adapters/types';\nimport {\n\tcreateSpanProcessor,\n\tgetRecommendedStrategy,\n\tsetGlobalLogProcessor,\n\tsetGlobalSpanProcessor,\n} from './core';\n\n/**\n * Options for configuring telemetry\n */\nexport interface TelemetryOptions {\n\t/**\n\t * Service name for resource identification\n\t */\n\tserviceName: string;\n\n\t/**\n\t * Service version\n\t */\n\tserviceVersion?: string;\n\n\t/**\n\t * OTLP endpoint URL (e.g., 'http://localhost:3000/__telescope/v1')\n\t * If not provided, traces will be logged to console\n\t */\n\tendpoint?: string;\n\n\t/**\n\t * Whether to instrument Pino for log correlation\n\t * @default true\n\t */\n\tinstrumentPino?: boolean;\n\n\t/**\n\t * Whether to enable auto-instrumentation for common libraries\n\t * (http, fetch, express, etc.)\n\t * @default true\n\t */\n\tautoInstrument?: boolean;\n\n\t/**\n\t * Enable debug logging for OTel SDK\n\t * @default false\n\t */\n\tdebug?: boolean;\n\n\t/**\n\t * Additional resource attributes\n\t */\n\tresourceAttributes?: Record<string, string>;\n\n\t/**\n\t * Headers to send with OTLP requests\n\t */\n\theaders?: Record<string, string>;\n\n\t/**\n\t * Span processor strategy.\n\t * - 'batch': Efficient batching for long-running servers (default)\n\t * - 'simple': Immediate export for serverless environments (Lambda, Edge)\n\t *\n\t * If not specified, automatically selected based on environment detection.\n\t */\n\tspanProcessorStrategy?: SpanProcessorStrategy;\n\n\t/**\n\t * Environment type for automatic configuration\n\t * @default 'server'\n\t */\n\tenvironment?: 'server' | 'lambda' | 'edge' | 'custom';\n}\n\nlet sdk: NodeSDK | null = null;\n\n/**\n * Set up OpenTelemetry instrumentation.\n * Call this BEFORE importing your application code.\n *\n * @example\n * ```typescript\n * // instrumentation.ts (create this file)\n * import { setupTelemetry } from '@geekmidas/telescope/instrumentation';\n *\n * setupTelemetry({\n * serviceName: 'my-api',\n * endpoint: 'http://localhost:3000/__telescope/v1',\n * });\n *\n * // Then in your entry point:\n * // import './instrumentation';\n * // import { app } from './app';\n * ```\n */\nexport function setupTelemetry(options: TelemetryOptions): void {\n\tif (sdk) {\n\t\treturn;\n\t}\n\n\tconst {\n\t\tserviceName,\n\t\tserviceVersion = '1.0.0',\n\t\tendpoint,\n\t\tinstrumentPino = true,\n\t\tautoInstrument = true,\n\t\tdebug = false,\n\t\tresourceAttributes = {},\n\t\theaders = {},\n\t\tspanProcessorStrategy,\n\t\tenvironment = 'server',\n\t} = options;\n\n\t// Enable debug logging if requested\n\tif (debug) {\n\t\tdiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);\n\t}\n\n\t// Create resource\n\tconst resource = new Resource({\n\t\t[ATTR_SERVICE_NAME]: serviceName,\n\t\t[ATTR_SERVICE_VERSION]: serviceVersion,\n\t\t...resourceAttributes,\n\t});\n\n\t// Build instrumentations list\n\tconst instrumentations = [];\n\n\t// Add Pino instrumentation for log correlation\n\tif (instrumentPino) {\n\t\tinstrumentations.push(\n\t\t\tnew PinoInstrumentation({\n\t\t\t\t// Inject trace context into log records\n\t\t\t\tlogHook: (span, record) => {\n\t\t\t\t\trecord.trace_id = span.spanContext().traceId;\n\t\t\t\t\trecord.span_id = span.spanContext().spanId;\n\t\t\t\t\trecord.trace_flags = span.spanContext().traceFlags;\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Add auto-instrumentations for common libraries\n\tif (autoInstrument) {\n\t\tinstrumentations.push(\n\t\t\tgetNodeAutoInstrumentations({\n\t\t\t\t// Disable file system instrumentation (too noisy)\n\t\t\t\t'@opentelemetry/instrumentation-fs': { enabled: false },\n\t\t\t\t// Configure HTTP instrumentation\n\t\t\t\t'@opentelemetry/instrumentation-http': {\n\t\t\t\t\tignoreIncomingRequestHook: (request) => {\n\t\t\t\t\t\t// Ignore health checks and internal routes\n\t\t\t\t\t\tconst path = request.url || '';\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tpath.includes('/__health') ||\n\t\t\t\t\t\t\tpath.includes('/__telescope') ||\n\t\t\t\t\t\t\tpath.includes('/favicon')\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Create exporters\n\tlet traceExporter: SpanExporter;\n\tif (endpoint) {\n\t\ttraceExporter = new OTLPTraceExporter({\n\t\t\turl: `${endpoint}/traces`,\n\t\t\theaders,\n\t\t});\n\t} else {\n\t\t// Fall back to console exporter for debugging\n\t\ttraceExporter = new ConsoleSpanExporter();\n\t}\n\n\t// Determine span processor strategy\n\tconst strategy = spanProcessorStrategy ?? getRecommendedStrategy(environment);\n\tconst spanProcessor = createSpanProcessor(traceExporter, { strategy });\n\n\t// Register globally for flush operations\n\tsetGlobalSpanProcessor(spanProcessor);\n\n\t// Create and configure SDK\n\tsdk = new NodeSDK({\n\t\tresource,\n\t\ttraceExporter,\n\t\tspanProcessors: [spanProcessor],\n\t\tinstrumentations,\n\t});\n\n\t// Set up log exporter if endpoint is provided\n\tif (endpoint) {\n\t\tconst logExporter = new OTLPLogExporter({\n\t\t\turl: `${endpoint}/logs`,\n\t\t\theaders,\n\t\t});\n\n\t\tconst loggerProvider = new LoggerProvider({ resource });\n\t\tconst logProcessor = new BatchLogRecordProcessor(logExporter);\n\t\tloggerProvider.addLogRecordProcessor(logProcessor);\n\n\t\t// Register for flush operations\n\t\tsetGlobalLogProcessor(logProcessor);\n\t}\n\n\t// Start the SDK\n\tsdk.start();\n\n\t// Graceful shutdown\n\tprocess.on('SIGTERM', () => {\n\t\tsdk\n\t\t\t?.shutdown()\n\t\t\t.then(() => {})\n\t\t\t.catch((_error) => {})\n\t\t\t.finally(() => process.exit(0));\n\t});\n}\n\n/**\n * Shut down telemetry (for testing or graceful shutdown)\n */\nexport async function shutdownTelemetry(): Promise<void> {\n\tif (sdk) {\n\t\tawait sdk.shutdown();\n\t\tsdk = null;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AA4FA,IAAIA,MAAsB;;;;;;;;;;;;;;;;;;;;AAqB1B,SAAgB,eAAeC,SAAiC;AAC/D,KAAI,IACH;CAGD,MAAM,EACL,aACA,iBAAiB,SACjB,UACA,iBAAiB,MACjB,iBAAiB,MACjB,QAAQ,OACR,qBAAqB,CAAE,GACvB,UAAU,CAAE,GACZ,uBACA,cAAc,UACd,GAAG;AAGJ,KAAI,MACH,MAAK,UAAU,IAAI,qBAAqB,aAAa,MAAM;CAI5D,MAAM,WAAW,IAAI,SAAS;GAC5B,oBAAoB;GACpB,uBAAuB;EACxB,GAAG;CACH;CAGD,MAAM,mBAAmB,CAAE;AAG3B,KAAI,eACH,kBAAiB,KAChB,IAAI,oBAAoB,EAEvB,SAAS,CAAC,MAAM,WAAW;AAC1B,SAAO,WAAW,KAAK,aAAa,CAAC;AACrC,SAAO,UAAU,KAAK,aAAa,CAAC;AACpC,SAAO,cAAc,KAAK,aAAa,CAAC;CACxC,EACD,GACD;AAIF,KAAI,eACH,kBAAiB,KAChB,4BAA4B;EAE3B,qCAAqC,EAAE,SAAS,MAAO;EAEvD,uCAAuC,EACtC,2BAA2B,CAAC,YAAY;GAEvC,MAAM,OAAO,QAAQ,OAAO;AAC5B,UACC,KAAK,SAAS,YAAY,IAC1B,KAAK,SAAS,eAAe,IAC7B,KAAK,SAAS,WAAW;EAE1B,EACD;CACD,EAAC,CACF;CAIF,IAAIC;AACJ,KAAI,SACH,iBAAgB,IAAI,kBAAkB;EACrC,MAAM,EAAE,SAAS;EACjB;CACA;KAGD,iBAAgB,IAAI;CAIrB,MAAM,WAAW,yBAAyB,uBAAuB,YAAY;CAC7E,MAAM,gBAAgB,oBAAoB,eAAe,EAAE,SAAU,EAAC;AAGtE,wBAAuB,cAAc;AAGrC,OAAM,IAAI,QAAQ;EACjB;EACA;EACA,gBAAgB,CAAC,aAAc;EAC/B;CACA;AAGD,KAAI,UAAU;EACb,MAAM,cAAc,IAAI,gBAAgB;GACvC,MAAM,EAAE,SAAS;GACjB;EACA;EAED,MAAM,iBAAiB,IAAI,eAAe,EAAE,SAAU;EACtD,MAAM,eAAe,IAAI,wBAAwB;AACjD,iBAAe,sBAAsB,aAAa;AAGlD,wBAAsB,aAAa;CACnC;AAGD,KAAI,OAAO;AAGX,SAAQ,GAAG,WAAW,MAAM;AAC3B,OACG,UAAU,CACX,KAAK,MAAM,CAAE,EAAC,CACd,MAAM,CAAC,WAAW,CAAE,EAAC,CACrB,QAAQ,MAAM,QAAQ,KAAK,EAAE,CAAC;CAChC,EAAC;AACF;;;;AAKD,eAAsB,oBAAmC;AACxD,KAAI,KAAK;AACR,QAAM,IAAI,UAAU;AACpB,QAAM;CACN;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-
|
|
1
|
+
{"version":3,"file":"setup-DufxQpi9.cjs","names":["sdk: NodeSDK | null","options: TelemetryOptions","DiagConsoleLogger","DiagLogLevel","Resource","ATTR_SERVICE_NAME","ATTR_SERVICE_VERSION","PinoInstrumentation","traceExporter: SpanExporter","OTLPTraceExporter","ConsoleSpanExporter","NodeSDK","OTLPLogExporter","LoggerProvider","BatchLogRecordProcessor"],"sources":["../src/instrumentation/setup.ts"],"sourcesContent":["import { DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\nimport { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';\nimport { Resource } from '@opentelemetry/resources';\nimport {\n\tBatchLogRecordProcessor,\n\tLoggerProvider,\n} from '@opentelemetry/sdk-logs';\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport {\n\tConsoleSpanExporter,\n\ttype SpanExporter,\n} from '@opentelemetry/sdk-trace-node';\nimport {\n\tATTR_SERVICE_NAME,\n\tATTR_SERVICE_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport type { SpanProcessorStrategy } from '../adapters/types';\nimport {\n\tcreateSpanProcessor,\n\tgetRecommendedStrategy,\n\tsetGlobalLogProcessor,\n\tsetGlobalSpanProcessor,\n} from './core';\n\n/**\n * Options for configuring telemetry\n */\nexport interface TelemetryOptions {\n\t/**\n\t * Service name for resource identification\n\t */\n\tserviceName: string;\n\n\t/**\n\t * Service version\n\t */\n\tserviceVersion?: string;\n\n\t/**\n\t * OTLP endpoint URL (e.g., 'http://localhost:3000/__telescope/v1')\n\t * If not provided, traces will be logged to console\n\t */\n\tendpoint?: string;\n\n\t/**\n\t * Whether to instrument Pino for log correlation\n\t * @default true\n\t */\n\tinstrumentPino?: boolean;\n\n\t/**\n\t * Whether to enable auto-instrumentation for common libraries\n\t * (http, fetch, express, etc.)\n\t * @default true\n\t */\n\tautoInstrument?: boolean;\n\n\t/**\n\t * Enable debug logging for OTel SDK\n\t * @default false\n\t */\n\tdebug?: boolean;\n\n\t/**\n\t * Additional resource attributes\n\t */\n\tresourceAttributes?: Record<string, string>;\n\n\t/**\n\t * Headers to send with OTLP requests\n\t */\n\theaders?: Record<string, string>;\n\n\t/**\n\t * Span processor strategy.\n\t * - 'batch': Efficient batching for long-running servers (default)\n\t * - 'simple': Immediate export for serverless environments (Lambda, Edge)\n\t *\n\t * If not specified, automatically selected based on environment detection.\n\t */\n\tspanProcessorStrategy?: SpanProcessorStrategy;\n\n\t/**\n\t * Environment type for automatic configuration\n\t * @default 'server'\n\t */\n\tenvironment?: 'server' | 'lambda' | 'edge' | 'custom';\n}\n\nlet sdk: NodeSDK | null = null;\n\n/**\n * Set up OpenTelemetry instrumentation.\n * Call this BEFORE importing your application code.\n *\n * @example\n * ```typescript\n * // instrumentation.ts (create this file)\n * import { setupTelemetry } from '@geekmidas/telescope/instrumentation';\n *\n * setupTelemetry({\n * serviceName: 'my-api',\n * endpoint: 'http://localhost:3000/__telescope/v1',\n * });\n *\n * // Then in your entry point:\n * // import './instrumentation';\n * // import { app } from './app';\n * ```\n */\nexport function setupTelemetry(options: TelemetryOptions): void {\n\tif (sdk) {\n\t\treturn;\n\t}\n\n\tconst {\n\t\tserviceName,\n\t\tserviceVersion = '1.0.0',\n\t\tendpoint,\n\t\tinstrumentPino = true,\n\t\tautoInstrument = true,\n\t\tdebug = false,\n\t\tresourceAttributes = {},\n\t\theaders = {},\n\t\tspanProcessorStrategy,\n\t\tenvironment = 'server',\n\t} = options;\n\n\t// Enable debug logging if requested\n\tif (debug) {\n\t\tdiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);\n\t}\n\n\t// Create resource\n\tconst resource = new Resource({\n\t\t[ATTR_SERVICE_NAME]: serviceName,\n\t\t[ATTR_SERVICE_VERSION]: serviceVersion,\n\t\t...resourceAttributes,\n\t});\n\n\t// Build instrumentations list\n\tconst instrumentations = [];\n\n\t// Add Pino instrumentation for log correlation\n\tif (instrumentPino) {\n\t\tinstrumentations.push(\n\t\t\tnew PinoInstrumentation({\n\t\t\t\t// Inject trace context into log records\n\t\t\t\tlogHook: (span, record) => {\n\t\t\t\t\trecord.trace_id = span.spanContext().traceId;\n\t\t\t\t\trecord.span_id = span.spanContext().spanId;\n\t\t\t\t\trecord.trace_flags = span.spanContext().traceFlags;\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Add auto-instrumentations for common libraries\n\tif (autoInstrument) {\n\t\tinstrumentations.push(\n\t\t\tgetNodeAutoInstrumentations({\n\t\t\t\t// Disable file system instrumentation (too noisy)\n\t\t\t\t'@opentelemetry/instrumentation-fs': { enabled: false },\n\t\t\t\t// Configure HTTP instrumentation\n\t\t\t\t'@opentelemetry/instrumentation-http': {\n\t\t\t\t\tignoreIncomingRequestHook: (request) => {\n\t\t\t\t\t\t// Ignore health checks and internal routes\n\t\t\t\t\t\tconst path = request.url || '';\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tpath.includes('/__health') ||\n\t\t\t\t\t\t\tpath.includes('/__telescope') ||\n\t\t\t\t\t\t\tpath.includes('/favicon')\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Create exporters\n\tlet traceExporter: SpanExporter;\n\tif (endpoint) {\n\t\ttraceExporter = new OTLPTraceExporter({\n\t\t\turl: `${endpoint}/traces`,\n\t\t\theaders,\n\t\t});\n\t} else {\n\t\t// Fall back to console exporter for debugging\n\t\ttraceExporter = new ConsoleSpanExporter();\n\t}\n\n\t// Determine span processor strategy\n\tconst strategy = spanProcessorStrategy ?? getRecommendedStrategy(environment);\n\tconst spanProcessor = createSpanProcessor(traceExporter, { strategy });\n\n\t// Register globally for flush operations\n\tsetGlobalSpanProcessor(spanProcessor);\n\n\t// Create and configure SDK\n\tsdk = new NodeSDK({\n\t\tresource,\n\t\ttraceExporter,\n\t\tspanProcessors: [spanProcessor],\n\t\tinstrumentations,\n\t});\n\n\t// Set up log exporter if endpoint is provided\n\tif (endpoint) {\n\t\tconst logExporter = new OTLPLogExporter({\n\t\t\turl: `${endpoint}/logs`,\n\t\t\theaders,\n\t\t});\n\n\t\tconst loggerProvider = new LoggerProvider({ resource });\n\t\tconst logProcessor = new BatchLogRecordProcessor(logExporter);\n\t\tloggerProvider.addLogRecordProcessor(logProcessor);\n\n\t\t// Register for flush operations\n\t\tsetGlobalLogProcessor(logProcessor);\n\t}\n\n\t// Start the SDK\n\tsdk.start();\n\n\t// Graceful shutdown\n\tprocess.on('SIGTERM', () => {\n\t\tsdk\n\t\t\t?.shutdown()\n\t\t\t.then(() => {})\n\t\t\t.catch((_error) => {})\n\t\t\t.finally(() => process.exit(0));\n\t});\n}\n\n/**\n * Shut down telemetry (for testing or graceful shutdown)\n */\nexport async function shutdownTelemetry(): Promise<void> {\n\tif (sdk) {\n\t\tawait sdk.shutdown();\n\t\tsdk = null;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AA4FA,IAAIA,MAAsB;;;;;;;;;;;;;;;;;;;;AAqB1B,SAAgB,eAAeC,SAAiC;AAC/D,KAAI,IACH;CAGD,MAAM,EACL,aACA,iBAAiB,SACjB,UACA,iBAAiB,MACjB,iBAAiB,MACjB,QAAQ,OACR,qBAAqB,CAAE,GACvB,UAAU,CAAE,GACZ,uBACA,cAAc,UACd,GAAG;AAGJ,KAAI,MACH,0BAAK,UAAU,IAAIC,yCAAqBC,iCAAa,MAAM;CAI5D,MAAM,WAAW,IAAIC,mCAAS;GAC5BC,yDAAoB;GACpBC,4DAAuB;EACxB,GAAG;CACH;CAGD,MAAM,mBAAmB,CAAE;AAG3B,KAAI,eACH,kBAAiB,KAChB,IAAIC,yDAAoB,EAEvB,SAAS,CAAC,MAAM,WAAW;AAC1B,SAAO,WAAW,KAAK,aAAa,CAAC;AACrC,SAAO,UAAU,KAAK,aAAa,CAAC;AACpC,SAAO,cAAc,KAAK,aAAa,CAAC;CACxC,EACD,GACD;AAIF,KAAI,eACH,kBAAiB,KAChB,4EAA4B;EAE3B,qCAAqC,EAAE,SAAS,MAAO;EAEvD,uCAAuC,EACtC,2BAA2B,CAAC,YAAY;GAEvC,MAAM,OAAO,QAAQ,OAAO;AAC5B,UACC,KAAK,SAAS,YAAY,IAC1B,KAAK,SAAS,eAAe,IAC7B,KAAK,SAAS,WAAW;EAE1B,EACD;CACD,EAAC,CACF;CAIF,IAAIC;AACJ,KAAI,SACH,iBAAgB,IAAIC,2DAAkB;EACrC,MAAM,EAAE,SAAS;EACjB;CACA;KAGD,iBAAgB,IAAIC;CAIrB,MAAM,WAAW,yBAAyB,oCAAuB,YAAY;CAC7E,MAAM,gBAAgB,iCAAoB,eAAe,EAAE,SAAU,EAAC;AAGtE,qCAAuB,cAAc;AAGrC,OAAM,IAAIC,iCAAQ;EACjB;EACA;EACA,gBAAgB,CAAC,aAAc;EAC/B;CACA;AAGD,KAAI,UAAU;EACb,MAAM,cAAc,IAAIC,wDAAgB;GACvC,MAAM,EAAE,SAAS;GACjB;EACA;EAED,MAAM,iBAAiB,IAAIC,wCAAe,EAAE,SAAU;EACtD,MAAM,eAAe,IAAIC,iDAAwB;AACjD,iBAAe,sBAAsB,aAAa;AAGlD,qCAAsB,aAAa;CACnC;AAGD,KAAI,OAAO;AAGX,SAAQ,GAAG,WAAW,MAAM;AAC3B,OACG,UAAU,CACX,KAAK,MAAM,CAAE,EAAC,CACd,MAAM,CAAC,WAAW,CAAE,EAAC,CACrB,QAAQ,MAAM,QAAQ,KAAK,EAAE,CAAC;CAChC,EAAC;AACF;;;;AAKD,eAAsB,oBAAmC;AACxD,KAAI,KAAK;AACR,QAAM,IAAI,UAAU;AACpB,QAAM;CACN;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing-PnECEbEu.d.mts","names":[],"sources":["../src/instrumentation/tracing.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;AAOgB,iBAPA,aAAA,CAAA,CAO8B,EAPb,
|
|
1
|
+
{"version":3,"file":"tracing-PnECEbEu.d.mts","names":[],"sources":["../src/instrumentation/tracing.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;AAOgB,iBAPA,aAAA,CAAA,CAO8B,EAPb,IAOuB,GAAA,SAAA;AAUxD;;;AAAmE,iBAVnD,iBAAA,CAUmD,UAAA,EAVrB,UAUqB,CAAA,EAAA,IAAA;AAAI;AAkBvE;;AAEY,iBApBI,UAAA,CAoBJ,IAAA,EAAA,MAAA,EAAA,UAAA,CAAA,EApB0C,UAoB1C,CAAA,EApBuD,IAoBvD;;;;;;AAEF;AA4BV;;;;;;AAII,iBApCkB,QAoClB,CAAA,CAAA,CAAA,CAAA,IAAA,EAAA,MAAA,EAAA,EAAA,EAAA,CAAA,IAAA,EAlCQ,IAkCR,EAAA,GAlCiB,OAkCjB,CAlCyB,CAkCzB,CAAA,EAAA,UAAA,CAAA,EAjCU,UAiCV,CAAA,EAhCD,OAgCC,CAhCO,CAgCP,CAAA;AA2BJ;AAQA;AAQA;AAcgB,iBA7DA,YA6DwC,CAAA,CAAA,CAAA,CAAU,IAAA,EAAA,MAAA,EAAA,EAAA,EAAA,CAAA,IAAA,EA3DtD,IA2DsD,EAAA,GA3D7C,CA2D6C,EAAA,UAAA,CAAA,EA1DpD,UA0DoD,CAAA,EAzD/D,CAyD+D;;;;iBA9BlD,UAAA,CAAA;;;;iBAQA,SAAA,CAAA;;;;iBAQA,eAAA,QAAuB;;;;iBAcvB,YAAA,4BAAwC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SeverityNumber, SpanKind, SpanStatusCode } from "./types-
|
|
1
|
+
import { SeverityNumber, SpanKind, SpanStatusCode } from "./types-Cj59nqy7.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/otlp/transformer.ts
|
|
4
4
|
/**
|
|
@@ -212,4 +212,4 @@ function transformMetrics(request) {
|
|
|
212
212
|
|
|
213
213
|
//#endregion
|
|
214
214
|
export { transformLogs, transformMetrics, transformTraces };
|
|
215
|
-
//# sourceMappingURL=transformer-
|
|
215
|
+
//# sourceMappingURL=transformer-CFQ4WFk6.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer-CFrJQkUg.mjs","names":["value?: AnyValue","attrs?: KeyValue[]","result: Record<string, unknown>","nanoStr: string","severity?: SeverityNumber","span: Span","resourceAttrs: Record<string, unknown>","headers: Record<string, string>","request: ExportTraceServiceRequest","entries: Array<Omit<RequestEntry, 'id' | 'timestamp'>>","record: LogRecord","scopeName?: string","context: Record<string, unknown>","request: ExportLogsServiceRequest","entries: Array<Omit<LogEntry, 'id' | 'timestamp'>>","request: ExportMetricsServiceRequest","points: MetricDataPoint[]"],"sources":["../src/otlp/transformer.ts"],"sourcesContent":["import type { LogEntry, RequestEntry } from '../types';\nimport {\n\ttype AnyValue,\n\ttype ExportLogsServiceRequest,\n\ttype ExportMetricsServiceRequest,\n\ttype ExportTraceServiceRequest,\n\ttype KeyValue,\n\ttype LogRecord,\n\tSeverityNumber,\n\ttype Span,\n\tSpanKind,\n\tSpanStatusCode,\n} from './types';\n\n/**\n * Extract a primitive value from an AnyValue\n */\nfunction extractValue(value?: AnyValue): unknown {\n\tif (!value) return undefined;\n\tif (value.stringValue !== undefined) return value.stringValue;\n\tif (value.boolValue !== undefined) return value.boolValue;\n\tif (value.intValue !== undefined) return parseInt(value.intValue, 10);\n\tif (value.doubleValue !== undefined) return value.doubleValue;\n\tif (value.bytesValue !== undefined) return value.bytesValue;\n\tif (value.arrayValue) return value.arrayValue.values.map(extractValue);\n\tif (value.kvlistValue) return attributesToObject(value.kvlistValue.values);\n\treturn undefined;\n}\n\n/**\n * Convert KeyValue array to a plain object\n */\nfunction attributesToObject(attrs?: KeyValue[]): Record<string, unknown> {\n\tif (!attrs) return {};\n\tconst result: Record<string, unknown> = {};\n\tfor (const attr of attrs) {\n\t\tresult[attr.key] = extractValue(attr.value);\n\t}\n\treturn result;\n}\n\n/**\n * Convert nanoseconds string to Date\n */\nfunction nanoToDate(nanoStr: string): Date {\n\tconst nano = BigInt(nanoStr);\n\tconst ms = Number(nano / BigInt(1_000_000));\n\treturn new Date(ms);\n}\n\n/**\n * Convert nanoseconds string to milliseconds number\n */\nfunction nanoToMs(nanoStr: string): number {\n\tconst nano = BigInt(nanoStr);\n\treturn Number(nano / BigInt(1_000_000));\n}\n\n/**\n * Map OTLP severity number to Telescope log level\n */\nfunction mapSeverity(\n\tseverity?: SeverityNumber,\n): 'debug' | 'info' | 'warn' | 'error' {\n\tif (severity === undefined) return 'info';\n\tif (severity <= SeverityNumber.SEVERITY_NUMBER_DEBUG4) return 'debug';\n\tif (severity <= SeverityNumber.SEVERITY_NUMBER_INFO4) return 'info';\n\tif (severity <= SeverityNumber.SEVERITY_NUMBER_WARN4) return 'warn';\n\treturn 'error';\n}\n\n/**\n * Determine HTTP status from span attributes and status\n */\nfunction getHttpStatus(span: Span): number {\n\tconst attrs = attributesToObject(span.attributes);\n\n\t// Look for HTTP status code in various attribute names\n\tconst statusCode =\n\t\tattrs['http.status_code'] ??\n\t\tattrs['http.response.status_code'] ??\n\t\tattrs['http.response_status_code'];\n\n\tif (typeof statusCode === 'number') return statusCode;\n\tif (typeof statusCode === 'string') return parseInt(statusCode, 10) || 200;\n\n\t// Fall back to span status\n\tif (span.status?.code === SpanStatusCode.STATUS_CODE_ERROR) return 500;\n\tif (span.status?.code === SpanStatusCode.STATUS_CODE_OK) return 200;\n\n\treturn 200;\n}\n\n/**\n * Check if a span represents an HTTP server request\n */\nfunction isHttpServerSpan(span: Span): boolean {\n\tif (span.kind !== SpanKind.SPAN_KIND_SERVER) return false;\n\n\tconst attrs = attributesToObject(span.attributes);\n\treturn !!(\n\t\tattrs['http.method'] ||\n\t\tattrs['http.request.method'] ||\n\t\tattrs['http.url'] ||\n\t\tattrs['http.target'] ||\n\t\tattrs['url.path']\n\t);\n}\n\n/**\n * Transform HTTP-related span attributes to RequestEntry format\n */\nfunction transformHttpSpan(\n\tspan: Span,\n\tresourceAttrs: Record<string, unknown>,\n): Omit<RequestEntry, 'id' | 'timestamp'> {\n\tconst attrs = attributesToObject(span.attributes);\n\n\t// Extract HTTP method\n\tconst method = String(\n\t\tattrs['http.method'] ?? attrs['http.request.method'] ?? 'GET',\n\t).toUpperCase();\n\n\t// Extract path\n\tconst path = String(\n\t\tattrs['http.target'] ?? attrs['url.path'] ?? attrs['http.route'] ?? '/',\n\t);\n\n\t// Extract full URL\n\tconst url = String(\n\t\tattrs['http.url'] ?? attrs['url.full'] ?? `http://localhost${path}`,\n\t);\n\n\t// Extract headers (if available)\n\tconst headers: Record<string, string> = {};\n\tconst userAgent = attrs['http.user_agent'] ?? attrs['user_agent.original'];\n\tif (userAgent) headers['user-agent'] = String(userAgent);\n\n\tconst contentType = attrs['http.request.header.content_type'];\n\tif (contentType) headers['content-type'] = String(contentType);\n\n\t// Calculate duration\n\tconst startTime = nanoToMs(span.startTimeUnixNano);\n\tconst endTime = nanoToMs(span.endTimeUnixNano);\n\tconst duration = endTime - startTime;\n\n\t// Get status code\n\tconst status = getHttpStatus(span);\n\n\t// Extract client IP\n\tconst ip =\n\t\tattrs['net.peer.ip'] ?? attrs['client.address'] ?? attrs['http.client_ip'];\n\n\treturn {\n\t\tmethod,\n\t\tpath,\n\t\turl,\n\t\theaders,\n\t\tquery: {},\n\t\tstatus,\n\t\tresponseHeaders: {},\n\t\tduration,\n\t\tip: ip ? String(ip) : undefined,\n\t\ttags: [\n\t\t\t`trace:${span.traceId}`,\n\t\t\t`span:${span.spanId}`,\n\t\t\t...(resourceAttrs['service.name']\n\t\t\t\t? [`service:${resourceAttrs['service.name']}`]\n\t\t\t\t: []),\n\t\t],\n\t};\n}\n\n/**\n * Transform OTLP traces to Telescope RequestEntries\n * Only transforms HTTP server spans to request entries\n */\nexport function transformTraces(\n\trequest: ExportTraceServiceRequest,\n): Array<Omit<RequestEntry, 'id' | 'timestamp'>> {\n\tconst entries: Array<Omit<RequestEntry, 'id' | 'timestamp'>> = [];\n\n\tfor (const resourceSpans of request.resourceSpans ?? []) {\n\t\tconst resourceAttrs = attributesToObject(\n\t\t\tresourceSpans.resource?.attributes,\n\t\t);\n\n\t\tfor (const scopeSpans of resourceSpans.scopeSpans ?? []) {\n\t\t\tfor (const span of scopeSpans.spans ?? []) {\n\t\t\t\t// Only transform HTTP server spans\n\t\t\t\tif (isHttpServerSpan(span)) {\n\t\t\t\t\tentries.push(transformHttpSpan(span, resourceAttrs));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn entries;\n}\n\n/**\n * Transform a single OTLP log record to Telescope LogEntry\n */\nfunction transformLogRecord(\n\trecord: LogRecord,\n\tresourceAttrs: Record<string, unknown>,\n\tscopeName?: string,\n): Omit<LogEntry, 'id' | 'timestamp'> {\n\tconst attrs = attributesToObject(record.attributes);\n\n\t// Extract message from body\n\tlet message = '';\n\tif (record.body) {\n\t\tconst bodyValue = extractValue(record.body);\n\t\tmessage =\n\t\t\ttypeof bodyValue === 'string' ? bodyValue : JSON.stringify(bodyValue);\n\t}\n\n\t// Build context from attributes\n\tconst context: Record<string, unknown> = {\n\t\t...attrs,\n\t\t...resourceAttrs,\n\t};\n\n\tif (scopeName) {\n\t\tcontext['instrumentation.scope'] = scopeName;\n\t}\n\n\t// Add severity text if present\n\tif (record.severityText) {\n\t\tcontext['severity.text'] = record.severityText;\n\t}\n\n\treturn {\n\t\tlevel: mapSeverity(record.severityNumber),\n\t\tmessage,\n\t\tcontext: Object.keys(context).length > 0 ? context : undefined,\n\t\trequestId: record.spanId ? `span:${record.spanId}` : undefined,\n\t};\n}\n\n/**\n * Transform OTLP logs to Telescope LogEntries\n */\nexport function transformLogs(\n\trequest: ExportLogsServiceRequest,\n): Array<Omit<LogEntry, 'id' | 'timestamp'>> {\n\tconst entries: Array<Omit<LogEntry, 'id' | 'timestamp'>> = [];\n\n\tfor (const resourceLogs of request.resourceLogs ?? []) {\n\t\tconst resourceAttrs = attributesToObject(resourceLogs.resource?.attributes);\n\n\t\tfor (const scopeLogs of resourceLogs.scopeLogs ?? []) {\n\t\t\tconst scopeName = scopeLogs.scope?.name;\n\n\t\t\tfor (const record of scopeLogs.logRecords ?? []) {\n\t\t\t\tentries.push(transformLogRecord(record, resourceAttrs, scopeName));\n\t\t\t}\n\t\t}\n\t}\n\n\treturn entries;\n}\n\n/**\n * Extracted metric data point for recording\n */\nexport interface MetricDataPoint {\n\tname: string;\n\tdescription?: string;\n\tunit?: string;\n\tvalue: number;\n\ttimestamp: Date;\n\tattributes: Record<string, unknown>;\n\tresourceAttributes: Record<string, unknown>;\n\ttype: 'gauge' | 'sum' | 'histogram' | 'summary';\n}\n\n/**\n * Transform OTLP metrics to normalized data points\n * These can be used for custom metrics processing or forwarding\n */\nexport function transformMetrics(\n\trequest: ExportMetricsServiceRequest,\n): MetricDataPoint[] {\n\tconst points: MetricDataPoint[] = [];\n\n\tfor (const resourceMetrics of request.resourceMetrics ?? []) {\n\t\tconst resourceAttrs = attributesToObject(\n\t\t\tresourceMetrics.resource?.attributes,\n\t\t);\n\n\t\tfor (const scopeMetrics of resourceMetrics.scopeMetrics ?? []) {\n\t\t\tfor (const metric of scopeMetrics.metrics ?? []) {\n\t\t\t\tconst baseMeta = {\n\t\t\t\t\tname: metric.name,\n\t\t\t\t\tdescription: metric.description,\n\t\t\t\t\tunit: metric.unit,\n\t\t\t\t\tresourceAttributes: resourceAttrs,\n\t\t\t\t};\n\n\t\t\t\t// Handle gauge\n\t\t\t\tif (metric.gauge) {\n\t\t\t\t\tfor (const dp of metric.gauge.dataPoints) {\n\t\t\t\t\t\tpoints.push({\n\t\t\t\t\t\t\t...baseMeta,\n\t\t\t\t\t\t\tvalue: dp.asDouble ?? (dp.asInt ? parseInt(dp.asInt, 10) : 0),\n\t\t\t\t\t\t\ttimestamp: nanoToDate(dp.timeUnixNano),\n\t\t\t\t\t\t\tattributes: attributesToObject(dp.attributes),\n\t\t\t\t\t\t\ttype: 'gauge',\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle sum (counter)\n\t\t\t\tif (metric.sum) {\n\t\t\t\t\tfor (const dp of metric.sum.dataPoints) {\n\t\t\t\t\t\tpoints.push({\n\t\t\t\t\t\t\t...baseMeta,\n\t\t\t\t\t\t\tvalue: dp.asDouble ?? (dp.asInt ? parseInt(dp.asInt, 10) : 0),\n\t\t\t\t\t\t\ttimestamp: nanoToDate(dp.timeUnixNano),\n\t\t\t\t\t\t\tattributes: attributesToObject(dp.attributes),\n\t\t\t\t\t\t\ttype: 'sum',\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle histogram (extract sum as the value)\n\t\t\t\tif (metric.histogram) {\n\t\t\t\t\tfor (const dp of metric.histogram.dataPoints) {\n\t\t\t\t\t\tpoints.push({\n\t\t\t\t\t\t\t...baseMeta,\n\t\t\t\t\t\t\tvalue: dp.sum ?? 0,\n\t\t\t\t\t\t\ttimestamp: nanoToDate(dp.timeUnixNano),\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t...attributesToObject(dp.attributes),\n\t\t\t\t\t\t\t\tcount: parseInt(dp.count, 10),\n\t\t\t\t\t\t\t\tmin: dp.min,\n\t\t\t\t\t\t\t\tmax: dp.max,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttype: 'histogram',\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle summary\n\t\t\t\tif (metric.summary) {\n\t\t\t\t\tfor (const dp of metric.summary.dataPoints) {\n\t\t\t\t\t\tpoints.push({\n\t\t\t\t\t\t\t...baseMeta,\n\t\t\t\t\t\t\tvalue: dp.sum ?? 0,\n\t\t\t\t\t\t\ttimestamp: nanoToDate(dp.timeUnixNano),\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t...attributesToObject(dp.attributes),\n\t\t\t\t\t\t\t\tcount: parseInt(dp.count, 10),\n\t\t\t\t\t\t\t\tquantiles: dp.quantileValues,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttype: 'summary',\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn points;\n}\n"],"mappings":";;;;;;AAiBA,SAAS,aAAaA,OAA2B;AAChD,MAAK,MAAO;AACZ,KAAI,MAAM,uBAA2B,QAAO,MAAM;AAClD,KAAI,MAAM,qBAAyB,QAAO,MAAM;AAChD,KAAI,MAAM,oBAAwB,QAAO,SAAS,MAAM,UAAU,GAAG;AAC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, unknown>","nanoStr: string","severity?: SeverityNumber","span: Span","resourceAttrs: Record<string, unknown>","headers: Record<string, string>","request: ExportTraceServiceRequest","entries: Array<Omit<RequestEntry, 'id' | 'timestamp'>>","record: LogRecord","scopeName?: string","context: Record<string, unknown>","request: ExportLogsServiceRequest","entries: Array<Omit<LogEntry, 'id' | 'timestamp'>>","request: ExportMetricsServiceRequest","points: MetricDataPoint[]"],"sources":["../src/otlp/transformer.ts"],"sourcesContent":["import type { LogEntry, RequestEntry } from '../types';\nimport {\n\ttype AnyValue,\n\ttype ExportLogsServiceRequest,\n\ttype ExportMetricsServiceRequest,\n\ttype ExportTraceServiceRequest,\n\ttype KeyValue,\n\ttype LogRecord,\n\tSeverityNumber,\n\ttype Span,\n\tSpanKind,\n\tSpanStatusCode,\n} from './types';\n\n/**\n * Extract a primitive value from an AnyValue\n */\nfunction extractValue(value?: AnyValue): unknown {\n\tif (!value) return undefined;\n\tif (value.stringValue !== undefined) return value.stringValue;\n\tif (value.boolValue !== undefined) return value.boolValue;\n\tif (value.intValue !== undefined) return parseInt(value.intValue, 10);\n\tif (value.doubleValue !== undefined) return value.doubleValue;\n\tif (value.bytesValue !== undefined) return value.bytesValue;\n\tif (value.arrayValue) return value.arrayValue.values.map(extractValue);\n\tif (value.kvlistValue) return attributesToObject(value.kvlistValue.values);\n\treturn undefined;\n}\n\n/**\n * Convert KeyValue array to a plain object\n */\nfunction attributesToObject(attrs?: KeyValue[]): Record<string, unknown> {\n\tif (!attrs) return {};\n\tconst result: Record<string, unknown> = {};\n\tfor (const attr of attrs) {\n\t\tresult[attr.key] = extractValue(attr.value);\n\t}\n\treturn result;\n}\n\n/**\n * Convert nanoseconds string to Date\n */\nfunction nanoToDate(nanoStr: string): Date {\n\tconst nano = BigInt(nanoStr);\n\tconst ms = Number(nano / BigInt(1_000_000));\n\treturn new Date(ms);\n}\n\n/**\n * Convert nanoseconds string to milliseconds number\n */\nfunction nanoToMs(nanoStr: string): number {\n\tconst nano = BigInt(nanoStr);\n\treturn Number(nano / BigInt(1_000_000));\n}\n\n/**\n * Map OTLP severity number to Telescope log level\n */\nfunction mapSeverity(\n\tseverity?: SeverityNumber,\n): 'debug' | 'info' | 'warn' | 'error' {\n\tif (severity === undefined) return 'info';\n\tif (severity <= SeverityNumber.SEVERITY_NUMBER_DEBUG4) return 'debug';\n\tif (severity <= SeverityNumber.SEVERITY_NUMBER_INFO4) return 'info';\n\tif (severity <= SeverityNumber.SEVERITY_NUMBER_WARN4) return 'warn';\n\treturn 'error';\n}\n\n/**\n * Determine HTTP status from span attributes and status\n */\nfunction getHttpStatus(span: Span): number {\n\tconst attrs = attributesToObject(span.attributes);\n\n\t// Look for HTTP status code in various attribute names\n\tconst statusCode =\n\t\tattrs['http.status_code'] ??\n\t\tattrs['http.response.status_code'] ??\n\t\tattrs['http.response_status_code'];\n\n\tif (typeof statusCode === 'number') return statusCode;\n\tif (typeof statusCode === 'string') return parseInt(statusCode, 10) || 200;\n\n\t// Fall back to span status\n\tif (span.status?.code === SpanStatusCode.STATUS_CODE_ERROR) return 500;\n\tif (span.status?.code === SpanStatusCode.STATUS_CODE_OK) return 200;\n\n\treturn 200;\n}\n\n/**\n * Check if a span represents an HTTP server request\n */\nfunction isHttpServerSpan(span: Span): boolean {\n\tif (span.kind !== SpanKind.SPAN_KIND_SERVER) return false;\n\n\tconst attrs = attributesToObject(span.attributes);\n\treturn !!(\n\t\tattrs['http.method'] ||\n\t\tattrs['http.request.method'] ||\n\t\tattrs['http.url'] ||\n\t\tattrs['http.target'] ||\n\t\tattrs['url.path']\n\t);\n}\n\n/**\n * Transform HTTP-related span attributes to RequestEntry format\n */\nfunction transformHttpSpan(\n\tspan: Span,\n\tresourceAttrs: Record<string, unknown>,\n): Omit<RequestEntry, 'id' | 'timestamp'> {\n\tconst attrs = attributesToObject(span.attributes);\n\n\t// Extract HTTP method\n\tconst method = String(\n\t\tattrs['http.method'] ?? attrs['http.request.method'] ?? 'GET',\n\t).toUpperCase();\n\n\t// Extract path\n\tconst path = String(\n\t\tattrs['http.target'] ?? attrs['url.path'] ?? attrs['http.route'] ?? '/',\n\t);\n\n\t// Extract full URL\n\tconst url = String(\n\t\tattrs['http.url'] ?? attrs['url.full'] ?? `http://localhost${path}`,\n\t);\n\n\t// Extract headers (if available)\n\tconst headers: Record<string, string> = {};\n\tconst userAgent = attrs['http.user_agent'] ?? attrs['user_agent.original'];\n\tif (userAgent) headers['user-agent'] = String(userAgent);\n\n\tconst contentType = attrs['http.request.header.content_type'];\n\tif (contentType) headers['content-type'] = String(contentType);\n\n\t// Calculate duration\n\tconst startTime = nanoToMs(span.startTimeUnixNano);\n\tconst endTime = nanoToMs(span.endTimeUnixNano);\n\tconst duration = endTime - startTime;\n\n\t// Get status code\n\tconst status = getHttpStatus(span);\n\n\t// Extract client IP\n\tconst ip =\n\t\tattrs['net.peer.ip'] ?? attrs['client.address'] ?? attrs['http.client_ip'];\n\n\treturn {\n\t\tmethod,\n\t\tpath,\n\t\turl,\n\t\theaders,\n\t\tquery: {},\n\t\tstatus,\n\t\tresponseHeaders: {},\n\t\tduration,\n\t\tip: ip ? String(ip) : undefined,\n\t\ttags: [\n\t\t\t`trace:${span.traceId}`,\n\t\t\t`span:${span.spanId}`,\n\t\t\t...(resourceAttrs['service.name']\n\t\t\t\t? [`service:${resourceAttrs['service.name']}`]\n\t\t\t\t: []),\n\t\t],\n\t};\n}\n\n/**\n * Transform OTLP traces to Telescope RequestEntries\n * Only transforms HTTP server spans to request entries\n */\nexport function transformTraces(\n\trequest: ExportTraceServiceRequest,\n): Array<Omit<RequestEntry, 'id' | 'timestamp'>> {\n\tconst entries: Array<Omit<RequestEntry, 'id' | 'timestamp'>> = [];\n\n\tfor (const resourceSpans of request.resourceSpans ?? []) {\n\t\tconst resourceAttrs = attributesToObject(\n\t\t\tresourceSpans.resource?.attributes,\n\t\t);\n\n\t\tfor (const scopeSpans of resourceSpans.scopeSpans ?? []) {\n\t\t\tfor (const span of scopeSpans.spans ?? []) {\n\t\t\t\t// Only transform HTTP server spans\n\t\t\t\tif (isHttpServerSpan(span)) {\n\t\t\t\t\tentries.push(transformHttpSpan(span, resourceAttrs));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn entries;\n}\n\n/**\n * Transform a single OTLP log record to Telescope LogEntry\n */\nfunction transformLogRecord(\n\trecord: LogRecord,\n\tresourceAttrs: Record<string, unknown>,\n\tscopeName?: string,\n): Omit<LogEntry, 'id' | 'timestamp'> {\n\tconst attrs = attributesToObject(record.attributes);\n\n\t// Extract message from body\n\tlet message = '';\n\tif (record.body) {\n\t\tconst bodyValue = extractValue(record.body);\n\t\tmessage =\n\t\t\ttypeof bodyValue === 'string' ? bodyValue : JSON.stringify(bodyValue);\n\t}\n\n\t// Build context from attributes\n\tconst context: Record<string, unknown> = {\n\t\t...attrs,\n\t\t...resourceAttrs,\n\t};\n\n\tif (scopeName) {\n\t\tcontext['instrumentation.scope'] = scopeName;\n\t}\n\n\t// Add severity text if present\n\tif (record.severityText) {\n\t\tcontext['severity.text'] = record.severityText;\n\t}\n\n\treturn {\n\t\tlevel: mapSeverity(record.severityNumber),\n\t\tmessage,\n\t\tcontext: Object.keys(context).length > 0 ? context : undefined,\n\t\trequestId: record.spanId ? `span:${record.spanId}` : undefined,\n\t};\n}\n\n/**\n * Transform OTLP logs to Telescope LogEntries\n */\nexport function transformLogs(\n\trequest: ExportLogsServiceRequest,\n): Array<Omit<LogEntry, 'id' | 'timestamp'>> {\n\tconst entries: Array<Omit<LogEntry, 'id' | 'timestamp'>> = [];\n\n\tfor (const resourceLogs of request.resourceLogs ?? []) {\n\t\tconst resourceAttrs = attributesToObject(resourceLogs.resource?.attributes);\n\n\t\tfor (const scopeLogs of resourceLogs.scopeLogs ?? []) {\n\t\t\tconst scopeName = scopeLogs.scope?.name;\n\n\t\t\tfor (const record of scopeLogs.logRecords ?? []) {\n\t\t\t\tentries.push(transformLogRecord(record, resourceAttrs, scopeName));\n\t\t\t}\n\t\t}\n\t}\n\n\treturn entries;\n}\n\n/**\n * Extracted metric data point for recording\n */\nexport interface MetricDataPoint {\n\tname: string;\n\tdescription?: string;\n\tunit?: string;\n\tvalue: number;\n\ttimestamp: Date;\n\tattributes: Record<string, unknown>;\n\tresourceAttributes: Record<string, unknown>;\n\ttype: 'gauge' | 'sum' | 'histogram' | 'summary';\n}\n\n/**\n * Transform OTLP metrics to normalized data points\n * These can be used for custom metrics processing or forwarding\n */\nexport function transformMetrics(\n\trequest: ExportMetricsServiceRequest,\n): MetricDataPoint[] {\n\tconst points: MetricDataPoint[] = [];\n\n\tfor (const resourceMetrics of request.resourceMetrics ?? []) {\n\t\tconst resourceAttrs = attributesToObject(\n\t\t\tresourceMetrics.resource?.attributes,\n\t\t);\n\n\t\tfor (const scopeMetrics of resourceMetrics.scopeMetrics ?? []) {\n\t\t\tfor (const metric of scopeMetrics.metrics ?? []) {\n\t\t\t\tconst baseMeta = {\n\t\t\t\t\tname: metric.name,\n\t\t\t\t\tdescription: metric.description,\n\t\t\t\t\tunit: metric.unit,\n\t\t\t\t\tresourceAttributes: resourceAttrs,\n\t\t\t\t};\n\n\t\t\t\t// Handle gauge\n\t\t\t\tif (metric.gauge) {\n\t\t\t\t\tfor (const dp of metric.gauge.dataPoints) {\n\t\t\t\t\t\tpoints.push({\n\t\t\t\t\t\t\t...baseMeta,\n\t\t\t\t\t\t\tvalue: dp.asDouble ?? (dp.asInt ? parseInt(dp.asInt, 10) : 0),\n\t\t\t\t\t\t\ttimestamp: nanoToDate(dp.timeUnixNano),\n\t\t\t\t\t\t\tattributes: attributesToObject(dp.attributes),\n\t\t\t\t\t\t\ttype: 'gauge',\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle sum (counter)\n\t\t\t\tif (metric.sum) {\n\t\t\t\t\tfor (const dp of metric.sum.dataPoints) {\n\t\t\t\t\t\tpoints.push({\n\t\t\t\t\t\t\t...baseMeta,\n\t\t\t\t\t\t\tvalue: dp.asDouble ?? (dp.asInt ? parseInt(dp.asInt, 10) : 0),\n\t\t\t\t\t\t\ttimestamp: nanoToDate(dp.timeUnixNano),\n\t\t\t\t\t\t\tattributes: attributesToObject(dp.attributes),\n\t\t\t\t\t\t\ttype: 'sum',\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle histogram (extract sum as the value)\n\t\t\t\tif (metric.histogram) {\n\t\t\t\t\tfor (const dp of metric.histogram.dataPoints) {\n\t\t\t\t\t\tpoints.push({\n\t\t\t\t\t\t\t...baseMeta,\n\t\t\t\t\t\t\tvalue: dp.sum ?? 0,\n\t\t\t\t\t\t\ttimestamp: nanoToDate(dp.timeUnixNano),\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t...attributesToObject(dp.attributes),\n\t\t\t\t\t\t\t\tcount: parseInt(dp.count, 10),\n\t\t\t\t\t\t\t\tmin: dp.min,\n\t\t\t\t\t\t\t\tmax: dp.max,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttype: 'histogram',\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle summary\n\t\t\t\tif (metric.summary) {\n\t\t\t\t\tfor (const dp of metric.summary.dataPoints) {\n\t\t\t\t\t\tpoints.push({\n\t\t\t\t\t\t\t...baseMeta,\n\t\t\t\t\t\t\tvalue: dp.sum ?? 0,\n\t\t\t\t\t\t\ttimestamp: nanoToDate(dp.timeUnixNano),\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t...attributesToObject(dp.attributes),\n\t\t\t\t\t\t\t\tcount: parseInt(dp.count, 10),\n\t\t\t\t\t\t\t\tquantiles: dp.quantileValues,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttype: 'summary',\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn points;\n}\n"],"mappings":";;;;;;AAiBA,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G,OAAO,GAAG;KAC7B,WAAW,GAAG;IACd;IACD,MAAM;GACN,EAAC;EAGJ;CAEF;AAED,QAAO;AACP"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_types = require('./types-
|
|
1
|
+
const require_types = require('./types-BMiHgsi4.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/otlp/transformer.ts
|
|
4
4
|
/**
|
|
@@ -229,4 +229,4 @@ Object.defineProperty(exports, 'transformTraces', {
|
|
|
229
229
|
return transformTraces;
|
|
230
230
|
}
|
|
231
231
|
});
|
|
232
|
-
//# sourceMappingURL=transformer-
|
|
232
|
+
//# sourceMappingURL=transformer-Csl6fbgv.cjs.map
|