Skip to content

Commit

Permalink
fix: do not reuse logger in topiccreator (#573)
Browse files Browse the repository at this point in the history
logger should be scoped to the loop/response because the logfieldfunc
could set topic-specific fields

Related to elastic/apm-managed-service#470
  • Loading branch information
kruskall authored Sep 23, 2024
1 parent 986e89f commit 4ae7121
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kafka/topiccreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ func (c *TopicCreator) CreateTopics(ctx context.Context, topics ...apmqueue.Topi
}

var updateErrors []error
logger := c.m.cfg.Logger.With(loggerFields...)
for _, response := range responses.Sorted() {
topicName := strings.TrimPrefix(response.Topic, namespacePrefix)
logger := c.m.cfg.Logger.With(loggerFields...)
if c.m.cfg.TopicLogFieldFunc != nil {
logger = logger.With(c.m.cfg.TopicLogFieldFunc(topicName))
}
Expand Down Expand Up @@ -222,6 +222,7 @@ func (c *TopicCreator) CreateTopics(ctx context.Context, topics ...apmqueue.Topi
}
for _, response := range updateResp.Sorted() {
topicName := strings.TrimPrefix(response.Topic, namespacePrefix)
logger := c.m.cfg.Logger.With(loggerFields...)
if c.m.cfg.TopicLogFieldFunc != nil {
logger = logger.With(c.m.cfg.TopicLogFieldFunc(topicName))
}
Expand Down Expand Up @@ -264,6 +265,7 @@ func (c *TopicCreator) CreateTopics(ctx context.Context, topics ...apmqueue.Topi
}
for _, response := range alterResp {
topicName := strings.TrimPrefix(response.Name, namespacePrefix)
logger := c.m.cfg.Logger.With(loggerFields...)
if c.m.cfg.TopicLogFieldFunc != nil {
logger = logger.With(c.m.cfg.TopicLogFieldFunc(topicName))
}
Expand Down

0 comments on commit 4ae7121

Please sign in to comment.