{"version":3,"file":"LogRecordProcessorMetrics.mjs","names":[],"sources":["../../src/export/LogRecordProcessorMetrics.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n  Attributes,\n  Counter,\n  Meter,\n  ObservableCallback,\n  ObservableUpDownCounter,\n} from '@opentelemetry/api';\nimport {\n  ATTR_ERROR_TYPE,\n  ATTR_OTEL_COMPONENT_NAME,\n  ATTR_OTEL_COMPONENT_TYPE,\n  METRIC_OTEL_SDK_PROCESSOR_LOG_PROCESSED,\n  METRIC_OTEL_SDK_PROCESSOR_LOG_QUEUE_CAPACITY,\n  METRIC_OTEL_SDK_PROCESSOR_LOG_QUEUE_SIZE,\n} from '../semconv';\n\nconst componentCounter = new Map<string, number>();\n\ninterface QueueConfig {\n  capacity: number;\n  getQueueSize: () => number;\n}\n\nexport class LogRecordProcessorMetrics {\n  private readonly processedLogs: Counter;\n  private readonly queueSize: ObservableUpDownCounter | undefined;\n  private readonly queueSizeCallback: ObservableCallback | undefined;\n\n  private readonly standardAttrs: Attributes;\n  private readonly droppedAttrs: Attributes;\n\n  constructor(componentType: string, meter: Meter, queueConfig?: QueueConfig) {\n    const counter = componentCounter.get(componentType) ?? 0;\n    componentCounter.set(componentType, counter + 1);\n\n    this.standardAttrs = {\n      [ATTR_OTEL_COMPONENT_TYPE]: componentType,\n      [ATTR_OTEL_COMPONENT_NAME]: `${componentType}/${counter}`,\n    };\n\n    this.droppedAttrs = {\n      ...this.standardAttrs,\n      [ATTR_ERROR_TYPE]: 'queue_full',\n    };\n\n    this.processedLogs = meter.createCounter(\n      METRIC_OTEL_SDK_PROCESSOR_LOG_PROCESSED,\n      {\n        unit: '{log_record}',\n        description:\n          'The number of log records for which the processing has finished, either successful or failed.',\n      }\n    );\n\n    if (queueConfig) {\n      const { capacity, getQueueSize } = queueConfig;\n      const queueCapacity = meter.createUpDownCounter(\n        METRIC_OTEL_SDK_PROCESSOR_LOG_QUEUE_CAPACITY,\n        {\n          unit: '{log_record}',\n          description:\n            'The maximum number of log records the queue of a given instance of an SDK log processor can hold.',\n        }\n      );\n      queueCapacity.add(capacity, this.standardAttrs);\n\n      this.queueSize = meter.createObservableUpDownCounter(\n        METRIC_OTEL_SDK_PROCESSOR_LOG_QUEUE_SIZE,\n        {\n          unit: '{log_record}',\n          description:\n            'The number of log records in the queue of a given instance of an SDK log processor.',\n        }\n      );\n      this.queueSizeCallback = result =>\n        result.observe(getQueueSize(), this.standardAttrs);\n      this.queueSize.addCallback(this.queueSizeCallback);\n    }\n  }\n\n  dropLogs(count: number) {\n    this.processedLogs.add(count, this.droppedAttrs);\n  }\n\n  finishLogs(count: number, error: Error | undefined) {\n    if (!error) {\n      this.processedLogs.add(count, this.standardAttrs);\n      return;\n    }\n\n    const attrs = {\n      ...this.standardAttrs,\n      [ATTR_ERROR_TYPE]: error.name,\n    };\n    this.processedLogs.add(count, attrs);\n  }\n\n  shutdown() {\n    if (this.queueSize && this.queueSizeCallback) {\n      this.queueSize.removeCallback(this.queueSizeCallback);\n    }\n  }\n}\n"],"mappings":";;AAqBA,MAAM,mCAAmB,IAAI,IAAoB;AAOjD,IAAa,4BAAb,MAAuC;CACrC;CACA;CACA;CAEA;CACA;CAEA,YAAY,eAAuB,OAAc,aAA2B;EAC1E,MAAM,UAAU,iBAAiB,IAAI,aAAa,KAAK;EACvD,iBAAiB,IAAI,eAAe,UAAU,CAAC;EAE/C,KAAK,gBAAgB;IAClB,2BAA2B;IAC3B,2BAA2B,GAAG,cAAc,GAAG;EAClD;EAEA,KAAK,eAAe;GAClB,GAAG,KAAK;IACP,kBAAkB;EACrB;EAEA,KAAK,gBAAgB,MAAM,cACzB,yCACA;GACE,MAAM;GACN,aACE;EACJ,CACF;EAEA,IAAI,aAAa;GACf,MAAM,EAAE,UAAU,iBAAiB;GASnC,MAR4B,oBAC1B,8CACA;IACE,MAAM;IACN,aACE;GACJ,CAEU,CAAC,CAAC,IAAI,UAAU,KAAK,aAAa;GAE9C,KAAK,YAAY,MAAM,8BACrB,0CACA;IACE,MAAM;IACN,aACE;GACJ,CACF;GACA,KAAK,qBAAoB,WACvB,OAAO,QAAQ,aAAa,GAAG,KAAK,aAAa;GACnD,KAAK,UAAU,YAAY,KAAK,iBAAiB;EACnD;CACF;CAEA,SAAS,OAAe;EACtB,KAAK,cAAc,IAAI,OAAO,KAAK,YAAY;CACjD;CAEA,WAAW,OAAe,OAA0B;EAClD,IAAI,CAAC,OAAO;GACV,KAAK,cAAc,IAAI,OAAO,KAAK,aAAa;GAChD;EACF;EAEA,MAAM,QAAQ;GACZ,GAAG,KAAK;IACP,kBAAkB,MAAM;EAC3B;EACA,KAAK,cAAc,IAAI,OAAO,KAAK;CACrC;CAEA,WAAW;EACT,IAAI,KAAK,aAAa,KAAK,mBACzB,KAAK,UAAU,eAAe,KAAK,iBAAiB;CAExD;AACF"}