Skip to content

Commit ef56fa0

Browse files
committed
[#78] add document comments
1 parent 7ae50a7 commit ef56fa0

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

plugin/sarama/consumer.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
//
99
// ConsumePartition example:
1010
//
11-
// ctx := ppsarama.NewContext(context.Background(), broker)
12-
// pc, _ := consumer.ConsumePartition(topic, partition, offset)
13-
// for msg := range pc.Messages() {
14-
// ppsarama.ConsumeMessageContext(processMessage, ctx, msg)
15-
// }
11+
// ctx := ppsarama.NewContext(context.Background(), broker)
12+
// pc, _ := consumer.ConsumePartition(topic, partition, offset)
13+
// for msg := range pc.Messages() {
14+
// ppsarama.ConsumeMessageContext(processMessage, ctx, msg)
15+
// }
1616
//
1717
// ConsumerGroupHandler example:
1818
//
19-
// func (h exampleConsumerGroupHandler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
20-
// ctx := sess.Context()
21-
// for msg := range claim.Messages() {
22-
// _ = ppsarama.ConsumeMessageContext(process, ctx, msg)
23-
// }
19+
// func (h exampleConsumerGroupHandler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
20+
// ctx := sess.Context()
21+
// for msg := range claim.Messages() {
22+
// _ = ppsarama.ConsumeMessageContext(process, ctx, msg)
23+
// }
2424
//
2525
// ConsumeMessageContext passes a context added pinpoint.Tracer to HandlerContextFunc.
2626
// In HandlerContextFunc, this tracer can be obtained by using the pinpoint.FromContext function.
2727
//
28-
// func process(ctx context.Context, msg *sarama.ConsumerMessage) error {
29-
// tracer := pinpoint.FromContext(ctx)
30-
// defer tracer.NewSpanEvent("process").EndSpanEvent()
28+
// func process(ctx context.Context, msg *sarama.ConsumerMessage) error {
29+
// tracer := pinpoint.FromContext(ctx)
30+
// defer tracer.NewSpanEvent("process").EndSpanEvent()
3131
//
32-
// fmt.Printf("Message topic:%q partition:%d offset:%d\n", msg.Topic, msg.Partition, msg.Offset)
32+
// fmt.Printf("Message topic:%q partition:%d offset:%d\n", msg.Topic, msg.Partition, msg.Offset)
3333
//
3434
// To instrument a Kafka producer, use NewSyncProducer or NewAsyncProducer.
3535
//
@@ -39,8 +39,12 @@
3939
// It is necessary to pass the context containing the pinpoint.Tracer
4040
// to sarama.SyncProducer (or sarama.AsyncProducer) using WithContext function.
4141
//
42-
// ppsarama.WithContext(pinpoint.NewContext(context.Background(), tracer), producer)
43-
// partition, offset, err := producer.SendMessage(msg)
42+
// ppsarama.WithContext(pinpoint.NewContext(context.Background(), tracer), producer)
43+
// partition, offset, err := producer.SendMessage(msg)
44+
//
45+
// The WithContext function() function is not thread-safe, so use the SendMessageContext function() if you have a data trace.
46+
//
47+
// partition, offset, err := producer.SendMessageContext(r.Context(), msg)
4448
package ppsarama
4549

4650
import (

plugin/sarama/syncproducer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ func (m *distributedTracingContextWriterConsumer) Set(key string, value string)
2929
})
3030
}
3131

32+
// SendMessageContext produces a given message with the context.
33+
// It is possible to trace only when the given context contains a pinpoint.Tracer.
3234
func (p *syncProducer) SendMessageContext(ctx context.Context, msg *sarama.ProducerMessage) (partition int32, offset int64, err error) {
3335
defer newProducerTracer(ctx, p.addrs, msg).EndSpanEvent()
3436
partition, offset, err = p.SyncProducer.SendMessage(msg)
@@ -39,6 +41,8 @@ func (p *syncProducer) SendMessage(msg *sarama.ProducerMessage) (partition int32
3941
return p.SendMessageContext(p.ctx, msg)
4042
}
4143

44+
// SendMessagesContext produces a given set of messages with the context.
45+
// It is possible to trace only when the given context contains a pinpoint.Tracer.
4246
func (p *syncProducer) SendMessagesContext(ctx context.Context, msgs []*sarama.ProducerMessage) error {
4347
spans := make([]pinpoint.Tracer, len(msgs))
4448
for i, msg := range msgs {

0 commit comments

Comments
 (0)