@embrace-io/web-sdk
Version:
1 lines • 4.04 kB
Source Map (JSON)
{"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;EAC7B,KAAK,QAAQ;CACf;;;;CAKA,IAAW,aAAyB;EAClC,OAAO,KAAK,MAAM;CACpB;CAEA,SACE,MACA,uBACA,WACM;EACN,KAAK,MAAM,SAAS,MAAM,uBAAuB,SAAS;EAC1D,OAAO;CACT;CAEA,QAAe,MAAkB;EAC/B,KAAK,MAAM,QAAQ,IAAI;EACvB,OAAO;CACT;CAEA,SAAgB,OAAqB;EACnC,KAAK,MAAM,SAAS,KAAK;EACzB,OAAO;CACT;CAEA,IAAW,SAA2B;EACpC,KAAK,MAAM,IAAI,OAAO;CACxB;CAEA,cAA8B;EAC5B,OAAO,KAAK,MAAM,YAAY;CAChC;CAEA,gBAAuB,WAAsB,MAAwB;EACnE,KAAK,MAAM,gBAAgB,WAAW,IAAI;CAC5C;CAEA,aAAoB,KAAa,OAA6B;EAC5D,KAAK,MAAM,aAAa,KAAK,KAAK;EAClC,OAAO;CACT;CAEA,cAAqB,YAA8B;EACjD,KAAK,MAAM,cAAc,UAAU;EACnC,OAAO;CACT;CAEA,gBAAuB,KAAmB;EACxC,MAAM,GAAG,MAAM,GAAG,GAAG,eAAe,KAAK,MAAM;EAE/C,KAAK,MAAM,aAAa;EACxB,OAAO;CACT;CAEA,UAAiB,QAA0B;EACzC,KAAK,MAAM,UAAU,MAAM;EAC3B,OAAO;CACT;CAEA,cAAkC;EAChC,OAAO,KAAK,MAAM,YAAY;CAChC;CAEA,WAAkB,MAAoB;EACpC,KAAK,MAAM,WAAW,IAAI;EAC1B,OAAO;CACT;CAEA,KACE,UAAqC,EACnC,MAAM,UACR,GACM;EACN,IAAI,QAAQ,MACV,KAAK,MAAM,aAAaA,6BAAAA,oBAAoB,QAAQ,KAAK,YAAY,CAAC;EAGxE,KAAK,MAAM,IAAI,QAAQ,OAAO;CAChC;AACF"}