Abacn commented on code in PR #40483:
URL: https://github.com/apache/beam/pull/40483#discussion_r4231514612


##########
sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java:
##########


Review Comment:
   Newly added `tracer` are transient. Should we make it transient here as well?
   
   
https://github.com/apache/beam/pull/40483/changes#diff-89f3e8695375f86f8de56e6244d51187030f9e764072c6de4458744caea0961cR1583



##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubIO.java:
##########
@@ -1573,24 +1575,41 @@ public void set(@Nullable Map<String, String> attr, 
String key, String value) {
         W3CTraceContextPropagator.getInstance().inject(Context.current(), 
attr, inject);
       }
 
+      @Setup
+      public void setup(PipelineOptions po) {
+        tracer = 
po.as(SdkHarnessOptions.class).getOpenTelemetry().getTracer("PubSubIO");
+      }
+
+      private transient @MonotonicNonNull Tracer tracer = null;
+
       @ProcessElement
       public void processElement(
           @Element PubsubMessage message, OutputReceiver<PubsubMessage> 
output) {
-        Map<String, String> attributeMap = message.getAttributeMap();
-        Map<String, String> attr =
-            attributeMap == null ? new HashMap<>() : new 
HashMap<>(attributeMap);
-        injectSpanContext(attr);
-
-        // copy the message, multiple fields
-        PubsubMessage ps =
-            new PubsubMessage(
-                message.getPayload(), attr, message.getMessageId(), 
message.getOrderingKey());
-
-        // topic is copied seperately, not via constructor
-        if (message.getTopic() != null) {
-          ps = ps.withTopic(message.getTopic());
+        Span span =
+            checkArgumentNotNull(tracer)
+                .spanBuilder("PubSubIO.Write")
+                .setSpanKind(SpanKind.PRODUCER)
+                .setParent(Context.current())
+                .startSpan();
+        try (Scope s = span.makeCurrent()) {
+          Map<String, String> attributeMap = message.getAttributeMap();
+          Map<String, String> attr =
+              attributeMap == null ? new HashMap<>() : new 
HashMap<>(attributeMap);
+          injectSpanContext(attr);
+
+          // copy the message, multiple fields
+          PubsubMessage ps =
+              new PubsubMessage(
+                  message.getPayload(), attr, message.getMessageId(), 
message.getOrderingKey());
+
+          // topic is copied seperately, not via constructor

Review Comment:
   typo: separately



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to