-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add initial code instrumentation with honeycomb #15
Conversation
f81c9ff
to
3853ec1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall it is OK, but please create a missing PR and test it E2E 👍 Thanks!
internal/source/ai-brain/brain.go
Outdated
@@ -83,6 +88,14 @@ func (s *Source) Stream(ctx context.Context, in source.StreamInput) (source.Stre | |||
|
|||
sourceName := in.Context.SourceName | |||
|
|||
// Set up opentelemetry with honeycomb if enabled. | |||
if cfg.HoneycombAPIKey != "" { | |||
otelServiceName := "plugins-source-" + sourceName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot assume this will be unique in the whole Botkube Cloud. Probably there could be some duplication between orgs as we randomize just 4-5 chars AFAIR. Is it good enough for our use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you suggest we change it to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just wanted to double check if that's OK - personally I think that should be good enough. If not, then we'd probably need to randomize it or use kube-system
ns uid, like with telemetry 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
service name property is used as a dataset name in honeycomb, so it's quite important I'd say. We don't want to have a gazillion datasets in honeycomb as that would be quite tricky to query. Maybe botkube-plugins-source-ai-brain
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, so the goal is to group them all under a single static service name. Then yes, botkube-plugins-source-ai-brain
or plugins-source-ai-brain
sound good 👍
a822b58
to
15797c4
Compare
@@ -99,14 +101,14 @@ func (s *Source) Stream(ctx context.Context, in source.StreamInput) (source.Stre | |||
} | |||
|
|||
// HandleExternalRequest handles incoming payload and returns an event based on it. | |||
func (s *Source) HandleExternalRequest(_ context.Context, in source.ExternalRequestInput) (source.ExternalRequestOutput, error) { | |||
func (s *Source) HandleExternalRequest(ctx context.Context, in source.ExternalRequestInput) (source.ExternalRequestOutput, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (s *Source) HandleExternalRequest(ctx context.Context, in source.ExternalRequestInput) (source.ExternalRequestOutput, error) { | |
func (s *Source) HandleExternalRequest(- context.Context, in source.ExternalRequestInput) (source.ExternalRequestOutput, error) { |
func (i *assistant) handleThread(ctx context.Context, p *Payload) error { | ||
ctx, span := i.tracer.Start(ctx, "aibrain.assistant.handleThread") | ||
defer span.End() | ||
|
||
var thread openai.Thread | ||
var err error | ||
|
||
defer func() { | ||
if err != nil { | ||
span.RecordError(err) | ||
span.SetStatus(codes.Error, err.Error()) | ||
} | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in order to make it work in all cases, you need to introduce named return param instead of var
👍
func (i *assistant) handleThread(ctx context.Context, p *Payload) error { | |
ctx, span := i.tracer.Start(ctx, "aibrain.assistant.handleThread") | |
defer span.End() | |
var thread openai.Thread | |
var err error | |
defer func() { | |
if err != nil { | |
span.RecordError(err) | |
span.SetStatus(codes.Error, err.Error()) | |
} | |
}() | |
func (i *assistant) handleThread(ctx context.Context, p *Payload) (err error) { | |
ctx, span := i.tracer.Start(ctx, "aibrain.assistant.handleThread") | |
defer span.End() | |
var thread openai.Thread | |
defer func() { | |
if err != nil { | |
span.RecordError(err) | |
span.SetStatus(codes.Error, err.Error()) | |
} | |
}() | |
I double-checked that with this unit-test:
Details
func TestNamedParams(t *testing.T) {
t.Log("here we will catch the error as it's assigned to the 'var err' before returning")
_ = handleThread(t, false)
t.Log("here we won't catch the error as it's directly returned")
_ = handleThread(t, true)
t.Log("named return params - this will work")
_ = handleThreadV2(t, true)
}
func handleThread(t *testing.T, directFnReturn bool) error {
var err error
defer func() {
if err != nil {
t.Log("Error on defer:", err)
}
}()
if !directFnReturn {
err = errors.New("some error, directFnReturn = false")
if err != nil {
return fmt.Errorf("while creating a new message on a thread: %w", err)
}
}
return returnError()
}
func handleThreadV2(t *testing.T, directFnReturn bool) (err error) {
defer func() {
if err != nil {
t.Log("Error on defer:", err)
}
}()
if !directFnReturn {
err = errors.New("some error, directFnReturn = false")
if err != nil {
return fmt.Errorf("while creating a new message on a thread: %w", err)
}
}
return returnError()
}
func returnError() error {
return errors.New("some error, directFnReturn = true")
}
Description
Changes proposed in this pull request:
Related issue(s)