@@ -26,6 +26,8 @@ func NewFranzProducerMetrics(tb *metadata.TelemetryBuilder) FranzProducerMetrics
2626 return FranzProducerMetrics {tb : tb }
2727}
2828
29+ var _ kgo.HookBrokerConnect = FranzProducerMetrics {}
30+
2931func (fpm FranzProducerMetrics ) OnBrokerConnect (meta kgo.BrokerMetadata , _ time.Duration , _ net.Conn , err error ) {
3032 outcome := "success"
3133 if err != nil {
@@ -41,6 +43,8 @@ func (fpm FranzProducerMetrics) OnBrokerConnect(meta kgo.BrokerMetadata, _ time.
4143 )
4244}
4345
46+ var _ kgo.HookBrokerDisconnect = FranzProducerMetrics {}
47+
4448func (fpm FranzProducerMetrics ) OnBrokerDisconnect (meta kgo.BrokerMetadata , _ net.Conn ) {
4549 fpm .tb .KafkaBrokerClosed .Add (
4650 context .Background (),
@@ -51,6 +55,8 @@ func (fpm FranzProducerMetrics) OnBrokerDisconnect(meta kgo.BrokerMetadata, _ ne
5155 )
5256}
5357
58+ var _ kgo.HookBrokerThrottle = FranzProducerMetrics {}
59+
5460func (fpm FranzProducerMetrics ) OnBrokerThrottle (meta kgo.BrokerMetadata , throttleInterval time.Duration , _ bool ) {
5561 // KafkaBrokerThrottlingDuration is deprecated in favor of KafkaBrokerThrottlingLatency.
5662 fpm .tb .KafkaBrokerThrottlingDuration .Record (
@@ -69,30 +75,34 @@ func (fpm FranzProducerMetrics) OnBrokerThrottle(meta kgo.BrokerMetadata, thrott
6975 )
7076}
7177
72- func (fpm FranzProducerMetrics ) OnBrokerWrite (meta kgo.BrokerMetadata , _ int16 , _ int , writeWait , timeToWrite time.Duration , err error ) {
78+ var _ kgo.HookBrokerE2E = FranzProducerMetrics {}
79+
80+ func (fpm FranzProducerMetrics ) OnBrokerE2E (meta kgo.BrokerMetadata , _ int16 , e2e kgo.BrokerE2E ) {
7381 outcome := "success"
74- if err != nil {
82+ if e2e . Err () != nil {
7583 outcome = "failure"
7684 }
7785 // KafkaExporterLatency is deprecated in favor of KafkaExporterWriteLatency.
7886 fpm .tb .KafkaExporterLatency .Record (
7987 context .Background (),
80- writeWait . Milliseconds ()+ timeToWrite .Milliseconds (),
88+ e2e . DurationE2E (). Milliseconds ()+ e2e . WriteWait .Milliseconds (),
8189 metric .WithAttributes (
8290 attribute .String ("node_id" , kgo .NodeName (meta .NodeID )),
8391 attribute .String ("outcome" , outcome ),
8492 ),
8593 )
8694 fpm .tb .KafkaExporterWriteLatency .Record (
8795 context .Background (),
88- writeWait . Seconds ()+ timeToWrite .Seconds (),
96+ e2e . DurationE2E (). Seconds ()+ e2e . WriteWait .Seconds (),
8997 metric .WithAttributes (
9098 attribute .String ("node_id" , kgo .NodeName (meta .NodeID )),
9199 attribute .String ("outcome" , outcome ),
92100 ),
93101 )
94102}
95103
104+ var _ kgo.HookProduceBatchWritten = FranzProducerMetrics {}
105+
96106// OnProduceBatchWritten is called when a batch has been produced.
97107// https://pkg.go.dev/github.com/twmb/franz-go/pkg/kgo#HookProduceBatchWritten
98108func (fpm FranzProducerMetrics ) OnProduceBatchWritten (meta kgo.BrokerMetadata , topic string , partition int32 , m kgo.ProduceBatchMetrics ) {
@@ -126,6 +136,8 @@ func (fpm FranzProducerMetrics) OnProduceBatchWritten(meta kgo.BrokerMetadata, t
126136 )
127137}
128138
139+ var _ kgo.HookProduceRecordUnbuffered = FranzProducerMetrics {}
140+
129141// OnProduceRecordUnbuffered records the number of produced messages that were
130142// not produced due to errors. The successfully produced records is recorded by
131143// `OnProduceBatchWritten`.
0 commit comments