"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.tracerTag = exports.nativeTracer = exports.make = exports.TracerTypeId = exports.NativeSpan = void 0;
var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Context"));
var _Global = /*#__PURE__*/require("@effect/data/Global");
var MutableRef = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/MutableRef"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
 * @since 1.0.0
 */

/** @internal */
const TracerTypeId = /*#__PURE__*/Symbol.for("@effect/io/Tracer");
/** @internal */
exports.TracerTypeId = TracerTypeId;
const make = options => ({
  [TracerTypeId]: TracerTypeId,
  ...options
});
/** @internal */
exports.make = make;
const tracerTag = /*#__PURE__*/Context.Tag( /*#__PURE__*/Symbol.for("@effect/io/Tracer"));
exports.tracerTag = tracerTag;
const ids = /*#__PURE__*/(0, _Global.globalValue)("@effect/io/Tracer/SpanId.ids", () => MutableRef.make(0));
/** @internal */
class NativeSpan {
  constructor(name, parent, context, startTime) {
    this.name = name;
    this.parent = parent;
    this.context = context;
    this.startTime = startTime;
    this._tag = "Span";
    this.traceId = "native";
    this.events = [];
    this.end = (endTime, exit) => {
      this.status = {
        _tag: "Ended",
        endTime,
        exit,
        startTime: this.status.startTime
      };
    };
    this.attribute = (key, value) => {
      this.attributes.set(key, value);
    };
    this.event = (name, startTime, attributes) => {
      this.events.push([name, startTime, attributes ?? {}]);
    };
    this.status = {
      _tag: "Started",
      startTime
    };
    this.attributes = new Map();
    this.spanId = `span${MutableRef.incrementAndGet(ids)}`;
  }
}
/** @internal */
exports.NativeSpan = NativeSpan;
const nativeTracer = /*#__PURE__*/make({
  span: (name, parent, traceFlags, startTime) => new NativeSpan(name, parent, traceFlags, startTime)
});
exports.nativeTracer = nativeTracer;
//# sourceMappingURL=tracer.js.map