You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "cozos (via GitHub)" <gi...@apache.org> on 2023/02/21 08:47:18 UTC

[GitHub] [beam] cozos opened a new issue, #25573: [Bug]: Fn Logging doesn't work in ParDo#with_exception_handling(use_subprocess=True)

cozos opened a new issue, #25573:
URL: https://github.com/apache/beam/issues/25573

   ### What happened?
   
   In the Python SDK, logging (via Fn Logging API) doesn't work when running a ParDo in a subprocess with `ParDo#with_exception_handling(use_subprocess=True)`. This is because the Fn Log API gRPC channel breaks when the DoFn gets pickled and sent to the subprocess.  
   
   Logging doesn't work here:
   ```py
   import logging
   
   logging.basicConfig(level=logging.INFO)
   
   class MyDoFn(beam.DoFn):
           def process(self, element):
               logging.getLogger().info(element)
   ```
   
   But if I reestablish the Fn Log API gRPC channel, it works:
   
   ```py
   import logging
   
   logging.basicConfig(level=logging.INFO)
   
   class MyDoFn(beam.DoFn):
       def setup(self):
           import os
           from apache_beam.portability.api import endpoints_pb2
           from google.protobuf import text_format
   
           # Copied from https://github.com/apache/beam/blob/master/sdks/python/apache_beam/runners/worker/sdk_worker_main.py#L82-L83
           if "LOGGING_API_SERVICE_DESCRIPTOR" in os.environ:
               logging_service_descriptor = endpoints_pb2.ApiServiceDescriptor()
               text_format.Merge(
                   os.environ["LOGGING_API_SERVICE_DESCRIPTOR"], logging_service_descriptor
               )
   
               fn_log_handler = FnApiLogRecordHandler(logging_service_descriptor)
               logging.getLogger().setLevel(logging.INFO)
               logging.getLogger().addHandler(fn_log_handler)
       
       def process(self, element):
               logging.info(element)
   ```
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [X] Component: Python SDK
   - [ ] Component: Java SDK
   - [ ] Component: Go SDK
   - [ ] Component: Typescript SDK
   - [ ] Component: IO connector
   - [ ] Component: Beam examples
   - [ ] Component: Beam playground
   - [ ] Component: Beam katas
   - [ ] Component: Website
   - [ ] Component: Spark Runner
   - [ ] Component: Flink Runner
   - [ ] Component: Samza Runner
   - [ ] Component: Twister2 Runner
   - [ ] Component: Hazelcast Jet Runner
   - [ ] Component: Google Cloud Dataflow Runner


-- 
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: github-unsubscribe@beam.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org