var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var trace_exports = {};
__export(trace_exports, {
  ResourceSpans: () => ResourceSpans,
  ScopeSpans: () => ScopeSpans,
  Span: () => Span,
  SpanFlags: () => SpanFlags,
  Span_Event: () => Span_Event,
  Span_Link: () => Span_Link,
  Span_SpanKind: () => Span_SpanKind,
  Status: () => Status,
  Status_StatusCode: () => Status_StatusCode,
  TracesData: () => TracesData,
  protobufPackage: () => protobufPackage,
  spanFlagsFromJSON: () => spanFlagsFromJSON,
  spanFlagsToJSON: () => spanFlagsToJSON,
  span_SpanKindFromJSON: () => span_SpanKindFromJSON,
  span_SpanKindToJSON: () => span_SpanKindToJSON,
  status_StatusCodeFromJSON: () => status_StatusCodeFromJSON,
  status_StatusCodeToJSON: () => status_StatusCodeToJSON
});
module.exports = __toCommonJS(trace_exports);
var import_global_this = __toESM(require("@babel/runtime-corejs3/core-js/global-this"));
var import_map = __toESM(require("@babel/runtime-corejs3/core-js/instance/map"));
var import_bind = __toESM(require("@babel/runtime-corejs3/core-js/instance/bind"));
var import_flags = __toESM(require("@babel/runtime-corejs3/core-js/instance/flags"));
var import_for_each = __toESM(require("@babel/runtime-corejs3/core-js/instance/for-each"));
var import_long = __toESM(require("long"));
var import_minimal = __toESM(require("protobufjs/minimal.js"));
var import_common = require("../../common/v1/common.js");
var import_resource = require("../../resource/v1/resource.js");
const protobufPackage = "opentelemetry.proto.trace.v1";
let SpanFlags = /* @__PURE__ */ function(SpanFlags2) {
  SpanFlags2[SpanFlags2["SPAN_FLAGS_DO_NOT_USE"] = 0] = "SPAN_FLAGS_DO_NOT_USE";
  SpanFlags2[SpanFlags2["SPAN_FLAGS_TRACE_FLAGS_MASK"] = 255] = "SPAN_FLAGS_TRACE_FLAGS_MASK";
  SpanFlags2[SpanFlags2["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
  return SpanFlags2;
}({});
function spanFlagsFromJSON(object) {
  switch (object) {
    case 0:
    case "SPAN_FLAGS_DO_NOT_USE":
      return SpanFlags.SPAN_FLAGS_DO_NOT_USE;
    case 255:
    case "SPAN_FLAGS_TRACE_FLAGS_MASK":
      return SpanFlags.SPAN_FLAGS_TRACE_FLAGS_MASK;
    case -1:
    case "UNRECOGNIZED":
    default:
      return SpanFlags.UNRECOGNIZED;
  }
}
function spanFlagsToJSON(object) {
  switch (object) {
    case SpanFlags.SPAN_FLAGS_DO_NOT_USE:
      return "SPAN_FLAGS_DO_NOT_USE";
    case SpanFlags.SPAN_FLAGS_TRACE_FLAGS_MASK:
      return "SPAN_FLAGS_TRACE_FLAGS_MASK";
    case SpanFlags.UNRECOGNIZED:
    default:
      return "UNRECOGNIZED";
  }
}
let Span_SpanKind = /* @__PURE__ */ function(Span_SpanKind2) {
  Span_SpanKind2[Span_SpanKind2["SPAN_KIND_UNSPECIFIED"] = 0] = "SPAN_KIND_UNSPECIFIED";
  Span_SpanKind2[Span_SpanKind2["SPAN_KIND_INTERNAL"] = 1] = "SPAN_KIND_INTERNAL";
  Span_SpanKind2[Span_SpanKind2["SPAN_KIND_SERVER"] = 2] = "SPAN_KIND_SERVER";
  Span_SpanKind2[Span_SpanKind2["SPAN_KIND_CLIENT"] = 3] = "SPAN_KIND_CLIENT";
  Span_SpanKind2[Span_SpanKind2["SPAN_KIND_PRODUCER"] = 4] = "SPAN_KIND_PRODUCER";
  Span_SpanKind2[Span_SpanKind2["SPAN_KIND_CONSUMER"] = 5] = "SPAN_KIND_CONSUMER";
  Span_SpanKind2[Span_SpanKind2["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
  return Span_SpanKind2;
}({});
function span_SpanKindFromJSON(object) {
  switch (object) {
    case 0:
    case "SPAN_KIND_UNSPECIFIED":
      return Span_SpanKind.SPAN_KIND_UNSPECIFIED;
    case 1:
    case "SPAN_KIND_INTERNAL":
      return Span_SpanKind.SPAN_KIND_INTERNAL;
    case 2:
    case "SPAN_KIND_SERVER":
      return Span_SpanKind.SPAN_KIND_SERVER;
    case 3:
    case "SPAN_KIND_CLIENT":
      return Span_SpanKind.SPAN_KIND_CLIENT;
    case 4:
    case "SPAN_KIND_PRODUCER":
      return Span_SpanKind.SPAN_KIND_PRODUCER;
    case 5:
    case "SPAN_KIND_CONSUMER":
      return Span_SpanKind.SPAN_KIND_CONSUMER;
    case -1:
    case "UNRECOGNIZED":
    default:
      return Span_SpanKind.UNRECOGNIZED;
  }
}
function span_SpanKindToJSON(object) {
  switch (object) {
    case Span_SpanKind.SPAN_KIND_UNSPECIFIED:
      return "SPAN_KIND_UNSPECIFIED";
    case Span_SpanKind.SPAN_KIND_INTERNAL:
      return "SPAN_KIND_INTERNAL";
    case Span_SpanKind.SPAN_KIND_SERVER:
      return "SPAN_KIND_SERVER";
    case Span_SpanKind.SPAN_KIND_CLIENT:
      return "SPAN_KIND_CLIENT";
    case Span_SpanKind.SPAN_KIND_PRODUCER:
      return "SPAN_KIND_PRODUCER";
    case Span_SpanKind.SPAN_KIND_CONSUMER:
      return "SPAN_KIND_CONSUMER";
    case Span_SpanKind.UNRECOGNIZED:
    default:
      return "UNRECOGNIZED";
  }
}
let Status_StatusCode = /* @__PURE__ */ function(Status_StatusCode2) {
  Status_StatusCode2[Status_StatusCode2["STATUS_CODE_UNSET"] = 0] = "STATUS_CODE_UNSET";
  Status_StatusCode2[Status_StatusCode2["STATUS_CODE_OK"] = 1] = "STATUS_CODE_OK";
  Status_StatusCode2[Status_StatusCode2["STATUS_CODE_ERROR"] = 2] = "STATUS_CODE_ERROR";
  Status_StatusCode2[Status_StatusCode2["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
  return Status_StatusCode2;
}({});
function status_StatusCodeFromJSON(object) {
  switch (object) {
    case 0:
    case "STATUS_CODE_UNSET":
      return Status_StatusCode.STATUS_CODE_UNSET;
    case 1:
    case "STATUS_CODE_OK":
      return Status_StatusCode.STATUS_CODE_OK;
    case 2:
    case "STATUS_CODE_ERROR":
      return Status_StatusCode.STATUS_CODE_ERROR;
    case -1:
    case "UNRECOGNIZED":
    default:
      return Status_StatusCode.UNRECOGNIZED;
  }
}
function status_StatusCodeToJSON(object) {
  switch (object) {
    case Status_StatusCode.STATUS_CODE_UNSET:
      return "STATUS_CODE_UNSET";
    case Status_StatusCode.STATUS_CODE_OK:
      return "STATUS_CODE_OK";
    case Status_StatusCode.STATUS_CODE_ERROR:
      return "STATUS_CODE_ERROR";
    case Status_StatusCode.UNRECOGNIZED:
    default:
      return "UNRECOGNIZED";
  }
}
function createBaseTracesData() {
  return {
    resourceSpans: []
  };
}
const TracesData = {
  encode(message, writer = import_minimal.default.Writer.create()) {
    for (const v of message.resourceSpans) {
      ResourceSpans.encode(v, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof import_minimal.default.Reader ? input : import_minimal.default.Reader.create(input);
    let end = length === void 0 ? reader.len : reader.pos + length;
    const message = createBaseTracesData();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }
          message.resourceSpans.push(ResourceSpans.decode(reader, reader.uint32()));
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },
  fromJSON(object) {
    var _context;
    return {
      resourceSpans: import_global_this.default.Array.isArray(object?.resourceSpans) ? (0, import_map.default)(_context = object.resourceSpans).call(_context, (e) => ResourceSpans.fromJSON(e)) : []
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.resourceSpans?.length) {
      var _context2;
      obj.resourceSpans = (0, import_map.default)(_context2 = message.resourceSpans).call(_context2, (e) => ResourceSpans.toJSON(e));
    }
    return obj;
  },
  create(base) {
    return TracesData.fromPartial(base ?? {});
  },
  fromPartial(object) {
    var _context3, _context4;
    const message = createBaseTracesData();
    message.resourceSpans = ((_context3 = object.resourceSpans) == null ? void 0 : (0, import_bind.default)(_context4 = Function.call).call(_context4, (0, import_map.default)(_context3), _context3))?.((e) => ResourceSpans.fromPartial(e)) || [];
    return message;
  }
};
function createBaseResourceSpans() {
  return {
    resource: void 0,
    scopeSpans: [],
    schemaUrl: ""
  };
}
const ResourceSpans = {
  encode(message, writer = import_minimal.default.Writer.create()) {
    if (message.resource !== void 0) {
      import_resource.Resource.encode(message.resource, writer.uint32(10).fork()).ldelim();
    }
    for (const v of message.scopeSpans) {
      ScopeSpans.encode(v, writer.uint32(18).fork()).ldelim();
    }
    if (message.schemaUrl !== "") {
      writer.uint32(26).string(message.schemaUrl);
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof import_minimal.default.Reader ? input : import_minimal.default.Reader.create(input);
    let end = length === void 0 ? reader.len : reader.pos + length;
    const message = createBaseResourceSpans();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }
          message.resource = import_resource.Resource.decode(reader, reader.uint32());
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }
          message.scopeSpans.push(ScopeSpans.decode(reader, reader.uint32()));
          continue;
        case 3:
          if (tag !== 26) {
            break;
          }
          message.schemaUrl = reader.string();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },
  fromJSON(object) {
    var _context5;
    return {
      resource: isSet(object.resource) ? import_resource.Resource.fromJSON(object.resource) : void 0,
      scopeSpans: import_global_this.default.Array.isArray(object?.scopeSpans) ? (0, import_map.default)(_context5 = object.scopeSpans).call(_context5, (e) => ScopeSpans.fromJSON(e)) : [],
      schemaUrl: isSet(object.schemaUrl) ? import_global_this.default.String(object.schemaUrl) : ""
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.resource !== void 0) {
      obj.resource = import_resource.Resource.toJSON(message.resource);
    }
    if (message.scopeSpans?.length) {
      var _context6;
      obj.scopeSpans = (0, import_map.default)(_context6 = message.scopeSpans).call(_context6, (e) => ScopeSpans.toJSON(e));
    }
    if (message.schemaUrl !== "") {
      obj.schemaUrl = message.schemaUrl;
    }
    return obj;
  },
  create(base) {
    return ResourceSpans.fromPartial(base ?? {});
  },
  fromPartial(object) {
    var _context7, _context8;
    const message = createBaseResourceSpans();
    message.resource = object.resource !== void 0 && object.resource !== null ? import_resource.Resource.fromPartial(object.resource) : void 0;
    message.scopeSpans = ((_context7 = object.scopeSpans) == null ? void 0 : (0, import_bind.default)(_context8 = Function.call).call(_context8, (0, import_map.default)(_context7), _context7))?.((e) => ScopeSpans.fromPartial(e)) || [];
    message.schemaUrl = object.schemaUrl ?? "";
    return message;
  }
};
function createBaseScopeSpans() {
  return {
    scope: void 0,
    spans: [],
    schemaUrl: ""
  };
}
const ScopeSpans = {
  encode(message, writer = import_minimal.default.Writer.create()) {
    if (message.scope !== void 0) {
      import_common.InstrumentationScope.encode(message.scope, writer.uint32(10).fork()).ldelim();
    }
    for (const v of message.spans) {
      Span.encode(v, writer.uint32(18).fork()).ldelim();
    }
    if (message.schemaUrl !== "") {
      writer.uint32(26).string(message.schemaUrl);
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof import_minimal.default.Reader ? input : import_minimal.default.Reader.create(input);
    let end = length === void 0 ? reader.len : reader.pos + length;
    const message = createBaseScopeSpans();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }
          message.scope = import_common.InstrumentationScope.decode(reader, reader.uint32());
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }
          message.spans.push(Span.decode(reader, reader.uint32()));
          continue;
        case 3:
          if (tag !== 26) {
            break;
          }
          message.schemaUrl = reader.string();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },
  fromJSON(object) {
    var _context9;
    return {
      scope: isSet(object.scope) ? import_common.InstrumentationScope.fromJSON(object.scope) : void 0,
      spans: import_global_this.default.Array.isArray(object?.spans) ? (0, import_map.default)(_context9 = object.spans).call(_context9, (e) => Span.fromJSON(e)) : [],
      schemaUrl: isSet(object.schemaUrl) ? import_global_this.default.String(object.schemaUrl) : ""
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.scope !== void 0) {
      obj.scope = import_common.InstrumentationScope.toJSON(message.scope);
    }
    if (message.spans?.length) {
      var _context0;
      obj.spans = (0, import_map.default)(_context0 = message.spans).call(_context0, (e) => Span.toJSON(e));
    }
    if (message.schemaUrl !== "") {
      obj.schemaUrl = message.schemaUrl;
    }
    return obj;
  },
  create(base) {
    return ScopeSpans.fromPartial(base ?? {});
  },
  fromPartial(object) {
    var _context1, _context10;
    const message = createBaseScopeSpans();
    message.scope = object.scope !== void 0 && object.scope !== null ? import_common.InstrumentationScope.fromPartial(object.scope) : void 0;
    message.spans = ((_context1 = object.spans) == null ? void 0 : (0, import_bind.default)(_context10 = Function.call).call(_context10, (0, import_map.default)(_context1), _context1))?.((e) => Span.fromPartial(e)) || [];
    message.schemaUrl = object.schemaUrl ?? "";
    return message;
  }
};
function createBaseSpan() {
  return {
    traceId: new Uint8Array(0),
    spanId: new Uint8Array(0),
    traceState: "",
    parentSpanId: new Uint8Array(0),
    flags: 0,
    name: "",
    kind: 0,
    startTimeUnixNano: 0,
    endTimeUnixNano: 0,
    attributes: [],
    droppedAttributesCount: 0,
    events: [],
    droppedEventsCount: 0,
    links: [],
    droppedLinksCount: 0,
    status: void 0
  };
}
const Span = {
  encode(message, writer = import_minimal.default.Writer.create()) {
    if (message.traceId.length !== 0) {
      writer.uint32(10).bytes(message.traceId);
    }
    if (message.spanId.length !== 0) {
      writer.uint32(18).bytes(message.spanId);
    }
    if (message.traceState !== "") {
      writer.uint32(26).string(message.traceState);
    }
    if (message.parentSpanId.length !== 0) {
      writer.uint32(34).bytes(message.parentSpanId);
    }
    if ((0, import_flags.default)(message) !== 0) {
      writer.uint32(133).fixed32((0, import_flags.default)(message));
    }
    if (message.name !== "") {
      writer.uint32(42).string(message.name);
    }
    if (message.kind !== 0) {
      writer.uint32(48).int32(message.kind);
    }
    if (message.startTimeUnixNano !== 0) {
      writer.uint32(57).fixed64(message.startTimeUnixNano);
    }
    if (message.endTimeUnixNano !== 0) {
      writer.uint32(65).fixed64(message.endTimeUnixNano);
    }
    for (const v of message.attributes) {
      import_common.KeyValue.encode(v, writer.uint32(74).fork()).ldelim();
    }
    if (message.droppedAttributesCount !== 0) {
      writer.uint32(80).uint32(message.droppedAttributesCount);
    }
    for (const v of message.events) {
      Span_Event.encode(v, writer.uint32(90).fork()).ldelim();
    }
    if (message.droppedEventsCount !== 0) {
      writer.uint32(96).uint32(message.droppedEventsCount);
    }
    for (const v of message.links) {
      Span_Link.encode(v, writer.uint32(106).fork()).ldelim();
    }
    if (message.droppedLinksCount !== 0) {
      writer.uint32(112).uint32(message.droppedLinksCount);
    }
    if (message.status !== void 0) {
      Status.encode(message.status, writer.uint32(122).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof import_minimal.default.Reader ? input : import_minimal.default.Reader.create(input);
    let end = length === void 0 ? reader.len : reader.pos + length;
    const message = createBaseSpan();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }
          message.traceId = reader.bytes();
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }
          message.spanId = reader.bytes();
          continue;
        case 3:
          if (tag !== 26) {
            break;
          }
          message.traceState = reader.string();
          continue;
        case 4:
          if (tag !== 34) {
            break;
          }
          message.parentSpanId = reader.bytes();
          continue;
        case 16:
          if (tag !== 133) {
            break;
          }
          message.flags = reader.fixed32();
          continue;
        case 5:
          if (tag !== 42) {
            break;
          }
          message.name = reader.string();
          continue;
        case 6:
          if (tag !== 48) {
            break;
          }
          message.kind = reader.int32();
          continue;
        case 7:
          if (tag !== 57) {
            break;
          }
          message.startTimeUnixNano = longToNumber(reader.fixed64());
          continue;
        case 8:
          if (tag !== 65) {
            break;
          }
          message.endTimeUnixNano = longToNumber(reader.fixed64());
          continue;
        case 9:
          if (tag !== 74) {
            break;
          }
          message.attributes.push(import_common.KeyValue.decode(reader, reader.uint32()));
          continue;
        case 10:
          if (tag !== 80) {
            break;
          }
          message.droppedAttributesCount = reader.uint32();
          continue;
        case 11:
          if (tag !== 90) {
            break;
          }
          message.events.push(Span_Event.decode(reader, reader.uint32()));
          continue;
        case 12:
          if (tag !== 96) {
            break;
          }
          message.droppedEventsCount = reader.uint32();
          continue;
        case 13:
          if (tag !== 106) {
            break;
          }
          message.links.push(Span_Link.decode(reader, reader.uint32()));
          continue;
        case 14:
          if (tag !== 112) {
            break;
          }
          message.droppedLinksCount = reader.uint32();
          continue;
        case 15:
          if (tag !== 122) {
            break;
          }
          message.status = Status.decode(reader, reader.uint32());
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },
  fromJSON(object) {
    var _context11, _context12, _context13;
    return {
      traceId: isSet(object.traceId) ? bytesFromBase64(object.traceId) : new Uint8Array(0),
      spanId: isSet(object.spanId) ? bytesFromBase64(object.spanId) : new Uint8Array(0),
      traceState: isSet(object.traceState) ? import_global_this.default.String(object.traceState) : "",
      parentSpanId: isSet(object.parentSpanId) ? bytesFromBase64(object.parentSpanId) : new Uint8Array(0),
      flags: isSet((0, import_flags.default)(object)) ? import_global_this.default.Number((0, import_flags.default)(object)) : 0,
      name: isSet(object.name) ? import_global_this.default.String(object.name) : "",
      kind: isSet(object.kind) ? span_SpanKindFromJSON(object.kind) : 0,
      startTimeUnixNano: isSet(object.startTimeUnixNano) ? import_global_this.default.Number(object.startTimeUnixNano) : 0,
      endTimeUnixNano: isSet(object.endTimeUnixNano) ? import_global_this.default.Number(object.endTimeUnixNano) : 0,
      attributes: import_global_this.default.Array.isArray(object?.attributes) ? (0, import_map.default)(_context11 = object.attributes).call(_context11, (e) => import_common.KeyValue.fromJSON(e)) : [],
      droppedAttributesCount: isSet(object.droppedAttributesCount) ? import_global_this.default.Number(object.droppedAttributesCount) : 0,
      events: import_global_this.default.Array.isArray(object?.events) ? (0, import_map.default)(_context12 = object.events).call(_context12, (e) => Span_Event.fromJSON(e)) : [],
      droppedEventsCount: isSet(object.droppedEventsCount) ? import_global_this.default.Number(object.droppedEventsCount) : 0,
      links: import_global_this.default.Array.isArray(object?.links) ? (0, import_map.default)(_context13 = object.links).call(_context13, (e) => Span_Link.fromJSON(e)) : [],
      droppedLinksCount: isSet(object.droppedLinksCount) ? import_global_this.default.Number(object.droppedLinksCount) : 0,
      status: isSet(object.status) ? Status.fromJSON(object.status) : void 0
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.traceId.length !== 0) {
      obj.traceId = base64FromBytes(message.traceId);
    }
    if (message.spanId.length !== 0) {
      obj.spanId = base64FromBytes(message.spanId);
    }
    if (message.traceState !== "") {
      obj.traceState = message.traceState;
    }
    if (message.parentSpanId.length !== 0) {
      obj.parentSpanId = base64FromBytes(message.parentSpanId);
    }
    if ((0, import_flags.default)(message) !== 0) {
      obj.flags = Math.round((0, import_flags.default)(message));
    }
    if (message.name !== "") {
      obj.name = message.name;
    }
    if (message.kind !== 0) {
      obj.kind = span_SpanKindToJSON(message.kind);
    }
    if (message.startTimeUnixNano !== 0) {
      obj.startTimeUnixNano = Math.round(message.startTimeUnixNano);
    }
    if (message.endTimeUnixNano !== 0) {
      obj.endTimeUnixNano = Math.round(message.endTimeUnixNano);
    }
    if (message.attributes?.length) {
      var _context14;
      obj.attributes = (0, import_map.default)(_context14 = message.attributes).call(_context14, (e) => import_common.KeyValue.toJSON(e));
    }
    if (message.droppedAttributesCount !== 0) {
      obj.droppedAttributesCount = Math.round(message.droppedAttributesCount);
    }
    if (message.events?.length) {
      var _context15;
      obj.events = (0, import_map.default)(_context15 = message.events).call(_context15, (e) => Span_Event.toJSON(e));
    }
    if (message.droppedEventsCount !== 0) {
      obj.droppedEventsCount = Math.round(message.droppedEventsCount);
    }
    if (message.links?.length) {
      var _context16;
      obj.links = (0, import_map.default)(_context16 = message.links).call(_context16, (e) => Span_Link.toJSON(e));
    }
    if (message.droppedLinksCount !== 0) {
      obj.droppedLinksCount = Math.round(message.droppedLinksCount);
    }
    if (message.status !== void 0) {
      obj.status = Status.toJSON(message.status);
    }
    return obj;
  },
  create(base) {
    return Span.fromPartial(base ?? {});
  },
  fromPartial(object) {
    var _context17, _context18, _context19, _context20, _context21, _context22;
    const message = createBaseSpan();
    message.traceId = object.traceId ?? new Uint8Array(0);
    message.spanId = object.spanId ?? new Uint8Array(0);
    message.traceState = object.traceState ?? "";
    message.parentSpanId = object.parentSpanId ?? new Uint8Array(0);
    message.flags = (0, import_flags.default)(object) ?? 0;
    message.name = object.name ?? "";
    message.kind = object.kind ?? 0;
    message.startTimeUnixNano = object.startTimeUnixNano ?? 0;
    message.endTimeUnixNano = object.endTimeUnixNano ?? 0;
    message.attributes = ((_context17 = object.attributes) == null ? void 0 : (0, import_bind.default)(_context18 = Function.call).call(_context18, (0, import_map.default)(_context17), _context17))?.((e) => import_common.KeyValue.fromPartial(e)) || [];
    message.droppedAttributesCount = object.droppedAttributesCount ?? 0;
    message.events = ((_context19 = object.events) == null ? void 0 : (0, import_bind.default)(_context20 = Function.call).call(_context20, (0, import_map.default)(_context19), _context19))?.((e) => Span_Event.fromPartial(e)) || [];
    message.droppedEventsCount = object.droppedEventsCount ?? 0;
    message.links = ((_context21 = object.links) == null ? void 0 : (0, import_bind.default)(_context22 = Function.call).call(_context22, (0, import_map.default)(_context21), _context21))?.((e) => Span_Link.fromPartial(e)) || [];
    message.droppedLinksCount = object.droppedLinksCount ?? 0;
    message.status = object.status !== void 0 && object.status !== null ? Status.fromPartial(object.status) : void 0;
    return message;
  }
};
function createBaseSpan_Event() {
  return {
    timeUnixNano: 0,
    name: "",
    attributes: [],
    droppedAttributesCount: 0
  };
}
const Span_Event = {
  encode(message, writer = import_minimal.default.Writer.create()) {
    if (message.timeUnixNano !== 0) {
      writer.uint32(9).fixed64(message.timeUnixNano);
    }
    if (message.name !== "") {
      writer.uint32(18).string(message.name);
    }
    for (const v of message.attributes) {
      import_common.KeyValue.encode(v, writer.uint32(26).fork()).ldelim();
    }
    if (message.droppedAttributesCount !== 0) {
      writer.uint32(32).uint32(message.droppedAttributesCount);
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof import_minimal.default.Reader ? input : import_minimal.default.Reader.create(input);
    let end = length === void 0 ? reader.len : reader.pos + length;
    const message = createBaseSpan_Event();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 9) {
            break;
          }
          message.timeUnixNano = longToNumber(reader.fixed64());
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }
          message.name = reader.string();
          continue;
        case 3:
          if (tag !== 26) {
            break;
          }
          message.attributes.push(import_common.KeyValue.decode(reader, reader.uint32()));
          continue;
        case 4:
          if (tag !== 32) {
            break;
          }
          message.droppedAttributesCount = reader.uint32();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },
  fromJSON(object) {
    var _context23;
    return {
      timeUnixNano: isSet(object.timeUnixNano) ? import_global_this.default.Number(object.timeUnixNano) : 0,
      name: isSet(object.name) ? import_global_this.default.String(object.name) : "",
      attributes: import_global_this.default.Array.isArray(object?.attributes) ? (0, import_map.default)(_context23 = object.attributes).call(_context23, (e) => import_common.KeyValue.fromJSON(e)) : [],
      droppedAttributesCount: isSet(object.droppedAttributesCount) ? import_global_this.default.Number(object.droppedAttributesCount) : 0
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.timeUnixNano !== 0) {
      obj.timeUnixNano = Math.round(message.timeUnixNano);
    }
    if (message.name !== "") {
      obj.name = message.name;
    }
    if (message.attributes?.length) {
      var _context24;
      obj.attributes = (0, import_map.default)(_context24 = message.attributes).call(_context24, (e) => import_common.KeyValue.toJSON(e));
    }
    if (message.droppedAttributesCount !== 0) {
      obj.droppedAttributesCount = Math.round(message.droppedAttributesCount);
    }
    return obj;
  },
  create(base) {
    return Span_Event.fromPartial(base ?? {});
  },
  fromPartial(object) {
    var _context25, _context26;
    const message = createBaseSpan_Event();
    message.timeUnixNano = object.timeUnixNano ?? 0;
    message.name = object.name ?? "";
    message.attributes = ((_context25 = object.attributes) == null ? void 0 : (0, import_bind.default)(_context26 = Function.call).call(_context26, (0, import_map.default)(_context25), _context25))?.((e) => import_common.KeyValue.fromPartial(e)) || [];
    message.droppedAttributesCount = object.droppedAttributesCount ?? 0;
    return message;
  }
};
function createBaseSpan_Link() {
  return {
    traceId: new Uint8Array(0),
    spanId: new Uint8Array(0),
    traceState: "",
    attributes: [],
    droppedAttributesCount: 0,
    flags: 0
  };
}
const Span_Link = {
  encode(message, writer = import_minimal.default.Writer.create()) {
    if (message.traceId.length !== 0) {
      writer.uint32(10).bytes(message.traceId);
    }
    if (message.spanId.length !== 0) {
      writer.uint32(18).bytes(message.spanId);
    }
    if (message.traceState !== "") {
      writer.uint32(26).string(message.traceState);
    }
    for (const v of message.attributes) {
      import_common.KeyValue.encode(v, writer.uint32(34).fork()).ldelim();
    }
    if (message.droppedAttributesCount !== 0) {
      writer.uint32(40).uint32(message.droppedAttributesCount);
    }
    if ((0, import_flags.default)(message) !== 0) {
      writer.uint32(53).fixed32((0, import_flags.default)(message));
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof import_minimal.default.Reader ? input : import_minimal.default.Reader.create(input);
    let end = length === void 0 ? reader.len : reader.pos + length;
    const message = createBaseSpan_Link();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }
          message.traceId = reader.bytes();
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }
          message.spanId = reader.bytes();
          continue;
        case 3:
          if (tag !== 26) {
            break;
          }
          message.traceState = reader.string();
          continue;
        case 4:
          if (tag !== 34) {
            break;
          }
          message.attributes.push(import_common.KeyValue.decode(reader, reader.uint32()));
          continue;
        case 5:
          if (tag !== 40) {
            break;
          }
          message.droppedAttributesCount = reader.uint32();
          continue;
        case 6:
          if (tag !== 53) {
            break;
          }
          message.flags = reader.fixed32();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },
  fromJSON(object) {
    var _context27;
    return {
      traceId: isSet(object.traceId) ? bytesFromBase64(object.traceId) : new Uint8Array(0),
      spanId: isSet(object.spanId) ? bytesFromBase64(object.spanId) : new Uint8Array(0),
      traceState: isSet(object.traceState) ? import_global_this.default.String(object.traceState) : "",
      attributes: import_global_this.default.Array.isArray(object?.attributes) ? (0, import_map.default)(_context27 = object.attributes).call(_context27, (e) => import_common.KeyValue.fromJSON(e)) : [],
      droppedAttributesCount: isSet(object.droppedAttributesCount) ? import_global_this.default.Number(object.droppedAttributesCount) : 0,
      flags: isSet((0, import_flags.default)(object)) ? import_global_this.default.Number((0, import_flags.default)(object)) : 0
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.traceId.length !== 0) {
      obj.traceId = base64FromBytes(message.traceId);
    }
    if (message.spanId.length !== 0) {
      obj.spanId = base64FromBytes(message.spanId);
    }
    if (message.traceState !== "") {
      obj.traceState = message.traceState;
    }
    if (message.attributes?.length) {
      var _context28;
      obj.attributes = (0, import_map.default)(_context28 = message.attributes).call(_context28, (e) => import_common.KeyValue.toJSON(e));
    }
    if (message.droppedAttributesCount !== 0) {
      obj.droppedAttributesCount = Math.round(message.droppedAttributesCount);
    }
    if ((0, import_flags.default)(message) !== 0) {
      obj.flags = Math.round((0, import_flags.default)(message));
    }
    return obj;
  },
  create(base) {
    return Span_Link.fromPartial(base ?? {});
  },
  fromPartial(object) {
    var _context29, _context30;
    const message = createBaseSpan_Link();
    message.traceId = object.traceId ?? new Uint8Array(0);
    message.spanId = object.spanId ?? new Uint8Array(0);
    message.traceState = object.traceState ?? "";
    message.attributes = ((_context29 = object.attributes) == null ? void 0 : (0, import_bind.default)(_context30 = Function.call).call(_context30, (0, import_map.default)(_context29), _context29))?.((e) => import_common.KeyValue.fromPartial(e)) || [];
    message.droppedAttributesCount = object.droppedAttributesCount ?? 0;
    message.flags = (0, import_flags.default)(object) ?? 0;
    return message;
  }
};
function createBaseStatus() {
  return {
    message: "",
    code: 0
  };
}
const Status = {
  encode(message, writer = import_minimal.default.Writer.create()) {
    if (message.message !== "") {
      writer.uint32(18).string(message.message);
    }
    if (message.code !== 0) {
      writer.uint32(24).int32(message.code);
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof import_minimal.default.Reader ? input : import_minimal.default.Reader.create(input);
    let end = length === void 0 ? reader.len : reader.pos + length;
    const message = createBaseStatus();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 2:
          if (tag !== 18) {
            break;
          }
          message.message = reader.string();
          continue;
        case 3:
          if (tag !== 24) {
            break;
          }
          message.code = reader.int32();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },
  fromJSON(object) {
    return {
      message: isSet(object.message) ? import_global_this.default.String(object.message) : "",
      code: isSet(object.code) ? status_StatusCodeFromJSON(object.code) : 0
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.message !== "") {
      obj.message = message.message;
    }
    if (message.code !== 0) {
      obj.code = status_StatusCodeToJSON(message.code);
    }
    return obj;
  },
  create(base) {
    return Status.fromPartial(base ?? {});
  },
  fromPartial(object) {
    const message = createBaseStatus();
    message.message = object.message ?? "";
    message.code = object.code ?? 0;
    return message;
  }
};
function bytesFromBase64(b64) {
  if (import_global_this.default.Buffer) {
    return Uint8Array.from(import_global_this.default.Buffer.from(b64, "base64"));
  } else {
    const bin = import_global_this.default.atob(b64);
    const arr = new Uint8Array(bin.length);
    for (let i = 0; i < bin.length; ++i) {
      arr[i] = bin.charCodeAt(i);
    }
    return arr;
  }
}
function base64FromBytes(arr) {
  if (import_global_this.default.Buffer) {
    return import_global_this.default.Buffer.from(arr).toString("base64");
  } else {
    const bin = [];
    (0, import_for_each.default)(arr).call(arr, (byte) => {
      bin.push(import_global_this.default.String.fromCharCode(byte));
    });
    return import_global_this.default.btoa(bin.join(""));
  }
}
function longToNumber(long) {
  if (long.gt(import_global_this.default.Number.MAX_SAFE_INTEGER)) {
    throw new import_global_this.default.Error("Value is larger than Number.MAX_SAFE_INTEGER");
  }
  return long.toNumber();
}
if (import_minimal.default.util.Long !== import_long.default) {
  import_minimal.default.util.Long = import_long.default;
  import_minimal.default.configure();
}
function isSet(value) {
  return value !== null && value !== void 0;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ResourceSpans,
  ScopeSpans,
  Span,
  SpanFlags,
  Span_Event,
  Span_Link,
  Span_SpanKind,
  Status,
  Status_StatusCode,
  TracesData,
  protobufPackage,
  spanFlagsFromJSON,
  spanFlagsToJSON,
  span_SpanKindFromJSON,
  span_SpanKindToJSON,
  status_StatusCodeFromJSON,
  status_StatusCodeToJSON
});
//# sourceMappingURL=trace.js.map
