/**
 * @since 1.0.0
 */
import * as Context from "@effect/data/Context";
import { globalValue } from "@effect/data/Global";
import * as MutableRef from "@effect/data/MutableRef";
/** @internal */
export const TracerTypeId = /*#__PURE__*/Symbol.for("@effect/io/Tracer");
/** @internal */
export const make = options => ({
  [TracerTypeId]: TracerTypeId,
  ...options
});
/** @internal */
export const tracerTag = /*#__PURE__*/Context.Tag( /*#__PURE__*/Symbol.for("@effect/io/Tracer"));
const ids = /*#__PURE__*/globalValue("@effect/io/Tracer/SpanId.ids", () => MutableRef.make(0));
/** @internal */
export 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 */
export const nativeTracer = /*#__PURE__*/make({
  span: (name, parent, traceFlags, startTime) => new NativeSpan(name, parent, traceFlags, startTime)
});
//# sourceMappingURL=tracer.mjs.map