7
7
"context"
8
8
"encoding/json"
9
9
"fmt"
10
- semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
11
10
"net"
12
11
"net/http"
13
12
"os"
@@ -311,7 +310,7 @@ func (cs *checkoutService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderReq
311
310
312
311
// send to kafka only if kafka broker address is set
313
312
if cs .kafkaBrokerSvcAddr != "" {
314
- cs .sendToPostProcessor (ctx , orderResult )
313
+ cs .sendToPostProcessor (orderResult )
315
314
}
316
315
317
316
resp := & pb.PlaceOrderResponse {Order : orderResult }
@@ -474,7 +473,7 @@ func (cs *checkoutService) shipOrder(ctx context.Context, address *pb.Address, i
474
473
return resp .GetTrackingId (), nil
475
474
}
476
475
477
- func (cs * checkoutService ) sendToPostProcessor (ctx context. Context , result * pb.OrderResult ) {
476
+ func (cs * checkoutService ) sendToPostProcessor (result * pb.OrderResult ) {
478
477
message , err := proto .Marshal (result )
479
478
if err != nil {
480
479
log .Errorf ("Failed to marshal message to protobuf: %+v" , err )
@@ -486,37 +485,7 @@ func (cs *checkoutService) sendToPostProcessor(ctx context.Context, result *pb.O
486
485
Value : sarama .ByteEncoder (message ),
487
486
}
488
487
489
- // Inject tracing info into message
490
- span := createProducerSpan (ctx , & msg )
491
- defer span .End ()
492
-
493
488
cs .KafkaProducerClient .Input () <- & msg
494
489
successMsg := <- cs .KafkaProducerClient .Successes ()
495
490
log .Infof ("Successful to write message. offset: %v" , successMsg .Offset )
496
491
}
497
-
498
- func createProducerSpan (ctx context.Context , msg * sarama.ProducerMessage ) trace.Span {
499
- spanContext , span := tracer .Start (
500
- ctx ,
501
- fmt .Sprintf ("%s publish" , msg .Topic ),
502
- trace .WithSpanKind (trace .SpanKindProducer ),
503
- trace .WithAttributes (
504
- semconv .PeerService ("kafka" ),
505
- semconv .NetworkTransportTCP ,
506
- semconv .MessagingSystemKafka ,
507
- semconv .MessagingDestinationName (msg .Topic ),
508
- semconv .MessagingOperationPublish ,
509
- semconv .MessagingKafkaDestinationPartition (int (msg .Partition )),
510
- ),
511
- )
512
-
513
- carrier := propagation.MapCarrier {}
514
- propagator := otel .GetTextMapPropagator ()
515
- propagator .Inject (spanContext , carrier )
516
-
517
- for key , value := range carrier {
518
- msg .Headers = append (msg .Headers , sarama.RecordHeader {Key : []byte (key ), Value : []byte (value )})
519
- }
520
-
521
- return span
522
- }
0 commit comments