@lark-apaas/observable 1.0.1-alpha.2 → 1.0.1-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -155,7 +155,7 @@ var ProxyLoggerProvider = class {
155
155
  var _globalThis = typeof globalThis === "object" ? globalThis : global;
156
156
 
157
157
  // ../../../node_modules/@opentelemetry/api-logs/build/esm/internal/global-utils.js
158
- var GLOBAL_LOGS_API_KEY = Symbol.for("io.opentelemetry.js.api.logs");
158
+ var GLOBAL_LOGS_API_KEY = /* @__PURE__ */ Symbol.for("io.opentelemetry.js.api.logs");
159
159
  var _global = _globalThis;
160
160
  function makeGetter(requiredVersion, instance, fallback) {
161
161
  return (version) => version === requiredVersion ? instance : fallback;
@@ -264,6 +264,15 @@ var idGenerator = {
264
264
  }
265
265
  };
266
266
 
267
+ // src/utils/hrTimeToNanoString.ts
268
+ function hrTimeToNanosString(hrTime) {
269
+ const seconds = BigInt(hrTime[0]);
270
+ const nanos = BigInt(hrTime[1]);
271
+ const totalNanos = seconds * 1000000000n + nanos;
272
+ return totalNanos.toString();
273
+ }
274
+ __name(hrTimeToNanosString, "hrTimeToNanosString");
275
+
267
276
  // src/core/exportor.ts
268
277
  var CustomExporter = class {
269
278
  static {
@@ -281,12 +290,14 @@ var CustomExporter = class {
281
290
  const otlpLikeStructure = {
282
291
  resourceLogs: logs2.map((log) => ({
283
292
  resource: {
284
- attributes: log.resource.attributes
293
+ // resource.attributes 暂时置空
294
+ // attributes: log.resource.attributes,
295
+ attributes: {}
285
296
  },
286
297
  logRecords: [
287
298
  {
288
- timeUnixNano: log.hrTime,
289
- observedTimeUnixNano: log.hrTimeObserved,
299
+ timeUnixNano: hrTimeToNanosString(log.hrTime),
300
+ observedTimeUnixNano: hrTimeToNanosString(log.hrTimeObserved),
290
301
  severityNumber: log.severityNumber,
291
302
  severityText: log.severityText,
292
303
  body: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/core/sdk.ts","../../../../node_modules/@opentelemetry/api-logs/src/types/LogRecord.ts","../../../../node_modules/@opentelemetry/api-logs/src/NoopLogger.ts","../../../../node_modules/@opentelemetry/api-logs/src/NoopLoggerProvider.ts","../../../../node_modules/@opentelemetry/api-logs/src/ProxyLogger.ts","../../../../node_modules/@opentelemetry/api-logs/src/ProxyLoggerProvider.ts","../../../../node_modules/@opentelemetry/api-logs/src/platform/node/globalThis.ts","../../../../node_modules/@opentelemetry/api-logs/src/internal/global-utils.ts","../../../../node_modules/@opentelemetry/api-logs/src/api/logs.ts","../../../../node_modules/@opentelemetry/api-logs/src/index.ts","../src/core/resource-detector.ts","../../../../node_modules/@opentelemetry/core/src/ExportResult.ts","../src/utils/generateUUID.ts","../src/core/exportor.ts"],"sourcesContent":["export { AppOTelLoggerSDK } from './core/sdk';","// file: src/core/sdk.ts\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { detectResources } from '@opentelemetry/resources';\nimport { logs, SeverityNumber } from '@opentelemetry/api-logs';\nimport { PlatformDetector } from './resource-detector';\nimport type { LogAttributes } from '../type';\nimport { CustomExporter } from './exportor';\n\nexport class AppOTelLoggerSDK {\n private sdk: NodeSDK | null = null;\n private logProcessor: BatchLogRecordProcessor | null = null;\n\n start() {\n // 1. 探测并定义资源\n const resource = detectResources({\n detectors: [\n new PlatformDetector()\n ]\n });\n\n // 2. 配置数据出口 Exporter\n const logExporter = new CustomExporter();\n\n // 3. 配置 Processor\n // 手动创建是为了后面能调用它的 forceFlush\n this.logProcessor = new BatchLogRecordProcessor(logExporter, {\n scheduledDelayMillis: 1000,\n maxExportBatchSize: 512\n });\n\n // 4. 启动官方 SDK 底座\n this.sdk = new NodeSDK({\n resource,\n logRecordProcessor: this.logProcessor,\n // Trace 暂不实现\n traceExporter: undefined,\n });\n\n this.sdk.start();\n }\n \n /**\n * 用户使用的日志接口\n */\n public log(level: string, message: string, attributes: LogAttributes = {}) {\n const logger = logs.getLogger('app-logger');\n const severityNumber = this.mapSeverity(level);\n logger.emit({\n body: message,\n severityNumber: severityNumber,\n severityText: level.toUpperCase(),\n attributes: attributes,\n timestamp: new Date(),\n });\n }\n // FaaS 核心功能\n async flush() {\n if (this.logProcessor) {\n await this.logProcessor.forceFlush();\n }\n }\n\n private mapSeverity(level: string): SeverityNumber {\n switch (level.toLowerCase()) {\n case 'trace': return SeverityNumber.TRACE;\n case 'debug': return SeverityNumber.DEBUG;\n case 'info': return SeverityNumber.INFO;\n case 'warn': return SeverityNumber.WARN;\n case 'error': return SeverityNumber.ERROR;\n case 'fatal': return SeverityNumber.FATAL;\n default: return SeverityNumber.INFO;\n }\n }\n}\n\n// 导出单例\nexport const appSdk = new AppOTelLoggerSDK();","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Context, TimeInput } from '@opentelemetry/api';\nimport { AnyValue, AnyValueMap } from './AnyValue';\n\nexport type LogBody = AnyValue;\nexport type LogAttributes = AnyValueMap;\n\nexport enum SeverityNumber {\n UNSPECIFIED = 0,\n TRACE = 1,\n TRACE2 = 2,\n TRACE3 = 3,\n TRACE4 = 4,\n DEBUG = 5,\n DEBUG2 = 6,\n DEBUG3 = 7,\n DEBUG4 = 8,\n INFO = 9,\n INFO2 = 10,\n INFO3 = 11,\n INFO4 = 12,\n WARN = 13,\n WARN2 = 14,\n WARN3 = 15,\n WARN4 = 16,\n ERROR = 17,\n ERROR2 = 18,\n ERROR3 = 19,\n ERROR4 = 20,\n FATAL = 21,\n FATAL2 = 22,\n FATAL3 = 23,\n FATAL4 = 24,\n}\n\nexport interface LogRecord {\n /**\n * The unique identifier for the log record.\n */\n eventName?: string;\n\n /**\n * The time when the log record occurred as UNIX Epoch time in nanoseconds.\n */\n timestamp?: TimeInput;\n\n /**\n * Time when the event was observed by the collection system.\n */\n observedTimestamp?: TimeInput;\n\n /**\n * Numerical value of the severity.\n */\n severityNumber?: SeverityNumber;\n\n /**\n * The severity text.\n */\n severityText?: string;\n\n /**\n * A value containing the body of the log record.\n */\n body?: LogBody;\n\n /**\n * Attributes that define the log record.\n */\n attributes?: LogAttributes;\n\n /**\n * The Context associated with the LogRecord.\n */\n context?: Context;\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Logger } from './types/Logger';\nimport { LogRecord } from './types/LogRecord';\n\nexport class NoopLogger implements Logger {\n emit(_logRecord: LogRecord): void {}\n}\n\nexport const NOOP_LOGGER = new NoopLogger();\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from './types/LoggerProvider';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { NoopLogger } from './NoopLogger';\n\nexport class NoopLoggerProvider implements LoggerProvider {\n getLogger(\n _name: string,\n _version?: string | undefined,\n _options?: LoggerOptions | undefined\n ): Logger {\n return new NoopLogger();\n }\n}\n\nexport const NOOP_LOGGER_PROVIDER = new NoopLoggerProvider();\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { NOOP_LOGGER } from './NoopLogger';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { LogRecord } from './types/LogRecord';\n\nexport class ProxyLogger implements Logger {\n // When a real implementation is provided, this will be it\n private _delegate?: Logger;\n\n constructor(\n private _provider: LoggerDelegator,\n public readonly name: string,\n public readonly version?: string | undefined,\n public readonly options?: LoggerOptions | undefined\n ) {}\n\n /**\n * Emit a log record. This method should only be used by log appenders.\n *\n * @param logRecord\n */\n emit(logRecord: LogRecord): void {\n this._getLogger().emit(logRecord);\n }\n\n /**\n * Try to get a logger from the proxy logger provider.\n * If the proxy logger provider has no delegate, return a noop logger.\n */\n private _getLogger() {\n if (this._delegate) {\n return this._delegate;\n }\n const logger = this._provider._getDelegateLogger(\n this.name,\n this.version,\n this.options\n );\n if (!logger) {\n return NOOP_LOGGER;\n }\n this._delegate = logger;\n return this._delegate;\n }\n}\n\nexport interface LoggerDelegator {\n _getDelegateLogger(\n name: string,\n version?: string,\n options?: LoggerOptions\n ): Logger | undefined;\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from './types/LoggerProvider';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { NOOP_LOGGER_PROVIDER } from './NoopLoggerProvider';\nimport { ProxyLogger } from './ProxyLogger';\n\nexport class ProxyLoggerProvider implements LoggerProvider {\n private _delegate?: LoggerProvider;\n\n getLogger(\n name: string,\n version?: string | undefined,\n options?: LoggerOptions | undefined\n ): Logger {\n return (\n this._getDelegateLogger(name, version, options) ??\n new ProxyLogger(this, name, version, options)\n );\n }\n\n /**\n * Get the delegate logger provider.\n * Used by tests only.\n * @internal\n */\n _getDelegate(): LoggerProvider {\n return this._delegate ?? NOOP_LOGGER_PROVIDER;\n }\n\n /**\n * Set the delegate logger provider\n * @internal\n */\n _setDelegate(delegate: LoggerProvider) {\n this._delegate = delegate;\n }\n\n /**\n * @internal\n */\n _getDelegateLogger(\n name: string,\n version?: string | undefined,\n options?: LoggerOptions | undefined\n ): Logger | undefined {\n return this._delegate?.getLogger(name, version, options);\n }\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** only globals that common to node and browsers are allowed */\n// eslint-disable-next-line n/no-unsupported-features/es-builtins\nexport const _globalThis = typeof globalThis === 'object' ? globalThis : global;\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from '../types/LoggerProvider';\nimport { _globalThis } from '../platform';\n\nexport const GLOBAL_LOGS_API_KEY = Symbol.for('io.opentelemetry.js.api.logs');\n\ntype Get<T> = (version: number) => T;\ntype OtelGlobal = Partial<{\n [GLOBAL_LOGS_API_KEY]: Get<LoggerProvider>;\n}>;\n\nexport const _global = _globalThis as OtelGlobal;\n\n/**\n * Make a function which accepts a version integer and returns the instance of an API if the version\n * is compatible, or a fallback version (usually NOOP) if it is not.\n *\n * @param requiredVersion Backwards compatibility version which is required to return the instance\n * @param instance Instance which should be returned if the required version is compatible\n * @param fallback Fallback instance, usually NOOP, which will be returned if the required version is not compatible\n */\nexport function makeGetter<T>(\n requiredVersion: number,\n instance: T,\n fallback: T\n): Get<T> {\n return (version: number): T =>\n version === requiredVersion ? instance : fallback;\n}\n\n/**\n * A number which should be incremented each time a backwards incompatible\n * change is made to the API. This number is used when an API package\n * attempts to access the global API to ensure it is getting a compatible\n * version. If the global API is not compatible with the API package\n * attempting to get it, a NOOP API implementation will be returned.\n */\nexport const API_BACKWARDS_COMPATIBILITY_VERSION = 1;\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n API_BACKWARDS_COMPATIBILITY_VERSION,\n GLOBAL_LOGS_API_KEY,\n _global,\n makeGetter,\n} from '../internal/global-utils';\nimport { LoggerProvider } from '../types/LoggerProvider';\nimport { NOOP_LOGGER_PROVIDER } from '../NoopLoggerProvider';\nimport { Logger } from '../types/Logger';\nimport { LoggerOptions } from '../types/LoggerOptions';\nimport { ProxyLoggerProvider } from '../ProxyLoggerProvider';\n\nexport class LogsAPI {\n private static _instance?: LogsAPI;\n\n private _proxyLoggerProvider = new ProxyLoggerProvider();\n\n private constructor() {}\n\n public static getInstance(): LogsAPI {\n if (!this._instance) {\n this._instance = new LogsAPI();\n }\n\n return this._instance;\n }\n\n public setGlobalLoggerProvider(provider: LoggerProvider): LoggerProvider {\n if (_global[GLOBAL_LOGS_API_KEY]) {\n return this.getLoggerProvider();\n }\n\n _global[GLOBAL_LOGS_API_KEY] = makeGetter<LoggerProvider>(\n API_BACKWARDS_COMPATIBILITY_VERSION,\n provider,\n NOOP_LOGGER_PROVIDER\n );\n this._proxyLoggerProvider._setDelegate(provider);\n\n return provider;\n }\n\n /**\n * Returns the global logger provider.\n *\n * @returns LoggerProvider\n */\n public getLoggerProvider(): LoggerProvider {\n return (\n _global[GLOBAL_LOGS_API_KEY]?.(API_BACKWARDS_COMPATIBILITY_VERSION) ??\n this._proxyLoggerProvider\n );\n }\n\n /**\n * Returns a logger from the global logger provider.\n *\n * @returns Logger\n */\n public getLogger(\n name: string,\n version?: string,\n options?: LoggerOptions\n ): Logger {\n return this.getLoggerProvider().getLogger(name, version, options);\n }\n\n /** Remove the global logger provider */\n public disable(): void {\n delete _global[GLOBAL_LOGS_API_KEY];\n this._proxyLoggerProvider = new ProxyLoggerProvider();\n }\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type { Logger } from './types/Logger';\nexport type { LoggerProvider } from './types/LoggerProvider';\nexport { SeverityNumber } from './types/LogRecord';\nexport type { LogAttributes, LogBody, LogRecord } from './types/LogRecord';\nexport type { LoggerOptions } from './types/LoggerOptions';\nexport type { AnyValue, AnyValueMap } from './types/AnyValue';\nexport { NOOP_LOGGER, NoopLogger } from './NoopLogger';\nexport { ProxyLoggerProvider } from './ProxyLoggerProvider';\n\nimport { LogsAPI } from './api/logs';\nexport const logs = LogsAPI.getInstance();\n","import { ResourceDetector, ResourceDetectionConfig, DetectedResource } from '@opentelemetry/resources';\n\n/**\n * 业务专属资源探测器\n * 负责从环境变量中提取低代码平台特有的元数据 (Tenant, App, Env)\n */\nexport class PlatformDetector implements ResourceDetector {\n \n /**\n * 实现 detect 接口\n * @param config 探测配置 (可选)\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ndetect(config?: ResourceDetectionConfig): DetectedResource {\n // 1. 定义我们要提取的业务属性\n const attributes: Record<string, string | number | boolean> = {};\n\n // 2. 清洗数据:移除 undefined/null 的值,防止 OTel 报错\n const cleanAttributes = Object.entries(attributes).reduce((acc, [key, value]) => {\n if (value !== undefined && value !== null && value !== '') {\n acc[key] = value;\n }\n return acc;\n }, {} as Record<string, string | number | boolean>);\n\n // 3. 返回 Resource 对象\n // 注意:detect 方法必须返回一个 Promise\n return {\n attributes: cleanAttributes,\n }\n }\n}\n\nexport const lowCodeDetector = new PlatformDetector();","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface ExportResult {\n code: ExportResultCode;\n error?: Error;\n}\n\nexport enum ExportResultCode {\n SUCCESS,\n FAILED,\n}\n","import { randomBytes } from 'crypto';\n\nexport const idGenerator = {\n /**\n * 生成 TraceId (128-bit / 32-char hex)\n * 符合 W3C Trace Context 标准\n * 示例: \"5b8efff798038103d269b633813fc60c\"\n */\n generateTraceId(): string {\n // 16 字节 = 128 位,转为 hex 就是 32 个字符\n return randomBytes(16).toString('hex');\n },\n\n /**\n * 生成 SpanId (64-bit / 16-char hex)\n * 示例: \"eee19b7ec3c1b174\"\n */\n generateSpanId(): string {\n // 8 字节 = 64 位,转为 hex 就是 16 个字符\n return randomBytes(8).toString('hex');\n }\n};","import { LogRecordExporter, ReadableLogRecord,} from '@opentelemetry/sdk-logs';\nimport { ExportResult, ExportResultCode } from '@opentelemetry/core';\nimport { Attributes } from '@opentelemetry/api';\nimport { idGenerator } from '../utils/generateUUID';\n\nexport class CustomExporter implements LogRecordExporter {\n private logPrefix: string = \"force-log-prefix\"\n private logSuffix: string = \"force-log-suffix\"\n\n\n\n export(logs: ReadableLogRecord[], resultCallback: (result: ExportResult) => void) {\n // 初始化默认 log 内 attributes\n const defaultAttributes: Attributes = {\n tenant_id: 'default-tenant',\n user_id: 'default-user',\n app_id: 'default-app',\n uuid: idGenerator.generateTraceId(),\n };\n\n // 模拟 OTLP 的结构化过程\n const otlpLikeStructure = {\n resourceLogs: logs.map(log => ({\n resource: {\n attributes: log.resource.attributes,\n },\n logRecords: [{\n timeUnixNano: log.hrTime,\n observedTimeUnixNano: log.hrTimeObserved,\n severityNumber: log.severityNumber,\n severityText: log.severityText,\n body: { stringValue: log.body }, \n attributes:{\n ...defaultAttributes\n },\n traceId: log.spanContext?.traceId,\n spanId: log.spanContext?.spanId\n }]\n }))\n };\n \n console.log(this.logPrefix + JSON.stringify(otlpLikeStructure, null, 2) + this.logSuffix);\n resultCallback({ code: ExportRes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MACpC,KAAK;AAAS,eAAOL,eAAeM;MACpC;AAAS,eAAON,eAAeG;IACjC;EACF;AACF;AAGO,IAAMI,SAAS,IAAI1C,iBAAAA;","names":["SeverityNumber","PlatformDetector","detect","config","attributes","cleanAttributes","Object","entries","reduce","acc","key","value","undefined","lowCodeDetector","ExportResultCode","idGenerator","generateTraceId","randomBytes","toString","generateSpanId","CustomExporter","logPrefix","logSuffix","export","logs","resultCallback","defaultAttributes","tenant_id","user_id","app_id","uuid","idGenerator","generateTraceId","otlpLikeStructure","resourceLogs","map","log","resource","attributes","logRecords","timeUnixNano","hrTime","observedTimeUnixNano","hrTimeObserved","severityNumber","severityText","body","stringValue","traceId","spanContext","spanId","console","JSON","stringify","code","ExportResultCode","SUCCESS","shutdown","AppOTelLoggerSDK","sdk","logProcessor","start","resource","detectResources","detectors","PlatformDetector","logExporter","CustomExporter","BatchLogRecordProcessor","scheduledDelayMillis","maxExportBatchSize","NodeSDK","logRecordProcessor","traceExporter","undefined","log","level","message","attributes","logger","logs","getLogger","severityNumber","mapSeverity","emit","body","severityText","toUpperCase","timestamp","Date","flush","forceFlush","toLowerCase","SeverityNumber","TRACE","DEBUG","INFO","WARN","ERROR","FATAL","appSdk"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/core/sdk.ts","../../../../node_modules/@opentelemetry/api-logs/src/types/LogRecord.ts","../../../../node_modules/@opentelemetry/api-logs/src/NoopLogger.ts","../../../../node_modules/@opentelemetry/api-logs/src/NoopLoggerProvider.ts","../../../../node_modules/@opentelemetry/api-logs/src/ProxyLogger.ts","../../../../node_modules/@opentelemetry/api-logs/src/ProxyLoggerProvider.ts","../../../../node_modules/@opentelemetry/api-logs/src/platform/node/globalThis.ts","../../../../node_modules/@opentelemetry/api-logs/src/internal/global-utils.ts","../../../../node_modules/@opentelemetry/api-logs/src/api/logs.ts","../../../../node_modules/@opentelemetry/api-logs/src/index.ts","../src/core/resource-detector.ts","../../../../node_modules/@opentelemetry/core/src/ExportResult.ts","../src/utils/generateUUID.ts","../src/utils/hrTimeToNanoString.ts","../src/core/exportor.ts"],"sourcesContent":["export { AppOTelLoggerSDK } from './core/sdk';","// file: src/core/sdk.ts\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { detectResources } from '@opentelemetry/resources';\nimport { logs, SeverityNumber } from '@opentelemetry/api-logs';\nimport { PlatformDetector } from './resource-detector';\nimport type { LogAttributes } from '../type';\nimport { CustomExporter } from './exportor';\n\nexport class AppOTelLoggerSDK {\n private sdk: NodeSDK | null = null;\n private logProcessor: BatchLogRecordProcessor | null = null;\n\n start() {\n // 1. 探测并定义资源\n const resource = detectResources({\n detectors: [\n new PlatformDetector()\n ]\n });\n\n // 2. 配置数据出口 Exporter\n const logExporter = new CustomExporter();\n\n // 3. 配置 Processor\n // 手动创建是为了后面能调用它的 forceFlush\n this.logProcessor = new BatchLogRecordProcessor(logExporter, {\n scheduledDelayMillis: 1000,\n maxExportBatchSize: 512\n });\n\n // 4. 启动官方 SDK 底座\n this.sdk = new NodeSDK({\n resource,\n logRecordProcessor: this.logProcessor,\n // Trace 暂不实现\n traceExporter: undefined,\n });\n\n this.sdk.start();\n }\n \n /**\n * 用户使用的日志接口\n */\n public log(level: string, message: string, attributes: LogAttributes = {}) {\n const logger = logs.getLogger('app-logger');\n const severityNumber = this.mapSeverity(level);\n logger.emit({\n body: message,\n severityNumber: severityNumber,\n severityText: level.toUpperCase(),\n attributes: attributes,\n timestamp: new Date(),\n });\n }\n // FaaS 核心功能\n async flush() {\n if (this.logProcessor) {\n await this.logProcessor.forceFlush();\n }\n }\n\n private mapSeverity(level: string): SeverityNumber {\n switch (level.toLowerCase()) {\n case 'trace': return SeverityNumber.TRACE;\n case 'debug': return SeverityNumber.DEBUG;\n case 'info': return SeverityNumber.INFO;\n case 'warn': return SeverityNumber.WARN;\n case 'error': return SeverityNumber.ERROR;\n case 'fatal': return SeverityNumber.FATAL;\n default: return SeverityNumber.INFO;\n }\n }\n}\n\n// 导出单例\nexport const appSdk = new AppOTelLoggerSDK();","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Context, TimeInput } from '@opentelemetry/api';\nimport { AnyValue, AnyValueMap } from './AnyValue';\n\nexport type LogBody = AnyValue;\nexport type LogAttributes = AnyValueMap;\n\nexport enum SeverityNumber {\n UNSPECIFIED = 0,\n TRACE = 1,\n TRACE2 = 2,\n TRACE3 = 3,\n TRACE4 = 4,\n DEBUG = 5,\n DEBUG2 = 6,\n DEBUG3 = 7,\n DEBUG4 = 8,\n INFO = 9,\n INFO2 = 10,\n INFO3 = 11,\n INFO4 = 12,\n WARN = 13,\n WARN2 = 14,\n WARN3 = 15,\n WARN4 = 16,\n ERROR = 17,\n ERROR2 = 18,\n ERROR3 = 19,\n ERROR4 = 20,\n FATAL = 21,\n FATAL2 = 22,\n FATAL3 = 23,\n FATAL4 = 24,\n}\n\nexport interface LogRecord {\n /**\n * The unique identifier for the log record.\n */\n eventName?: string;\n\n /**\n * The time when the log record occurred as UNIX Epoch time in nanoseconds.\n */\n timestamp?: TimeInput;\n\n /**\n * Time when the event was observed by the collection system.\n */\n observedTimestamp?: TimeInput;\n\n /**\n * Numerical value of the severity.\n */\n severityNumber?: SeverityNumber;\n\n /**\n * The severity text.\n */\n severityText?: string;\n\n /**\n * A value containing the body of the log record.\n */\n body?: LogBody;\n\n /**\n * Attributes that define the log record.\n */\n attributes?: LogAttributes;\n\n /**\n * The Context associated with the LogRecord.\n */\n context?: Context;\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Logger } from './types/Logger';\nimport { LogRecord } from './types/LogRecord';\n\nexport class NoopLogger implements Logger {\n emit(_logRecord: LogRecord): void {}\n}\n\nexport const NOOP_LOGGER = new NoopLogger();\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from './types/LoggerProvider';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { NoopLogger } from './NoopLogger';\n\nexport class NoopLoggerProvider implements LoggerProvider {\n getLogger(\n _name: string,\n _version?: string | undefined,\n _options?: LoggerOptions | undefined\n ): Logger {\n return new NoopLogger();\n }\n}\n\nexport const NOOP_LOGGER_PROVIDER = new NoopLoggerProvider();\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { NOOP_LOGGER } from './NoopLogger';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { LogRecord } from './types/LogRecord';\n\nexport class ProxyLogger implements Logger {\n // When a real implementation is provided, this will be it\n private _delegate?: Logger;\n\n constructor(\n private _provider: LoggerDelegator,\n public readonly name: string,\n public readonly version?: string | undefined,\n public readonly options?: LoggerOptions | undefined\n ) {}\n\n /**\n * Emit a log record. This method should only be used by log appenders.\n *\n * @param logRecord\n */\n emit(logRecord: LogRecord): void {\n this._getLogger().emit(logRecord);\n }\n\n /**\n * Try to get a logger from the proxy logger provider.\n * If the proxy logger provider has no delegate, return a noop logger.\n */\n private _getLogger() {\n if (this._delegate) {\n return this._delegate;\n }\n const logger = this._provider._getDelegateLogger(\n this.name,\n this.version,\n this.options\n );\n if (!logger) {\n return NOOP_LOGGER;\n }\n this._delegate = logger;\n return this._delegate;\n }\n}\n\nexport interface LoggerDelegator {\n _getDelegateLogger(\n name: string,\n version?: string,\n options?: LoggerOptions\n ): Logger | undefined;\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from './types/LoggerProvider';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { NOOP_LOGGER_PROVIDER } from './NoopLoggerProvider';\nimport { ProxyLogger } from './ProxyLogger';\n\nexport class ProxyLoggerProvider implements LoggerProvider {\n private _delegate?: LoggerProvider;\n\n getLogger(\n name: string,\n version?: string | undefined,\n options?: LoggerOptions | undefined\n ): Logger {\n return (\n this._getDelegateLogger(name, version, options) ??\n new ProxyLogger(this, name, version, options)\n );\n }\n\n /**\n * Get the delegate logger provider.\n * Used by tests only.\n * @internal\n */\n _getDelegate(): LoggerProvider {\n return this._delegate ?? NOOP_LOGGER_PROVIDER;\n }\n\n /**\n * Set the delegate logger provider\n * @internal\n */\n _setDelegate(delegate: LoggerProvider) {\n this._delegate = delegate;\n }\n\n /**\n * @internal\n */\n _getDelegateLogger(\n name: string,\n version?: string | undefined,\n options?: LoggerOptions | undefined\n ): Logger | undefined {\n return this._delegate?.getLogger(name, version, options);\n }\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** only globals that common to node and browsers are allowed */\n// eslint-disable-next-line n/no-unsupported-features/es-builtins\nexport const _globalThis = typeof globalThis === 'object' ? globalThis : global;\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from '../types/LoggerProvider';\nimport { _globalThis } from '../platform';\n\nexport const GLOBAL_LOGS_API_KEY = Symbol.for('io.opentelemetry.js.api.logs');\n\ntype Get<T> = (version: number) => T;\ntype OtelGlobal = Partial<{\n [GLOBAL_LOGS_API_KEY]: Get<LoggerProvider>;\n}>;\n\nexport const _global = _globalThis as OtelGlobal;\n\n/**\n * Make a function which accepts a version integer and returns the instance of an API if the version\n * is compatible, or a fallback version (usually NOOP) if it is not.\n *\n * @param requiredVersion Backwards compatibility version which is required to return the instance\n * @param instance Instance which should be returned if the required version is compatible\n * @param fallback Fallback instance, usually NOOP, which will be returned if the required version is not compatible\n */\nexport function makeGetter<T>(\n requiredVersion: number,\n instance: T,\n fallback: T\n): Get<T> {\n return (version: number): T =>\n version === requiredVersion ? instance : fallback;\n}\n\n/**\n * A number which should be incremented each time a backwards incompatible\n * change is made to the API. This number is used when an API package\n * attempts to access the global API to ensure it is getting a compatible\n * version. If the global API is not compatible with the API package\n * attempting to get it, a NOOP API implementation will be returned.\n */\nexport const API_BACKWARDS_COMPATIBILITY_VERSION = 1;\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n API_BACKWARDS_COMPATIBILITY_VERSION,\n GLOBAL_LOGS_API_KEY,\n _global,\n makeGetter,\n} from '../internal/global-utils';\nimport { LoggerProvider } from '../types/LoggerProvider';\nimport { NOOP_LOGGER_PROVIDER } from '../NoopLoggerProvider';\nimport { Logger } from '../types/Logger';\nimport { LoggerOptions } from '../types/LoggerOptions';\nimport { ProxyLoggerProvider } from '../ProxyLoggerProvider';\n\nexport class LogsAPI {\n private static _instance?: LogsAPI;\n\n private _proxyLoggerProvider = new ProxyLoggerProvider();\n\n private constructor() {}\n\n public static getInstance(): LogsAPI {\n if (!this._instance) {\n this._instance = new LogsAPI();\n }\n\n return this._instance;\n }\n\n public setGlobalLoggerProvider(provider: LoggerProvider): LoggerProvider {\n if (_global[GLOBAL_LOGS_API_KEY]) {\n return this.getLoggerProvider();\n }\n\n _global[GLOBAL_LOGS_API_KEY] = makeGetter<LoggerProvider>(\n API_BACKWARDS_COMPATIBILITY_VERSION,\n provider,\n NOOP_LOGGER_PROVIDER\n );\n this._proxyLoggerProvider._setDelegate(provider);\n\n return provider;\n }\n\n /**\n * Returns the global logger provider.\n *\n * @returns LoggerProvider\n */\n public getLoggerProvider(): LoggerProvider {\n return (\n _global[GLOBAL_LOGS_API_KEY]?.(API_BACKWARDS_COMPATIBILITY_VERSION) ??\n this._proxyLoggerProvider\n );\n }\n\n /**\n * Returns a logger from the global logger provider.\n *\n * @returns Logger\n */\n public getLogger(\n name: string,\n version?: string,\n options?: LoggerOptions\n ): Logger {\n return this.getLoggerProvider().getLogger(name, version, options);\n }\n\n /** Remove the global logger provider */\n public disable(): void {\n delete _global[GLOBAL_LOGS_API_KEY];\n this._proxyLoggerProvider = new ProxyLoggerProvider();\n }\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type { Logger } from './types/Logger';\nexport type { LoggerProvider } from './types/LoggerProvider';\nexport { SeverityNumber } from './types/LogRecord';\nexport type { LogAttributes, LogBody, LogRecord } from './types/LogRecord';\nexport type { LoggerOptions } from './types/LoggerOptions';\nexport type { AnyValue, AnyValueMap } from './types/AnyValue';\nexport { NOOP_LOGGER, NoopLogger } from './NoopLogger';\nexport { ProxyLoggerProvider } from './ProxyLoggerProvider';\n\nimport { LogsAPI } from './api/logs';\nexport const logs = LogsAPI.getInstance();\n","import { ResourceDetector, ResourceDetectionConfig, DetectedResource } from '@opentelemetry/resources';\n\n/**\n * 业务专属资源探测器\n * 负责从环境变量中提取低代码平台特有的元数据 (Tenant, App, Env)\n */\nexport class PlatformDetector implements ResourceDetector {\n \n /**\n * 实现 detect 接口\n * @param config 探测配置 (可选)\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ndetect(config?: ResourceDetectionConfig): DetectedResource {\n // 1. 定义我们要提取的业务属性\n const attributes: Record<string, string | number | boolean> = {};\n\n // 2. 清洗数据:移除 undefined/null 的值,防止 OTel 报错\n const cleanAttributes = Object.entries(attributes).reduce((acc, [key, value]) => {\n if (value !== undefined && value !== null && value !== '') {\n acc[key] = value;\n }\n return acc;\n }, {} as Record<string, string | number | boolean>);\n\n // 3. 返回 Resource 对象\n // 注意:detect 方法必须返回一个 Promise\n return {\n attributes: cleanAttributes,\n }\n }\n}\n\nexport const lowCodeDetector = new PlatformDetector();","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface ExportResult {\n code: ExportResultCode;\n error?: Error;\n}\n\nexport enum ExportResultCode {\n SUCCESS,\n FAILED,\n}\n","import { randomBytes } from 'crypto';\n\nexport const idGenerator = {\n /**\n * 生成 TraceId (128-bit / 32-char hex)\n * 符合 W3C Trace Context 标准\n * 示例: \"5b8efff798038103d269b633813fc60c\"\n */\n generateTraceId(): string {\n // 16 字节 = 128 位,转为 hex 就是 32 个字符\n return randomBytes(16).toString('hex');\n },\n\n /**\n * 生成 SpanId (64-bit / 16-char hex)\n * 示例: \"eee19b7ec3c1b174\"\n */\n generateSpanId(): string {\n // 8 字节 = 64 位,转为 hex 就是 16 个字符\n return randomBytes(8).toString('hex');\n }\n};","import type { HrTime } from '@opentelemetry/api';\n/**\n * 将 HrTime 转换为纳秒字符串\n * 使用 BigInt 防止精度丢失\n*/\nexport function hrTimeToNanosString(hrTime: HrTime): string {\n // 将秒转换为 BigInt\n const seconds = BigInt(hrTime[0]);\n // 将纳秒转换为 BigInt\n const nanos = BigInt(hrTime[1]);\n \n // 计算总纳秒数: seconds * 10^9 + nanos\n // 注意:数字后面加 'n' 表示 BigInt 字面量,或者使用 BigInt() 构造函数\n const totalNanos = (seconds * 1_000_000_000n) + nanos;\n \n return totalNanos.toString();\n}","import { LogRecordExporter, ReadableLogRecord,} from '@opentelemetry/sdk-logs';\nimport { ExportResult, ExportResultCode } from '@opentelemetry/core';\nimport { Attributes } from '@opentelemetry/api';\nimport { idGenerator } from '../utils/generateUUID';\nimport { hrTimeToNanosString } from '../utils/hrTimeToNanoString';\n\nexport class CustomExporter implements LogRecordExporter {\n private logPrefix: string = \"force-log-prefix\"\n private logSuffix: string = \"force-log-suffix\"\n\n\n\n export(logs: ReadableLogRecord[], resultCallback: (result: ExportResult) => void) {\n // 初始化默认 log 内 attributes\n const defaultAttributes: Attributes = {\n tenant_id: 'default-tenant',\n user_id: 'default-user',\n app_id: 'default-app',\n uuid: idGenerator.generateTraceId(),\n };\n\n // 模拟 OTLP 的结构化过程\n const otlpLikeStructure = {\n resourceLogs: logs.map(log => ({\n resource: {\n // resource.attributes 暂时置空\n // attributes: log.resource.attributes,\n attributes: {}\n },\n logRecords: [{\n timeUnixNano: hrTimeToNanosString(log.hrTime),\n observedTimeUnixNano: hrTimeToNanosString(log.hrTimeObserved),\n severityNumber: log.severityNumber,\n severityText: log.severityText,\n body: { stringValue: log.body }, \n attributes:{\n ...defaultAttributes\n },\n traceId: log.spanContext?.traceId,\n spanId: log.spanContext?.spanId\n }]\n }))\n };\n\n console.log(this.logPrefix + JSON.stringify(otlpLikeStructure, null, 2) + this.logSuffix);\n resultCallback({ code: Export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ACtC;EACJ;EAEQR,YAAYP,OAA+B;AACnD,YAAQA,MAAMgB,YAAW,GAAA;MACvB,KAAK;AAAS,eAAOC,eAAeC;MACpC,KAAK;AAAS,eAAOD,eAAeE;MACpC,KAAK;AAAQ,eAAOF,eAAeG;MACnC,KAAK;AAAQ,eAAOH,eAAeI;MACnC,KAAK;AAAS,eAAOJ,eAAeK;MACpC,KAAK;AAAS,eAAOL,eAAeM;MACpC;AAAS,eAAON,eAAeG;IACjC;EACF;AACF;AAGO,IAAMI,SAAS,IAAI1C,iBAAAA;","names":["SeverityNumber","PlatformDetector","detect","config","attributes","cleanAttributes","Object","entries","reduce","acc","key","value","undefined","lowCodeDetector","ExportResultCode","idGenerator","generateTraceId","randomBytes","toString","generateSpanId","hrTimeToNanosString","hrTime","seconds","BigInt","nanos","totalNanos","toString","CustomExporter","logPrefix","logSuffix","export","logs","resultCallback","defaultAttributes","tenant_id","user_id","app_id","uuid","idGenerator","generateTraceId","otlpLikeStructure","resourceLogs","map","log","resource","attributes","logRecords","timeUnixNano","hrTimeToNanosString","hrTime","observedTimeUnixNano","hrTimeObserved","severityNumber","severityText","body","stringValue","traceId","spanContext","spanId","console","JSON","stringify","code","ExportResultCode","SUCCESS","shutdown","AppOTelLoggerSDK","sdk","logProcessor","start","resource","detectResources","detectors","PlatformDetector","logExporter","CustomExporter","BatchLogRecordProcessor","scheduledDelayMillis","maxExportBatchSize","NodeSDK","logRecordProcessor","traceExporter","undefined","log","level","message","attributes","logger","logs","getLogger","severityNumber","mapSeverity","emit","body","severityText","toUpperCase","timestamp","Date","flush","forceFlush","toLowerCase","SeverityNumber","TRACE","DEBUG","INFO","WARN","ERROR","FATAL","appSdk"]}
package/dist/index.js CHANGED
@@ -131,7 +131,7 @@ var ProxyLoggerProvider = class {
131
131
  var _globalThis = typeof globalThis === "object" ? globalThis : global;
132
132
 
133
133
  // ../../../node_modules/@opentelemetry/api-logs/build/esm/internal/global-utils.js
134
- var GLOBAL_LOGS_API_KEY = Symbol.for("io.opentelemetry.js.api.logs");
134
+ var GLOBAL_LOGS_API_KEY = /* @__PURE__ */ Symbol.for("io.opentelemetry.js.api.logs");
135
135
  var _global = _globalThis;
136
136
  function makeGetter(requiredVersion, instance, fallback) {
137
137
  return (version) => version === requiredVersion ? instance : fallback;
@@ -240,6 +240,15 @@ var idGenerator = {
240
240
  }
241
241
  };
242
242
 
243
+ // src/utils/hrTimeToNanoString.ts
244
+ function hrTimeToNanosString(hrTime) {
245
+ const seconds = BigInt(hrTime[0]);
246
+ const nanos = BigInt(hrTime[1]);
247
+ const totalNanos = seconds * 1000000000n + nanos;
248
+ return totalNanos.toString();
249
+ }
250
+ __name(hrTimeToNanosString, "hrTimeToNanosString");
251
+
243
252
  // src/core/exportor.ts
244
253
  var CustomExporter = class {
245
254
  static {
@@ -257,12 +266,14 @@ var CustomExporter = class {
257
266
  const otlpLikeStructure = {
258
267
  resourceLogs: logs2.map((log) => ({
259
268
  resource: {
260
- attributes: log.resource.attributes
269
+ // resource.attributes 暂时置空
270
+ // attributes: log.resource.attributes,
271
+ attributes: {}
261
272
  },
262
273
  logRecords: [
263
274
  {
264
- timeUnixNano: log.hrTime,
265
- observedTimeUnixNano: log.hrTimeObserved,
275
+ timeUnixNano: hrTimeToNanosString(log.hrTime),
276
+ observedTimeUnixNano: hrTimeToNanosString(log.hrTimeObserved),
266
277
  severityNumber: log.severityNumber,
267
278
  severityText: log.severityText,
268
279
  body: {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/sdk.ts","../../../../node_modules/@opentelemetry/api-logs/src/types/LogRecord.ts","../../../../node_modules/@opentelemetry/api-logs/src/NoopLogger.ts","../../../../node_modules/@opentelemetry/api-logs/src/NoopLoggerProvider.ts","../../../../node_modules/@opentelemetry/api-logs/src/ProxyLogger.ts","../../../../node_modules/@opentelemetry/api-logs/src/ProxyLoggerProvider.ts","../../../../node_modules/@opentelemetry/api-logs/src/platform/node/globalThis.ts","../../../../node_modules/@opentelemetry/api-logs/src/internal/global-utils.ts","../../../../node_modules/@opentelemetry/api-logs/src/api/logs.ts","../../../../node_modules/@opentelemetry/api-logs/src/index.ts","../src/core/resource-detector.ts","../../../../node_modules/@opentelemetry/core/src/ExportResult.ts","../src/utils/generateUUID.ts","../src/core/exportor.ts"],"sourcesContent":["// file: src/core/sdk.ts\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { detectResources } from '@opentelemetry/resources';\nimport { logs, SeverityNumber } from '@opentelemetry/api-logs';\nimport { PlatformDetector } from './resource-detector';\nimport type { LogAttributes } from '../type';\nimport { CustomExporter } from './exportor';\n\nexport class AppOTelLoggerSDK {\n private sdk: NodeSDK | null = null;\n private logProcessor: BatchLogRecordProcessor | null = null;\n\n start() {\n // 1. 探测并定义资源\n const resource = detectResources({\n detectors: [\n new PlatformDetector()\n ]\n });\n\n // 2. 配置数据出口 Exporter\n const logExporter = new CustomExporter();\n\n // 3. 配置 Processor\n // 手动创建是为了后面能调用它的 forceFlush\n this.logProcessor = new BatchLogRecordProcessor(logExporter, {\n scheduledDelayMillis: 1000,\n maxExportBatchSize: 512\n });\n\n // 4. 启动官方 SDK 底座\n this.sdk = new NodeSDK({\n resource,\n logRecordProcessor: this.logProcessor,\n // Trace 暂不实现\n traceExporter: undefined,\n });\n\n this.sdk.start();\n }\n \n /**\n * 用户使用的日志接口\n */\n public log(level: string, message: string, attributes: LogAttributes = {}) {\n const logger = logs.getLogger('app-logger');\n const severityNumber = this.mapSeverity(level);\n logger.emit({\n body: message,\n severityNumber: severityNumber,\n severityText: level.toUpperCase(),\n attributes: attributes,\n timestamp: new Date(),\n });\n }\n // FaaS 核心功能\n async flush() {\n if (this.logProcessor) {\n await this.logProcessor.forceFlush();\n }\n }\n\n private mapSeverity(level: string): SeverityNumber {\n switch (level.toLowerCase()) {\n case 'trace': return SeverityNumber.TRACE;\n case 'debug': return SeverityNumber.DEBUG;\n case 'info': return SeverityNumber.INFO;\n case 'warn': return SeverityNumber.WARN;\n case 'error': return SeverityNumber.ERROR;\n case 'fatal': return SeverityNumber.FATAL;\n default: return SeverityNumber.INFO;\n }\n }\n}\n\n// 导出单例\nexport const appSdk = new AppOTelLoggerSDK();","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Context, TimeInput } from '@opentelemetry/api';\nimport { AnyValue, AnyValueMap } from './AnyValue';\n\nexport type LogBody = AnyValue;\nexport type LogAttributes = AnyValueMap;\n\nexport enum SeverityNumber {\n UNSPECIFIED = 0,\n TRACE = 1,\n TRACE2 = 2,\n TRACE3 = 3,\n TRACE4 = 4,\n DEBUG = 5,\n DEBUG2 = 6,\n DEBUG3 = 7,\n DEBUG4 = 8,\n INFO = 9,\n INFO2 = 10,\n INFO3 = 11,\n INFO4 = 12,\n WARN = 13,\n WARN2 = 14,\n WARN3 = 15,\n WARN4 = 16,\n ERROR = 17,\n ERROR2 = 18,\n ERROR3 = 19,\n ERROR4 = 20,\n FATAL = 21,\n FATAL2 = 22,\n FATAL3 = 23,\n FATAL4 = 24,\n}\n\nexport interface LogRecord {\n /**\n * The unique identifier for the log record.\n */\n eventName?: string;\n\n /**\n * The time when the log record occurred as UNIX Epoch time in nanoseconds.\n */\n timestamp?: TimeInput;\n\n /**\n * Time when the event was observed by the collection system.\n */\n observedTimestamp?: TimeInput;\n\n /**\n * Numerical value of the severity.\n */\n severityNumber?: SeverityNumber;\n\n /**\n * The severity text.\n */\n severityText?: string;\n\n /**\n * A value containing the body of the log record.\n */\n body?: LogBody;\n\n /**\n * Attributes that define the log record.\n */\n attributes?: LogAttributes;\n\n /**\n * The Context associated with the LogRecord.\n */\n context?: Context;\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Logger } from './types/Logger';\nimport { LogRecord } from './types/LogRecord';\n\nexport class NoopLogger implements Logger {\n emit(_logRecord: LogRecord): void {}\n}\n\nexport const NOOP_LOGGER = new NoopLogger();\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from './types/LoggerProvider';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { NoopLogger } from './NoopLogger';\n\nexport class NoopLoggerProvider implements LoggerProvider {\n getLogger(\n _name: string,\n _version?: string | undefined,\n _options?: LoggerOptions | undefined\n ): Logger {\n return new NoopLogger();\n }\n}\n\nexport const NOOP_LOGGER_PROVIDER = new NoopLoggerProvider();\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { NOOP_LOGGER } from './NoopLogger';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { LogRecord } from './types/LogRecord';\n\nexport class ProxyLogger implements Logger {\n // When a real implementation is provided, this will be it\n private _delegate?: Logger;\n\n constructor(\n private _provider: LoggerDelegator,\n public readonly name: string,\n public readonly version?: string | undefined,\n public readonly options?: LoggerOptions | undefined\n ) {}\n\n /**\n * Emit a log record. This method should only be used by log appenders.\n *\n * @param logRecord\n */\n emit(logRecord: LogRecord): void {\n this._getLogger().emit(logRecord);\n }\n\n /**\n * Try to get a logger from the proxy logger provider.\n * If the proxy logger provider has no delegate, return a noop logger.\n */\n private _getLogger() {\n if (this._delegate) {\n return this._delegate;\n }\n const logger = this._provider._getDelegateLogger(\n this.name,\n this.version,\n this.options\n );\n if (!logger) {\n return NOOP_LOGGER;\n }\n this._delegate = logger;\n return this._delegate;\n }\n}\n\nexport interface LoggerDelegator {\n _getDelegateLogger(\n name: string,\n version?: string,\n options?: LoggerOptions\n ): Logger | undefined;\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from './types/LoggerProvider';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { NOOP_LOGGER_PROVIDER } from './NoopLoggerProvider';\nimport { ProxyLogger } from './ProxyLogger';\n\nexport class ProxyLoggerProvider implements LoggerProvider {\n private _delegate?: LoggerProvider;\n\n getLogger(\n name: string,\n version?: string | undefined,\n options?: LoggerOptions | undefined\n ): Logger {\n return (\n this._getDelegateLogger(name, version, options) ??\n new ProxyLogger(this, name, version, options)\n );\n }\n\n /**\n * Get the delegate logger provider.\n * Used by tests only.\n * @internal\n */\n _getDelegate(): LoggerProvider {\n return this._delegate ?? NOOP_LOGGER_PROVIDER;\n }\n\n /**\n * Set the delegate logger provider\n * @internal\n */\n _setDelegate(delegate: LoggerProvider) {\n this._delegate = delegate;\n }\n\n /**\n * @internal\n */\n _getDelegateLogger(\n name: string,\n version?: string | undefined,\n options?: LoggerOptions | undefined\n ): Logger | undefined {\n return this._delegate?.getLogger(name, version, options);\n }\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** only globals that common to node and browsers are allowed */\n// eslint-disable-next-line n/no-unsupported-features/es-builtins\nexport const _globalThis = typeof globalThis === 'object' ? globalThis : global;\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from '../types/LoggerProvider';\nimport { _globalThis } from '../platform';\n\nexport const GLOBAL_LOGS_API_KEY = Symbol.for('io.opentelemetry.js.api.logs');\n\ntype Get<T> = (version: number) => T;\ntype OtelGlobal = Partial<{\n [GLOBAL_LOGS_API_KEY]: Get<LoggerProvider>;\n}>;\n\nexport const _global = _globalThis as OtelGlobal;\n\n/**\n * Make a function which accepts a version integer and returns the instance of an API if the version\n * is compatible, or a fallback version (usually NOOP) if it is not.\n *\n * @param requiredVersion Backwards compatibility version which is required to return the instance\n * @param instance Instance which should be returned if the required version is compatible\n * @param fallback Fallback instance, usually NOOP, which will be returned if the required version is not compatible\n */\nexport function makeGetter<T>(\n requiredVersion: number,\n instance: T,\n fallback: T\n): Get<T> {\n return (version: number): T =>\n version === requiredVersion ? instance : fallback;\n}\n\n/**\n * A number which should be incremented each time a backwards incompatible\n * change is made to the API. This number is used when an API package\n * attempts to access the global API to ensure it is getting a compatible\n * version. If the global API is not compatible with the API package\n * attempting to get it, a NOOP API implementation will be returned.\n */\nexport const API_BACKWARDS_COMPATIBILITY_VERSION = 1;\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n API_BACKWARDS_COMPATIBILITY_VERSION,\n GLOBAL_LOGS_API_KEY,\n _global,\n makeGetter,\n} from '../internal/global-utils';\nimport { LoggerProvider } from '../types/LoggerProvider';\nimport { NOOP_LOGGER_PROVIDER } from '../NoopLoggerProvider';\nimport { Logger } from '../types/Logger';\nimport { LoggerOptions } from '../types/LoggerOptions';\nimport { ProxyLoggerProvider } from '../ProxyLoggerProvider';\n\nexport class LogsAPI {\n private static _instance?: LogsAPI;\n\n private _proxyLoggerProvider = new ProxyLoggerProvider();\n\n private constructor() {}\n\n public static getInstance(): LogsAPI {\n if (!this._instance) {\n this._instance = new LogsAPI();\n }\n\n return this._instance;\n }\n\n public setGlobalLoggerProvider(provider: LoggerProvider): LoggerProvider {\n if (_global[GLOBAL_LOGS_API_KEY]) {\n return this.getLoggerProvider();\n }\n\n _global[GLOBAL_LOGS_API_KEY] = makeGetter<LoggerProvider>(\n API_BACKWARDS_COMPATIBILITY_VERSION,\n provider,\n NOOP_LOGGER_PROVIDER\n );\n this._proxyLoggerProvider._setDelegate(provider);\n\n return provider;\n }\n\n /**\n * Returns the global logger provider.\n *\n * @returns LoggerProvider\n */\n public getLoggerProvider(): LoggerProvider {\n return (\n _global[GLOBAL_LOGS_API_KEY]?.(API_BACKWARDS_COMPATIBILITY_VERSION) ??\n this._proxyLoggerProvider\n );\n }\n\n /**\n * Returns a logger from the global logger provider.\n *\n * @returns Logger\n */\n public getLogger(\n name: string,\n version?: string,\n options?: LoggerOptions\n ): Logger {\n return this.getLoggerProvider().getLogger(name, version, options);\n }\n\n /** Remove the global logger provider */\n public disable(): void {\n delete _global[GLOBAL_LOGS_API_KEY];\n this._proxyLoggerProvider = new ProxyLoggerProvider();\n }\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type { Logger } from './types/Logger';\nexport type { LoggerProvider } from './types/LoggerProvider';\nexport { SeverityNumber } from './types/LogRecord';\nexport type { LogAttributes, LogBody, LogRecord } from './types/LogRecord';\nexport type { LoggerOptions } from './types/LoggerOptions';\nexport type { AnyValue, AnyValueMap } from './types/AnyValue';\nexport { NOOP_LOGGER, NoopLogger } from './NoopLogger';\nexport { ProxyLoggerProvider } from './ProxyLoggerProvider';\n\nimport { LogsAPI } from './api/logs';\nexport const logs = LogsAPI.getInstance();\n","import { ResourceDetector, ResourceDetectionConfig, DetectedResource } from '@opentelemetry/resources';\n\n/**\n * 业务专属资源探测器\n * 负责从环境变量中提取低代码平台特有的元数据 (Tenant, App, Env)\n */\nexport class PlatformDetector implements ResourceDetector {\n \n /**\n * 实现 detect 接口\n * @param config 探测配置 (可选)\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ndetect(config?: ResourceDetectionConfig): DetectedResource {\n // 1. 定义我们要提取的业务属性\n const attributes: Record<string, string | number | boolean> = {};\n\n // 2. 清洗数据:移除 undefined/null 的值,防止 OTel 报错\n const cleanAttributes = Object.entries(attributes).reduce((acc, [key, value]) => {\n if (value !== undefined && value !== null && value !== '') {\n acc[key] = value;\n }\n return acc;\n }, {} as Record<string, string | number | boolean>);\n\n // 3. 返回 Resource 对象\n // 注意:detect 方法必须返回一个 Promise\n return {\n attributes: cleanAttributes,\n }\n }\n}\n\nexport const lowCodeDetector = new PlatformDetector();","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface ExportResult {\n code: ExportResultCode;\n error?: Error;\n}\n\nexport enum ExportResultCode {\n SUCCESS,\n FAILED,\n}\n","import { randomBytes } from 'crypto';\n\nexport const idGenerator = {\n /**\n * 生成 TraceId (128-bit / 32-char hex)\n * 符合 W3C Trace Context 标准\n * 示例: \"5b8efff798038103d269b633813fc60c\"\n */\n generateTraceId(): string {\n // 16 字节 = 128 位,转为 hex 就是 32 个字符\n return randomBytes(16).toString('hex');\n },\n\n /**\n * 生成 SpanId (64-bit / 16-char hex)\n * 示例: \"eee19b7ec3c1b174\"\n */\n generateSpanId(): string {\n // 8 字节 = 64 位,转为 hex 就是 16 个字符\n return randomBytes(8).toString('hex');\n }\n};","import { LogRecordExporter, ReadableLogRecord,} from '@opentelemetry/sdk-logs';\nimport { ExportResult, ExportResultCode } from '@opentelemetry/core';\nimport { Attributes } from '@opentelemetry/api';\nimport { idGenerator } from '../utils/generateUUID';\n\nexport class CustomExporter implements LogRecordExporter {\n private logPrefix: string = \"force-log-prefix\"\n private logSuffix: string = \"force-log-suffix\"\n\n\n\n export(logs: ReadableLogRecord[], resultCallback: (result: ExportResult) => void) {\n // 初始化默认 log 内 attributes\n const defaultAttributes: Attributes = {\n tenant_id: 'default-tenant',\n user_id: 'default-user',\n app_id: 'default-app',\n uuid: idGenerator.generateTraceId(),\n };\n\n // 模拟 OTLP 的结构化过程\n const otlpLikeStructure = {\n resourceLogs: logs.map(log => ({\n resource: {\n attributes: log.resource.attributes,\n },\n logRecords: [{\n timeUnixNano: log.hrTime,\n observedTimeUnixNano: log.hrTimeObserved,\n severityNumber: log.severityNumber,\n severityText: log.severityText,\n body: { stringValue: log.body }, \n attributes:{\n ...defaultAttributes\n },\n traceId: log.spanContext?.traceId,\n spanId: log.spanContext?.spanId\n }]\n }))\n };\n \n console.log(this.logPrefix + JSON.stringify(otlpLikeStructure, null, 2) + this.logSuffix);\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n async shutdown() {}\n}"],"mappings":";;;;AACA,SAASA,eAAe;AACxB,SAASC,+BAA+B;AACxC,SAASC,uBAAuB;;;ACmBhC,IAAY;CAAZ,SAAYC,iBAAc;AACxB,EAAAA,gBAAAA,gBAAA,aAAA,IAAA,CAAA,IAAA;AACA,EAAAA,gBAAAA,gBAAA,OAAA,IAAA,CAAA,IAAA;AACA,EAAAA,gBAAAA,gBAAA,QAAA,IAAA,CAAA,IAAA;AACA,EAAAA,gBAAAA,gBAAA,QAAA,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,WAAWC,gBAAgB;MAC7BC,WAAW;QACP,IAAIC,iBAAAA;;IAEZ,CAAA;AAGA,UAAMC,cAAc,IAAIC,eAAAA;AAIxB,SAAKP,eAAe,IAAIQ,wBAAwBF,aAAa;MACzDG,sBAAsB;MACtBC,oBAAoB;IACxB,CAAA;AAGA,SAAKX,MAAM,IAAIY,QAAQ;MACnBT;MACAU,oBAAoB,KAAKZ;;MAEzBa,eAAeC;IACnB,CAAA;AAEA,SAAKf,IAAIE,MAAK;EAClB;;;;EAKKc,IAAIC,OAAeC,SAAiBC,aAA4B,CAAC,GAAG;AACzE,UAAMC,SAASC,KAAKC,UAAU,YAAA;AAC9B,UAAMC,iBAAiB,KAAKC,YAAYP,KAAAA;AACxCG,WAAOK,KAAK;MACVC,MAAMR;MACNK;MACAI,cAAcV,MAAMW,YAAW;MAC/BT;MACAU,WAAW,oBAAIC,KAAAA;IACjB,CAAA;EACF;;EAEE,MAAMC,QAAQ;AACV,QAAI,KAAK9B,cAAc;AACnB,YAAM,KAAKA,aAAa+B,WAAU;IACtC;EACJ;EAEQR,YAAYP,OAA+B;AACnD,YAAQA,MAAMgB,YAAW,GAAA;MACvB,KAAK;AAAS,eAAOC,eAAeC;MACpC,KAAK;AAAS,eAAOD,eAAeE;MACpC,KAAK;AAAQ,eAAOF,eAAeG;MACnC,KAAK;AAAQ,eAAOH,eAAeI;MACnC,KAAK;AAAS,eAAOJ,eAAeK;MACpC,KAAK;AAAS,eAAOL,eAAeM;MACpC;AAAS,eAAON,eAAeG;IACjC;EACF;AACF;AAGO,IAAMI,SAAS,IAAI1C,iBAAAA;","names":["NodeSDK","BatchLogRecordProcessor","detectResources","SeverityNumber","PlatformDetector","detect","config","attributes","cleanAttributes","Object","entries","reduce","acc","key","value","undefined","lowCodeDetector","ExportResultCode","randomBytes","idGenerator","generateTraceId","toString","generateSpanId","CustomExporter","logPrefix","logSuffix","export","logs","resultCallback","defaultAttributes","tenant_id","user_id","app_id","uuid","idGenerator","generateTraceId","otlpLikeStructure","resourceLogs","map","log","resource","attributes","logRecords","timeUnixNano","hrTime","observedTimeUnixNano","hrTimeObserved","severityNumber","severityText","body","stringValue","traceId","spanContext","spanId","console","JSON","stringify","code","ExportResultCode","SUCCESS","shutdown","AppOTelLoggerSDK","sdk","logProcessor","start","resource","detectResources","detectors","PlatformDetector","logExporter","CustomExporter","BatchLogRecordProcessor","scheduledDelayMillis","maxExportBatchSize","NodeSDK","logRecordProcessor","traceExporter","undefined","log","level","message","attributes","logger","logs","getLogger","severityNumber","mapSeverity","emit","body","severityText","toUpperCase","timestamp","Date","flush","forceFlush","toLowerCase","SeverityNumber","TRACE","DEBUG","INFO","WARN","ERROR","FATAL","appSdk"]}
1
+ {"version":3,"sources":["../src/core/sdk.ts","../../../../node_modules/@opentelemetry/api-logs/src/types/LogRecord.ts","../../../../node_modules/@opentelemetry/api-logs/src/NoopLogger.ts","../../../../node_modules/@opentelemetry/api-logs/src/NoopLoggerProvider.ts","../../../../node_modules/@opentelemetry/api-logs/src/ProxyLogger.ts","../../../../node_modules/@opentelemetry/api-logs/src/ProxyLoggerProvider.ts","../../../../node_modules/@opentelemetry/api-logs/src/platform/node/globalThis.ts","../../../../node_modules/@opentelemetry/api-logs/src/internal/global-utils.ts","../../../../node_modules/@opentelemetry/api-logs/src/api/logs.ts","../../../../node_modules/@opentelemetry/api-logs/src/index.ts","../src/core/resource-detector.ts","../../../../node_modules/@opentelemetry/core/src/ExportResult.ts","../src/utils/generateUUID.ts","../src/utils/hrTimeToNanoString.ts","../src/core/exportor.ts"],"sourcesContent":["// file: src/core/sdk.ts\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { detectResources } from '@opentelemetry/resources';\nimport { logs, SeverityNumber } from '@opentelemetry/api-logs';\nimport { PlatformDetector } from './resource-detector';\nimport type { LogAttributes } from '../type';\nimport { CustomExporter } from './exportor';\n\nexport class AppOTelLoggerSDK {\n private sdk: NodeSDK | null = null;\n private logProcessor: BatchLogRecordProcessor | null = null;\n\n start() {\n // 1. 探测并定义资源\n const resource = detectResources({\n detectors: [\n new PlatformDetector()\n ]\n });\n\n // 2. 配置数据出口 Exporter\n const logExporter = new CustomExporter();\n\n // 3. 配置 Processor\n // 手动创建是为了后面能调用它的 forceFlush\n this.logProcessor = new BatchLogRecordProcessor(logExporter, {\n scheduledDelayMillis: 1000,\n maxExportBatchSize: 512\n });\n\n // 4. 启动官方 SDK 底座\n this.sdk = new NodeSDK({\n resource,\n logRecordProcessor: this.logProcessor,\n // Trace 暂不实现\n traceExporter: undefined,\n });\n\n this.sdk.start();\n }\n \n /**\n * 用户使用的日志接口\n */\n public log(level: string, message: string, attributes: LogAttributes = {}) {\n const logger = logs.getLogger('app-logger');\n const severityNumber = this.mapSeverity(level);\n logger.emit({\n body: message,\n severityNumber: severityNumber,\n severityText: level.toUpperCase(),\n attributes: attributes,\n timestamp: new Date(),\n });\n }\n // FaaS 核心功能\n async flush() {\n if (this.logProcessor) {\n await this.logProcessor.forceFlush();\n }\n }\n\n private mapSeverity(level: string): SeverityNumber {\n switch (level.toLowerCase()) {\n case 'trace': return SeverityNumber.TRACE;\n case 'debug': return SeverityNumber.DEBUG;\n case 'info': return SeverityNumber.INFO;\n case 'warn': return SeverityNumber.WARN;\n case 'error': return SeverityNumber.ERROR;\n case 'fatal': return SeverityNumber.FATAL;\n default: return SeverityNumber.INFO;\n }\n }\n}\n\n// 导出单例\nexport const appSdk = new AppOTelLoggerSDK();","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Context, TimeInput } from '@opentelemetry/api';\nimport { AnyValue, AnyValueMap } from './AnyValue';\n\nexport type LogBody = AnyValue;\nexport type LogAttributes = AnyValueMap;\n\nexport enum SeverityNumber {\n UNSPECIFIED = 0,\n TRACE = 1,\n TRACE2 = 2,\n TRACE3 = 3,\n TRACE4 = 4,\n DEBUG = 5,\n DEBUG2 = 6,\n DEBUG3 = 7,\n DEBUG4 = 8,\n INFO = 9,\n INFO2 = 10,\n INFO3 = 11,\n INFO4 = 12,\n WARN = 13,\n WARN2 = 14,\n WARN3 = 15,\n WARN4 = 16,\n ERROR = 17,\n ERROR2 = 18,\n ERROR3 = 19,\n ERROR4 = 20,\n FATAL = 21,\n FATAL2 = 22,\n FATAL3 = 23,\n FATAL4 = 24,\n}\n\nexport interface LogRecord {\n /**\n * The unique identifier for the log record.\n */\n eventName?: string;\n\n /**\n * The time when the log record occurred as UNIX Epoch time in nanoseconds.\n */\n timestamp?: TimeInput;\n\n /**\n * Time when the event was observed by the collection system.\n */\n observedTimestamp?: TimeInput;\n\n /**\n * Numerical value of the severity.\n */\n severityNumber?: SeverityNumber;\n\n /**\n * The severity text.\n */\n severityText?: string;\n\n /**\n * A value containing the body of the log record.\n */\n body?: LogBody;\n\n /**\n * Attributes that define the log record.\n */\n attributes?: LogAttributes;\n\n /**\n * The Context associated with the LogRecord.\n */\n context?: Context;\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Logger } from './types/Logger';\nimport { LogRecord } from './types/LogRecord';\n\nexport class NoopLogger implements Logger {\n emit(_logRecord: LogRecord): void {}\n}\n\nexport const NOOP_LOGGER = new NoopLogger();\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from './types/LoggerProvider';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { NoopLogger } from './NoopLogger';\n\nexport class NoopLoggerProvider implements LoggerProvider {\n getLogger(\n _name: string,\n _version?: string | undefined,\n _options?: LoggerOptions | undefined\n ): Logger {\n return new NoopLogger();\n }\n}\n\nexport const NOOP_LOGGER_PROVIDER = new NoopLoggerProvider();\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { NOOP_LOGGER } from './NoopLogger';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { LogRecord } from './types/LogRecord';\n\nexport class ProxyLogger implements Logger {\n // When a real implementation is provided, this will be it\n private _delegate?: Logger;\n\n constructor(\n private _provider: LoggerDelegator,\n public readonly name: string,\n public readonly version?: string | undefined,\n public readonly options?: LoggerOptions | undefined\n ) {}\n\n /**\n * Emit a log record. This method should only be used by log appenders.\n *\n * @param logRecord\n */\n emit(logRecord: LogRecord): void {\n this._getLogger().emit(logRecord);\n }\n\n /**\n * Try to get a logger from the proxy logger provider.\n * If the proxy logger provider has no delegate, return a noop logger.\n */\n private _getLogger() {\n if (this._delegate) {\n return this._delegate;\n }\n const logger = this._provider._getDelegateLogger(\n this.name,\n this.version,\n this.options\n );\n if (!logger) {\n return NOOP_LOGGER;\n }\n this._delegate = logger;\n return this._delegate;\n }\n}\n\nexport interface LoggerDelegator {\n _getDelegateLogger(\n name: string,\n version?: string,\n options?: LoggerOptions\n ): Logger | undefined;\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from './types/LoggerProvider';\nimport { Logger } from './types/Logger';\nimport { LoggerOptions } from './types/LoggerOptions';\nimport { NOOP_LOGGER_PROVIDER } from './NoopLoggerProvider';\nimport { ProxyLogger } from './ProxyLogger';\n\nexport class ProxyLoggerProvider implements LoggerProvider {\n private _delegate?: LoggerProvider;\n\n getLogger(\n name: string,\n version?: string | undefined,\n options?: LoggerOptions | undefined\n ): Logger {\n return (\n this._getDelegateLogger(name, version, options) ??\n new ProxyLogger(this, name, version, options)\n );\n }\n\n /**\n * Get the delegate logger provider.\n * Used by tests only.\n * @internal\n */\n _getDelegate(): LoggerProvider {\n return this._delegate ?? NOOP_LOGGER_PROVIDER;\n }\n\n /**\n * Set the delegate logger provider\n * @internal\n */\n _setDelegate(delegate: LoggerProvider) {\n this._delegate = delegate;\n }\n\n /**\n * @internal\n */\n _getDelegateLogger(\n name: string,\n version?: string | undefined,\n options?: LoggerOptions | undefined\n ): Logger | undefined {\n return this._delegate?.getLogger(name, version, options);\n }\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** only globals that common to node and browsers are allowed */\n// eslint-disable-next-line n/no-unsupported-features/es-builtins\nexport const _globalThis = typeof globalThis === 'object' ? globalThis : global;\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerProvider } from '../types/LoggerProvider';\nimport { _globalThis } from '../platform';\n\nexport const GLOBAL_LOGS_API_KEY = Symbol.for('io.opentelemetry.js.api.logs');\n\ntype Get<T> = (version: number) => T;\ntype OtelGlobal = Partial<{\n [GLOBAL_LOGS_API_KEY]: Get<LoggerProvider>;\n}>;\n\nexport const _global = _globalThis as OtelGlobal;\n\n/**\n * Make a function which accepts a version integer and returns the instance of an API if the version\n * is compatible, or a fallback version (usually NOOP) if it is not.\n *\n * @param requiredVersion Backwards compatibility version which is required to return the instance\n * @param instance Instance which should be returned if the required version is compatible\n * @param fallback Fallback instance, usually NOOP, which will be returned if the required version is not compatible\n */\nexport function makeGetter<T>(\n requiredVersion: number,\n instance: T,\n fallback: T\n): Get<T> {\n return (version: number): T =>\n version === requiredVersion ? instance : fallback;\n}\n\n/**\n * A number which should be incremented each time a backwards incompatible\n * change is made to the API. This number is used when an API package\n * attempts to access the global API to ensure it is getting a compatible\n * version. If the global API is not compatible with the API package\n * attempting to get it, a NOOP API implementation will be returned.\n */\nexport const API_BACKWARDS_COMPATIBILITY_VERSION = 1;\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n API_BACKWARDS_COMPATIBILITY_VERSION,\n GLOBAL_LOGS_API_KEY,\n _global,\n makeGetter,\n} from '../internal/global-utils';\nimport { LoggerProvider } from '../types/LoggerProvider';\nimport { NOOP_LOGGER_PROVIDER } from '../NoopLoggerProvider';\nimport { Logger } from '../types/Logger';\nimport { LoggerOptions } from '../types/LoggerOptions';\nimport { ProxyLoggerProvider } from '../ProxyLoggerProvider';\n\nexport class LogsAPI {\n private static _instance?: LogsAPI;\n\n private _proxyLoggerProvider = new ProxyLoggerProvider();\n\n private constructor() {}\n\n public static getInstance(): LogsAPI {\n if (!this._instance) {\n this._instance = new LogsAPI();\n }\n\n return this._instance;\n }\n\n public setGlobalLoggerProvider(provider: LoggerProvider): LoggerProvider {\n if (_global[GLOBAL_LOGS_API_KEY]) {\n return this.getLoggerProvider();\n }\n\n _global[GLOBAL_LOGS_API_KEY] = makeGetter<LoggerProvider>(\n API_BACKWARDS_COMPATIBILITY_VERSION,\n provider,\n NOOP_LOGGER_PROVIDER\n );\n this._proxyLoggerProvider._setDelegate(provider);\n\n return provider;\n }\n\n /**\n * Returns the global logger provider.\n *\n * @returns LoggerProvider\n */\n public getLoggerProvider(): LoggerProvider {\n return (\n _global[GLOBAL_LOGS_API_KEY]?.(API_BACKWARDS_COMPATIBILITY_VERSION) ??\n this._proxyLoggerProvider\n );\n }\n\n /**\n * Returns a logger from the global logger provider.\n *\n * @returns Logger\n */\n public getLogger(\n name: string,\n version?: string,\n options?: LoggerOptions\n ): Logger {\n return this.getLoggerProvider().getLogger(name, version, options);\n }\n\n /** Remove the global logger provider */\n public disable(): void {\n delete _global[GLOBAL_LOGS_API_KEY];\n this._proxyLoggerProvider = new ProxyLoggerProvider();\n }\n}\n","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type { Logger } from './types/Logger';\nexport type { LoggerProvider } from './types/LoggerProvider';\nexport { SeverityNumber } from './types/LogRecord';\nexport type { LogAttributes, LogBody, LogRecord } from './types/LogRecord';\nexport type { LoggerOptions } from './types/LoggerOptions';\nexport type { AnyValue, AnyValueMap } from './types/AnyValue';\nexport { NOOP_LOGGER, NoopLogger } from './NoopLogger';\nexport { ProxyLoggerProvider } from './ProxyLoggerProvider';\n\nimport { LogsAPI } from './api/logs';\nexport const logs = LogsAPI.getInstance();\n","import { ResourceDetector, ResourceDetectionConfig, DetectedResource } from '@opentelemetry/resources';\n\n/**\n * 业务专属资源探测器\n * 负责从环境变量中提取低代码平台特有的元数据 (Tenant, App, Env)\n */\nexport class PlatformDetector implements ResourceDetector {\n \n /**\n * 实现 detect 接口\n * @param config 探测配置 (可选)\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ndetect(config?: ResourceDetectionConfig): DetectedResource {\n // 1. 定义我们要提取的业务属性\n const attributes: Record<string, string | number | boolean> = {};\n\n // 2. 清洗数据:移除 undefined/null 的值,防止 OTel 报错\n const cleanAttributes = Object.entries(attributes).reduce((acc, [key, value]) => {\n if (value !== undefined && value !== null && value !== '') {\n acc[key] = value;\n }\n return acc;\n }, {} as Record<string, string | number | boolean>);\n\n // 3. 返回 Resource 对象\n // 注意:detect 方法必须返回一个 Promise\n return {\n attributes: cleanAttributes,\n }\n }\n}\n\nexport const lowCodeDetector = new PlatformDetector();","/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface ExportResult {\n code: ExportResultCode;\n error?: Error;\n}\n\nexport enum ExportResultCode {\n SUCCESS,\n FAILED,\n}\n","import { randomBytes } from 'crypto';\n\nexport const idGenerator = {\n /**\n * 生成 TraceId (128-bit / 32-char hex)\n * 符合 W3C Trace Context 标准\n * 示例: \"5b8efff798038103d269b633813fc60c\"\n */\n generateTraceId(): string {\n // 16 字节 = 128 位,转为 hex 就是 32 个字符\n return randomBytes(16).toString('hex');\n },\n\n /**\n * 生成 SpanId (64-bit / 16-char hex)\n * 示例: \"eee19b7ec3c1b174\"\n */\n generateSpanId(): string {\n // 8 字节 = 64 位,转为 hex 就是 16 个字符\n return randomBytes(8).toString('hex');\n }\n};","import type { HrTime } from '@opentelemetry/api';\n/**\n * 将 HrTime 转换为纳秒字符串\n * 使用 BigInt 防止精度丢失\n*/\nexport function hrTimeToNanosString(hrTime: HrTime): string {\n // 将秒转换为 BigInt\n const seconds = BigInt(hrTime[0]);\n // 将纳秒转换为 BigInt\n const nanos = BigInt(hrTime[1]);\n \n // 计算总纳秒数: seconds * 10^9 + nanos\n // 注意:数字后面加 'n' 表示 BigInt 字面量,或者使用 BigInt() 构造函数\n const totalNanos = (seconds * 1_000_000_000n) + nanos;\n \n return totalNanos.toString();\n}","import { LogRecordExporter, ReadableLogRecord,} from '@opentelemetry/sdk-logs';\nimport { ExportResult, ExportResultCode } from '@opentelemetry/core';\nimport { Attributes } from '@opentelemetry/api';\nimport { idGenerator } from '../utils/generateUUID';\nimport { hrTimeToNanosString } from '../utils/hrTimeToNanoString';\n\nexport class CustomExporter implements LogRecordExporter {\n private logPrefix: string = \"force-log-prefix\"\n private logSuffix: string = \"force-log-suffix\"\n\n\n\n export(logs: ReadableLogRecord[], resultCallback: (result: ExportResult) => void) {\n // 初始化默认 log 内 attributes\n const defaultAttributes: Attributes = {\n tenant_id: 'default-tenant',\n user_id: 'default-user',\n app_id: 'default-app',\n uuid: idGenerator.generateTraceId(),\n };\n\n // 模拟 OTLP 的结构化过程\n const otlpLikeStructure = {\n resourceLogs: logs.map(log => ({\n resource: {\n // resource.attributes 暂时置空\n // attributes: log.resource.attributes,\n attributes: {}\n },\n logRecords: [{\n timeUnixNano: hrTimeToNanosString(log.hrTime),\n observedTimeUnixNano: hrTimeToNanosString(log.hrTimeObserved),\n severityNumber: log.severityNumber,\n severityText: log.severityText,\n body: { stringValue: log.body }, \n attributes:{\n ...defaultAttributes\n },\n traceId: log.spanContext?.traceId,\n spanId: log.spanContext?.spanId\n }]\n }))\n };\n\n console.log(this.logPrefix + JSON.stringify(otlpLikeStructure, null, 2) + this.logSuffix);\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n async shutdown() {}\n}"],"mappings":";;;;AACA,SAASA,eAAe;AACxB,SAASC,+BAA+B;AACxC,SAASC,uBAAuB;;;ACmBhC,IAAY;CAAZ,SAAYC,iBAAc;AACxB,EAAAA,gBAAAA,gBAAA,aAAA,IAAA,CAAA,IAAA;AACA,EAAAA,gBAAAA,gBAAA,OAAA,IAAA,CAAA,IAAA;AACA,EAAAA,gBAAAA,gBAAA,QAAA,IAAA,CAAA,IAAA;AACA,EAAAA,gBAAAA,gBAAA,QAAA,IAAA,CAAA,IAAA;AACA,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ources","SeverityNumber","PlatformDetector","detect","config","attributes","cleanAttributes","Object","entries","reduce","acc","key","value","undefined","lowCodeDetector","ExportResultCode","randomBytes","idGenerator","generateTraceId","toString","generateSpanId","hrTimeToNanosString","hrTime","seconds","BigInt","nanos","totalNanos","toString","CustomExporter","logPrefix","logSuffix","export","logs","resultCallback","defaultAttributes","tenant_id","user_id","app_id","uuid","idGenerator","generateTraceId","otlpLikeStructure","resourceLogs","map","log","resource","attributes","logRecords","timeUnixNano","hrTimeToNanosString","hrTime","observedTimeUnixNano","hrTimeObserved","severityNumber","severityText","body","stringValue","traceId","spanContext","spanId","console","JSON","stringify","code","ExportResultCode","SUCCESS","shutdown","AppOTelLoggerSDK","sdk","logProcessor","start","resource","detectResources","detectors","PlatformDetector","logExporter","CustomExporter","BatchLogRecordProcessor","scheduledDelayMillis","maxExportBatchSize","NodeSDK","logRecordProcessor","traceExporter","undefined","log","level","message","attributes","logger","logs","getLogger","severityNumber","mapSeverity","emit","body","severityText","toUpperCase","timestamp","Date","flush","forceFlush","toLowerCase","SeverityNumber","TRACE","DEBUG","INFO","WARN","ERROR","FATAL","appSdk"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/observable",
3
- "version": "1.0.1-alpha.2",
3
+ "version": "1.0.1-alpha.4",
4
4
  "description": "Observable SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",