Skip to content

Conversation

@zeebo
Copy link
Member

@zeebo zeebo commented Jan 14, 2026

this adds a hook so that span creation and completion can be observed. this lets us more cheaply hook every span that monkit creates without having to use the trace observer system.

}
plugins := *pluginsPtr

nextPlugins := make([]SpanPlugin, len(plugins)+1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not worth the optimization, but we can reuse the buffer when retrying, rather than allocating a completely new one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concurrent callers could stomp over each other.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant reusing the nextPlugins:

func (r *Registry) AddSpanPlugin(h SpanPlugin) {
	var nextPlugins []SpanPlugin
	for {
		pluginsPtr := r.plugins.Load()
		if pluginsPtr == nil {
			r.plugins.CompareAndSwap(nil, new([]SpanPlugin))
			continue
		}
		plugins := *pluginsPtr

		nextPlugins = slices.Grow(nextPlugins[:0], len(plugins)+1)
		copy(nextPlugins, plugins...)
		nextPlugins[len(nextPlugins)-1] = h

		if r.plugins.CompareAndSwap(pluginsPtr, &nextPlugins) {
			return
		}
	}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooh yeah that would be fine of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants