var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var spanWrapper_exports = {};
__export(spanWrapper_exports, {
  OpenTelemetrySpanWrapper: () => OpenTelemetrySpanWrapper
});
module.exports = __toCommonJS(spanWrapper_exports);
var import_api = require("@opentelemetry/api");
var import_core = require("@opentelemetry/core");
var import_logger = require("./logger.js");
class OpenTelemetrySpanWrapper {
  _span;
  constructor(span) {
    this._span = span;
  }
  setStatus(status) {
    if (status.status === "error" && isRecordableError(status.error)) {
      if (status.error) {
        this._span.setStatus({ code: import_api.SpanStatusCode.ERROR, message: status.error.toString() });
        this.recordException(status.error);
      } else {
        this._span.setStatus({ code: import_api.SpanStatusCode.ERROR });
      }
    } else if (status.status === "success") {
      import_logger.logger.verbose("Leaving span with status UNSET per OpenTelemetry spec.");
    }
  }
  setAttribute(name, value) {
    if (value !== null && value !== void 0 && (0, import_core.isAttributeValue)(value)) {
      this._span.setAttribute(name, value);
    }
  }
  end() {
    this._span.end();
  }
  recordException(exception) {
    this._span.recordException(exception);
  }
  isRecording() {
    return this._span.isRecording();
  }
  addEvent(name, options = {}) {
    this._span.addEvent(name, (0, import_core.sanitizeAttributes)(options.attributes), options.startTime);
  }
  /**
   * Allows getting the wrapped span as needed.
   * @internal
   *
   * @returns The underlying span
   */
  unwrap() {
    return this._span;
  }
}
function isRecordableError(error) {
  if (error !== null && typeof error === "object" && "statusCode" in error) {
    return error.statusCode !== 304;
  }
  return true;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  OpenTelemetrySpanWrapper
});
//# sourceMappingURL=spanWrapper.js.map
