{"version":3,"file":"EmbraceExtendedSpan.cjs","names":["KEY_EMB_ERROR_CODE"],"sources":["../../../src/managers/EmbraceTraceManager/EmbraceExtendedSpan.ts"],"sourcesContent":["import type {\n  Attributes,\n  AttributeValue,\n  Exception,\n  Link,\n  Span,\n  SpanContext,\n  SpanStatus,\n  TimeInput,\n} from '@opentelemetry/api';\nimport type {\n  ExtendedSpan,\n  ExtendedSpanFailedOptions,\n} from '../../api-traces/index.ts';\nimport { KEY_EMB_ERROR_CODE } from '../../constants/index.ts';\n\n/**\n * EmbraceSpan for the most part simply delegates to the underlying Span it receives on initialization so\n * that it satisfies the Span interface. In addition, it gives us a spot where we can implement helpers that are part\n * of the EmbraceSpan interface.\n */\nexport class EmbraceExtendedSpan implements ExtendedSpan {\n  private readonly _span: ExtendedSpan;\n\n  public constructor(span: Span) {\n    this._span = span as ExtendedSpan;\n  }\n\n  /**\n   * Expose attributes by extending OpenTelemetry's ReadableSpan.\n   */\n  public get attributes(): Attributes {\n    return this._span.attributes;\n  }\n\n  public addEvent(\n    name: string,\n    attributesOrStartTime?: Attributes | TimeInput,\n    startTime?: TimeInput,\n  ): this {\n    this._span.addEvent(name, attributesOrStartTime, startTime);\n    return this;\n  }\n\n  public addLink(link: Link): this {\n    this._span.addLink(link);\n    return this;\n  }\n\n  public addLinks(links: Link[]): this {\n    this._span.addLinks(links);\n    return this;\n  }\n\n  public end(endTime?: TimeInput): void {\n    this._span.end(endTime);\n  }\n\n  public isRecording(): boolean {\n    return this._span.isRecording();\n  }\n\n  public recordException(exception: Exception, time?: TimeInput): void {\n    this._span.recordException(exception, time);\n  }\n\n  public setAttribute(key: string, value: AttributeValue): this {\n    this._span.setAttribute(key, value);\n    return this;\n  }\n\n  public setAttributes(attributes: Attributes): this {\n    this._span.setAttributes(attributes);\n    return this;\n  }\n\n  public removeAttribute(key: string): this {\n    const { [key]: _, ...attributes } = this._span.attributes;\n    // @ts-expect-error Read/write spans are allowed per the spec https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#additional-span-interfaces\n    this._span.attributes = attributes;\n    return this;\n  }\n\n  public setStatus(status: SpanStatus): this {\n    this._span.setStatus(status);\n    return this;\n  }\n\n  public spanContext(): SpanContext {\n    return this._span.spanContext();\n  }\n\n  public updateName(name: string): this {\n    this._span.updateName(name);\n    return this;\n  }\n\n  public fail(\n    options: ExtendedSpanFailedOptions = {\n      code: 'failure',\n    },\n  ): void {\n    if (options.code) {\n      this._span.setAttribute(KEY_EMB_ERROR_CODE, options.code.toUpperCase());\n    }\n\n    this._span.end(options.endTime);\n  }\n}\n"],"mappings":";;;;;;;;AAqBA,IAAa,sBAAb,MAAyD;CACvD;CAEA,YAAmB,MAAY;AAC7B,OAAK,QAAQ;;;;;CAMf,IAAW,aAAyB;AAClC,SAAO,KAAK,MAAM;;CAGpB,SACE,MACA,uBACA,WACM;AACN,OAAK,MAAM,SAAS,MAAM,uBAAuB,UAAU;AAC3D,SAAO;;CAGT,QAAe,MAAkB;AAC/B,OAAK,MAAM,QAAQ,KAAK;AACxB,SAAO;;CAGT,SAAgB,OAAqB;AACnC,OAAK,MAAM,SAAS,MAAM;AAC1B,SAAO;;CAGT,IAAW,SAA2B;AACpC,OAAK,MAAM,IAAI,QAAQ;;CAGzB,cAA8B;AAC5B,SAAO,KAAK,MAAM,aAAa;;CAGjC,gBAAuB,WAAsB,MAAwB;AACnE,OAAK,MAAM,gBAAgB,WAAW,KAAK;;CAG7C,aAAoB,KAAa,OAA6B;AAC5D,OAAK,MAAM,aAAa,KAAK,MAAM;AACnC,SAAO;;CAGT,cAAqB,YAA8B;AACjD,OAAK,MAAM,cAAc,WAAW;AACpC,SAAO;;CAGT,gBAAuB,KAAmB;EACxC,MAAM,GAAG,MAAM,GAAG,GAAG,eAAe,KAAK,MAAM;AAE/C,OAAK,MAAM,aAAa;AACxB,SAAO;;CAGT,UAAiB,QAA0B;AACzC,OAAK,MAAM,UAAU,OAAO;AAC5B,SAAO;;CAGT,cAAkC;AAChC,SAAO,KAAK,MAAM,aAAa;;CAGjC,WAAkB,MAAoB;AACpC,OAAK,MAAM,WAAW,KAAK;AAC3B,SAAO;;CAGT,KACE,UAAqC,EACnC,MAAM,WACP,EACK;AACN,MAAI,QAAQ,KACV,MAAK,MAAM,aAAaA,6BAAAA,oBAAoB,QAAQ,KAAK,aAAa,CAAC;AAGzE,OAAK,MAAM,IAAI,QAAQ,QAAQ"}