Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(sdk-base)!: Use TypeScript overload signature for addEvent #5359

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion api/src/trace/NonRecordingSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ export class NonRecordingSpan implements Span {
}

// By default does nothing
addEvent(_name: string, _attributes?: SpanAttributes): this {
addEvent(name: string, startTime?: TimeInput): this;
addEvent(
name: string,
attributes: SpanAttributes | undefined,
startTime?: TimeInput
): this;
addEvent(): this {
return this;
}

Expand Down
8 changes: 4 additions & 4 deletions api/src/trace/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ export interface Span {
* Adds an event to the Span.
*
* @param name the name of the event.
* @param [attributesOrStartTime] the attributes that will be added; these are
* associated with this event. Can be also a start time
* if type is {@type TimeInput} and 3rd param is undefined
* @param [attributes] the attributes that will be added; these are
* associated with this event.
* @param [startTime] start time of the event.
*/
addEvent(name: string, startTime?: TimeInput): this;
addEvent(
name: string,
attributesOrStartTime?: SpanAttributes | TimeInput,
attributes: SpanAttributes | undefined,
startTime?: TimeInput
): this;

Expand Down
24 changes: 14 additions & 10 deletions packages/opentelemetry-sdk-trace-base/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,18 @@ export class SpanImpl implements Span {
/**
*
* @param name Span Name
* @param [attributesOrStartTime] Span attributes or start time
* if type is {@type TimeInput} and 3rd param is undefined
* @param [attributes] Span attributes for the event
* @param [timeStamp] Specified time stamp for the event
*/
addEvent(name: string, timeStamp?: TimeInput): this;
addEvent(
name: string,
attributesOrStartTime?: Attributes | TimeInput,
attributes: Attributes | undefined,
timeStamp?: TimeInput
): this;
addEvent(
name: string,
attributesOrTimestamp?: Attributes | TimeInput,
timeStamp?: TimeInput
): this {
if (this._isSpanEnded()) return this;
Expand All @@ -202,14 +207,13 @@ export class SpanImpl implements Span {
this._droppedEventsCount++;
}

if (isTimeInput(attributesOrStartTime)) {
if (!isTimeInput(timeStamp)) {
timeStamp = attributesOrStartTime;
}
attributesOrStartTime = undefined;
}
let attributes: Attributes | undefined = undefined;

const attributes = sanitizeAttributes(attributesOrStartTime);
if (isTimeInput(attributesOrTimestamp)) {
timeStamp = attributesOrTimestamp;
} else {
attributes = sanitizeAttributes(attributesOrTimestamp);
}

this.events.push({
name,
Expand Down
Loading