Skip to content

Move the Event type from the API to the SDK #1845

@MrAlias

Description

@MrAlias

Currently the API exports an Event type:

// Event is a thing that happened during a Span's lifetime.
type Event struct {
// Name is the name of this event
Name string
// Attributes describe the aspects of the event.
Attributes []attribute.KeyValue
// DroppedAttributeCount is the number of attributes that were not
// recorded due to configured limits being reached.
DroppedAttributeCount int
// Time at which this event was recorded.
Time time.Time
}

This type is not used in the API, it is used in the trace SDK and those values of this type that it creates are passed down the processing pipeline. It does not make sense to have this type exported from the API. It should be included in the package that actually uses it, the trace SDK.

What about the API asymmetry between the Link and Event?

The following is mostly added to capture the though process that went into the decision to not move the Link type as well and is included for transparency and future understanding of the decision.

It seems wrong to move this type without also moving the Link type also declared in the API. This cannot be done though because the Link type is directly used in the API by being passed to the WithLinks SpanOption.

// WithLinks adds links to a Span. The links are added to the existing Span
// links, i.e. this does not overwrite.
func WithLinks(links ...Link) SpanOption {
return linksSpanOption(links)
}

This exposes an underlying asymmetry issue between the argument structure of functions in the API. The methods that create a span event accept the component parts of the event as arguments, but the function to create a span link accepts the composite struct type itself. This is the only part of the API where we use an underlying struct type to pass configuration state as an argument instead of functional options.

Possible Solutions

1) Move Event and Link type to SDK and update WithLinks SpanOption

  1. Move the Event type to the otel/sdk/trace package.
  2. Move the Link type to the otel/sdk/trace package.
  3. Remove the WithLinks SpanOption.
  4. Add a new WithLink SpanOption to the otel/trace package. E.g.
    func WithLinks(sc SpanContext, attr ...attribute.KeyValue) SpanOption
    

Pros:

  • Resolves the API asymmetry
  • Unifies the API function argument pattern
    • This might be an anti-pattern given it is uniformity driving design without considering what is appropriate for the situation.

Cons:

  • The span link API cannot be extended. If we want to add additional annotations to a link besides attributes it would require a breaking change to the function signature.

2) Move the Event type to SDK, but leave the Link type

  1. Move the Event type to the otel/sdk/trace package.
  2. Make no other API changes and leave the asymmetry in place.

Pros:

  • Allows links to be extended in the future in a backwards compatible way.

Cons:

  • Preserves the API asymmetry

3) Update the AddEvent method of the "otel/trace".Span interface to accept the Event type instead of EventOptions.

  1. Update the "otel/trace".Span interface AddEvent method to accept the Event type instead of EventOptions
  2. Make no other API changes.

Pros:

  • Resolves the API asymmetry between the Event and Link functions

Cons:

  • Splits the API further into accepting functional options in some places and config structs in others
  • It is not clear how the RecordError method, which creates an event, should be updated (or not) to support this

Proposed Solution

Move the Event type to SDK, but leave the Link type.

Metadata

Metadata

Assignees

Labels

area:tracePart of OpenTelemetry tracingpkg:APIRelated to an API packagepkg:SDKRelated to an SDK packagequestionFurther information is requested

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions