google-cloud-document_ai-v1 1.1.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b70f8144f9c98c05827b99942bda8a464e300f9f52ee3ee313f95b4d8d6ad98a
4
- data.tar.gz: 907bec635ca58b464d9125c073b1f30c610d1674d5457f9c19d8fde39d8c1e4f
3
+ metadata.gz: 95e3b111b3b85ac1d382e6552710500818a94dc3cc9e5f7e5727c3bde78e7ddf
4
+ data.tar.gz: c96bb3ac981ed6f2bba567108bd359b4353bcaaad1d9d290acd4f010719b58f3
5
5
  SHA512:
6
- metadata.gz: 954cde78a090b61822b2f0a939f4666aa0f55da4ef456d1b3af168060925ac0821df35fc77d4cb562932668de1969933e3d0c1b5cf9322ba753a8d69e4cb8fb5
7
- data.tar.gz: 88cb76e6701c4014e5cda7558df28e5e9a97e2fb3c10d9a0d3b0b8015a6b8d490fbed2a6ef41d60546e504363b3f5d8999ca59ab78d2df8fc0f7c967b81193a9
6
+ metadata.gz: b19f36cb6a3655f32c3312f69f337baac598185de2fca8c336f81f8cd182d11ed56a4ec0b39cfada8f64c80f8b98dbf77d1d66c21c00130f158caa84b8c331d0
7
+ data.tar.gz: efcf52b2b8ce093713e490998ac704dc87acc56138f6398b847d76e1a37ce9d4d152e20f003d6e66c208cfcbd139e8a83f3e993b4cbdc543da5a0f87143d5515
data/README.md CHANGED
@@ -43,33 +43,43 @@ for class and method documentation.
43
43
  See also the [Product Documentation](https://cloud.google.com/document-ai/docs)
44
44
  for general usage information.
45
45
 
46
- ## Enabling Logging
47
-
48
- To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
49
- The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/current/stdlibs/logger/Logger.html) as shown below,
50
- or a [`Google::Cloud::Logging::Logger`](https://cloud.google.com/ruby/docs/reference/google-cloud-logging/latest)
51
- that will write logs to [Cloud Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
52
- and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
53
-
54
- Configuring a Ruby stdlib logger:
46
+ ## Debug Logging
47
+
48
+ This library comes with opt-in Debug Logging that can help you troubleshoot
49
+ your application's integration with the API. When logging is activated, key
50
+ events such as requests and responses, along with data payloads and metadata
51
+ such as headers and client configuration, are logged to the standard error
52
+ stream.
53
+
54
+ **WARNING:** Client Library Debug Logging includes your data payloads in
55
+ plaintext, which could include sensitive data such as PII for yourself or your
56
+ customers, private keys, or other security data that could be compromising if
57
+ leaked. Always practice good data hygiene with your application logs, and follow
58
+ the principle of least access. Google also recommends that Client Library Debug
59
+ Logging be enabled only temporarily during active debugging, and not used
60
+ permanently in production.
61
+
62
+ To enable logging, set the environment variable `GOOGLE_SDK_RUBY_LOGGING_GEMS`
63
+ to the value `all`. Alternatively, you can set the value to a comma-delimited
64
+ list of client library gem names. This will select the default logging behavior,
65
+ which writes logs to the standard error stream. On a local workstation, this may
66
+ result in logs appearing on the console. When running on a Google Cloud hosting
67
+ service such as [Google Cloud Run](https://cloud.google.com/run), this generally
68
+ results in logs appearing alongside your application logs in the
69
+ [Google Cloud Logging](https://cloud.google.com/logging/) service.
70
+
71
+ You can customize logging by modifying the `logger` configuration when
72
+ constructing a client object. For example:
55
73
 
56
74
  ```ruby
75
+ require "google/cloud/document_ai/v1"
57
76
  require "logger"
58
77
 
59
- module MyLogger
60
- LOGGER = Logger.new $stderr, level: Logger::WARN
61
- def logger
62
- LOGGER
63
- end
64
- end
65
-
66
- # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
67
- module GRPC
68
- extend MyLogger
78
+ client = ::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new do |config|
79
+ config.logger = Logger.new "my-app.log"
69
80
  end
70
81
  ```
71
82
 
72
-
73
83
  ## Google Cloud Samples
74
84
 
75
85
  To browse ready to use code samples check [Google Cloud Samples](https://cloud.google.com/docs/samples).
@@ -76,17 +76,17 @@ module Google
76
76
 
77
77
  default_config.rpcs.process_document.timeout = 300.0
78
78
  default_config.rpcs.process_document.retry_policy = {
79
- initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
79
+ initial_delay: 1.0, max_delay: 90.0, multiplier: 9.0, retry_codes: [4, 14, 8]
80
80
  }
81
81
 
82
82
  default_config.rpcs.batch_process_documents.timeout = 120.0
83
83
  default_config.rpcs.batch_process_documents.retry_policy = {
84
- initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
84
+ initial_delay: 1.0, max_delay: 60.0, multiplier: 1.5, retry_codes: [4, 14]
85
85
  }
86
86
 
87
87
  default_config.rpcs.review_document.timeout = 120.0
88
88
  default_config.rpcs.review_document.retry_policy = {
89
- initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
89
+ initial_delay: 1.0, max_delay: 60.0, multiplier: 1.5, retry_codes: [4, 14]
90
90
  }
91
91
 
92
92
  default_config
@@ -183,14 +183,26 @@ module Google
183
183
  universe_domain: @config.universe_domain,
184
184
  channel_args: @config.channel_args,
185
185
  interceptors: @config.interceptors,
186
- channel_pool_config: @config.channel_pool
186
+ channel_pool_config: @config.channel_pool,
187
+ logger: @config.logger
187
188
  )
188
189
 
190
+ @document_processor_service_stub.stub_logger&.info do |entry|
191
+ entry.set_system_name
192
+ entry.set_service
193
+ entry.message = "Created client for #{entry.service}"
194
+ entry.set_credentials_fields credentials
195
+ entry.set "customEndpoint", @config.endpoint if @config.endpoint
196
+ entry.set "defaultTimeout", @config.timeout if @config.timeout
197
+ entry.set "quotaProject", @quota_project_id if @quota_project_id
198
+ end
199
+
189
200
  @location_client = Google::Cloud::Location::Locations::Client.new do |config|
190
201
  config.credentials = credentials
191
202
  config.quota_project = @quota_project_id
192
203
  config.endpoint = @document_processor_service_stub.endpoint
193
204
  config.universe_domain = @document_processor_service_stub.universe_domain
205
+ config.logger = @document_processor_service_stub.logger if config.respond_to? :logger=
194
206
  end
195
207
  end
196
208
 
@@ -208,6 +220,15 @@ module Google
208
220
  #
209
221
  attr_reader :location_client
210
222
 
223
+ ##
224
+ # The logger used for request/response debug logging.
225
+ #
226
+ # @return [Logger]
227
+ #
228
+ def logger
229
+ @document_processor_service_stub.logger
230
+ end
231
+
211
232
  # Service calls
212
233
 
213
234
  ##
@@ -324,7 +345,6 @@ module Google
324
345
 
325
346
  @document_processor_service_stub.call_rpc :process_document, request, options: options do |response, operation|
326
347
  yield response, operation if block_given?
327
- return response
328
348
  end
329
349
  rescue ::GRPC::BadStatus => e
330
350
  raise ::Google::Cloud::Error.from_error(e)
@@ -444,7 +464,7 @@ module Google
444
464
  @document_processor_service_stub.call_rpc :batch_process_documents, request, options: options do |response, operation|
445
465
  response = ::Gapic::Operation.new response, @operations_client, options: options
446
466
  yield response, operation if block_given?
447
- return response
467
+ throw :response, response
448
468
  end
449
469
  rescue ::GRPC::BadStatus => e
450
470
  raise ::Google::Cloud::Error.from_error(e)
@@ -533,7 +553,6 @@ module Google
533
553
 
534
554
  @document_processor_service_stub.call_rpc :fetch_processor_types, request, options: options do |response, operation|
535
555
  yield response, operation if block_given?
536
- return response
537
556
  end
538
557
  rescue ::GRPC::BadStatus => e
539
558
  raise ::Google::Cloud::Error.from_error(e)
@@ -631,7 +650,7 @@ module Google
631
650
  @document_processor_service_stub.call_rpc :list_processor_types, request, options: options do |response, operation|
632
651
  response = ::Gapic::PagedEnumerable.new @document_processor_service_stub, :list_processor_types, request, response, operation, options
633
652
  yield response, operation if block_given?
634
- return response
653
+ throw :response, response
635
654
  end
636
655
  rescue ::GRPC::BadStatus => e
637
656
  raise ::Google::Cloud::Error.from_error(e)
@@ -717,7 +736,6 @@ module Google
717
736
 
718
737
  @document_processor_service_stub.call_rpc :get_processor_type, request, options: options do |response, operation|
719
738
  yield response, operation if block_given?
720
- return response
721
739
  end
722
740
  rescue ::GRPC::BadStatus => e
723
741
  raise ::Google::Cloud::Error.from_error(e)
@@ -816,7 +834,7 @@ module Google
816
834
  @document_processor_service_stub.call_rpc :list_processors, request, options: options do |response, operation|
817
835
  response = ::Gapic::PagedEnumerable.new @document_processor_service_stub, :list_processors, request, response, operation, options
818
836
  yield response, operation if block_given?
819
- return response
837
+ throw :response, response
820
838
  end
821
839
  rescue ::GRPC::BadStatus => e
822
840
  raise ::Google::Cloud::Error.from_error(e)
@@ -902,7 +920,6 @@ module Google
902
920
 
903
921
  @document_processor_service_stub.call_rpc :get_processor, request, options: options do |response, operation|
904
922
  yield response, operation if block_given?
905
- return response
906
923
  end
907
924
  rescue ::GRPC::BadStatus => e
908
925
  raise ::Google::Cloud::Error.from_error(e)
@@ -1015,7 +1032,7 @@ module Google
1015
1032
  @document_processor_service_stub.call_rpc :train_processor_version, request, options: options do |response, operation|
1016
1033
  response = ::Gapic::Operation.new response, @operations_client, options: options
1017
1034
  yield response, operation if block_given?
1018
- return response
1035
+ throw :response, response
1019
1036
  end
1020
1037
  rescue ::GRPC::BadStatus => e
1021
1038
  raise ::Google::Cloud::Error.from_error(e)
@@ -1101,7 +1118,6 @@ module Google
1101
1118
 
1102
1119
  @document_processor_service_stub.call_rpc :get_processor_version, request, options: options do |response, operation|
1103
1120
  yield response, operation if block_given?
1104
- return response
1105
1121
  end
1106
1122
  rescue ::GRPC::BadStatus => e
1107
1123
  raise ::Google::Cloud::Error.from_error(e)
@@ -1201,7 +1217,7 @@ module Google
1201
1217
  @document_processor_service_stub.call_rpc :list_processor_versions, request, options: options do |response, operation|
1202
1218
  response = ::Gapic::PagedEnumerable.new @document_processor_service_stub, :list_processor_versions, request, response, operation, options
1203
1219
  yield response, operation if block_given?
1204
- return response
1220
+ throw :response, response
1205
1221
  end
1206
1222
  rescue ::GRPC::BadStatus => e
1207
1223
  raise ::Google::Cloud::Error.from_error(e)
@@ -1296,7 +1312,7 @@ module Google
1296
1312
  @document_processor_service_stub.call_rpc :delete_processor_version, request, options: options do |response, operation|
1297
1313
  response = ::Gapic::Operation.new response, @operations_client, options: options
1298
1314
  yield response, operation if block_given?
1299
- return response
1315
+ throw :response, response
1300
1316
  end
1301
1317
  rescue ::GRPC::BadStatus => e
1302
1318
  raise ::Google::Cloud::Error.from_error(e)
@@ -1390,7 +1406,7 @@ module Google
1390
1406
  @document_processor_service_stub.call_rpc :deploy_processor_version, request, options: options do |response, operation|
1391
1407
  response = ::Gapic::Operation.new response, @operations_client, options: options
1392
1408
  yield response, operation if block_given?
1393
- return response
1409
+ throw :response, response
1394
1410
  end
1395
1411
  rescue ::GRPC::BadStatus => e
1396
1412
  raise ::Google::Cloud::Error.from_error(e)
@@ -1484,7 +1500,7 @@ module Google
1484
1500
  @document_processor_service_stub.call_rpc :undeploy_processor_version, request, options: options do |response, operation|
1485
1501
  response = ::Gapic::Operation.new response, @operations_client, options: options
1486
1502
  yield response, operation if block_given?
1487
- return response
1503
+ throw :response, response
1488
1504
  end
1489
1505
  rescue ::GRPC::BadStatus => e
1490
1506
  raise ::Google::Cloud::Error.from_error(e)
@@ -1584,7 +1600,6 @@ module Google
1584
1600
 
1585
1601
  @document_processor_service_stub.call_rpc :create_processor, request, options: options do |response, operation|
1586
1602
  yield response, operation if block_given?
1587
- return response
1588
1603
  end
1589
1604
  rescue ::GRPC::BadStatus => e
1590
1605
  raise ::Google::Cloud::Error.from_error(e)
@@ -1679,7 +1694,7 @@ module Google
1679
1694
  @document_processor_service_stub.call_rpc :delete_processor, request, options: options do |response, operation|
1680
1695
  response = ::Gapic::Operation.new response, @operations_client, options: options
1681
1696
  yield response, operation if block_given?
1682
- return response
1697
+ throw :response, response
1683
1698
  end
1684
1699
  rescue ::GRPC::BadStatus => e
1685
1700
  raise ::Google::Cloud::Error.from_error(e)
@@ -1773,7 +1788,7 @@ module Google
1773
1788
  @document_processor_service_stub.call_rpc :enable_processor, request, options: options do |response, operation|
1774
1789
  response = ::Gapic::Operation.new response, @operations_client, options: options
1775
1790
  yield response, operation if block_given?
1776
- return response
1791
+ throw :response, response
1777
1792
  end
1778
1793
  rescue ::GRPC::BadStatus => e
1779
1794
  raise ::Google::Cloud::Error.from_error(e)
@@ -1867,7 +1882,7 @@ module Google
1867
1882
  @document_processor_service_stub.call_rpc :disable_processor, request, options: options do |response, operation|
1868
1883
  response = ::Gapic::Operation.new response, @operations_client, options: options
1869
1884
  yield response, operation if block_given?
1870
- return response
1885
+ throw :response, response
1871
1886
  end
1872
1887
  rescue ::GRPC::BadStatus => e
1873
1888
  raise ::Google::Cloud::Error.from_error(e)
@@ -1972,7 +1987,7 @@ module Google
1972
1987
  @document_processor_service_stub.call_rpc :set_default_processor_version, request, options: options do |response, operation|
1973
1988
  response = ::Gapic::Operation.new response, @operations_client, options: options
1974
1989
  yield response, operation if block_given?
1975
- return response
1990
+ throw :response, response
1976
1991
  end
1977
1992
  rescue ::GRPC::BadStatus => e
1978
1993
  raise ::Google::Cloud::Error.from_error(e)
@@ -2077,7 +2092,7 @@ module Google
2077
2092
  @document_processor_service_stub.call_rpc :review_document, request, options: options do |response, operation|
2078
2093
  response = ::Gapic::Operation.new response, @operations_client, options: options
2079
2094
  yield response, operation if block_given?
2080
- return response
2095
+ throw :response, response
2081
2096
  end
2082
2097
  rescue ::GRPC::BadStatus => e
2083
2098
  raise ::Google::Cloud::Error.from_error(e)
@@ -2178,7 +2193,7 @@ module Google
2178
2193
  @document_processor_service_stub.call_rpc :evaluate_processor_version, request, options: options do |response, operation|
2179
2194
  response = ::Gapic::Operation.new response, @operations_client, options: options
2180
2195
  yield response, operation if block_given?
2181
- return response
2196
+ throw :response, response
2182
2197
  end
2183
2198
  rescue ::GRPC::BadStatus => e
2184
2199
  raise ::Google::Cloud::Error.from_error(e)
@@ -2266,7 +2281,6 @@ module Google
2266
2281
 
2267
2282
  @document_processor_service_stub.call_rpc :get_evaluation, request, options: options do |response, operation|
2268
2283
  yield response, operation if block_given?
2269
- return response
2270
2284
  end
2271
2285
  rescue ::GRPC::BadStatus => e
2272
2286
  raise ::Google::Cloud::Error.from_error(e)
@@ -2367,7 +2381,7 @@ module Google
2367
2381
  @document_processor_service_stub.call_rpc :list_evaluations, request, options: options do |response, operation|
2368
2382
  response = ::Gapic::PagedEnumerable.new @document_processor_service_stub, :list_evaluations, request, response, operation, options
2369
2383
  yield response, operation if block_given?
2370
- return response
2384
+ throw :response, response
2371
2385
  end
2372
2386
  rescue ::GRPC::BadStatus => e
2373
2387
  raise ::Google::Cloud::Error.from_error(e)
@@ -2456,6 +2470,11 @@ module Google
2456
2470
  # default endpoint URL. The default value of nil uses the environment
2457
2471
  # universe (usually the default "googleapis.com" universe).
2458
2472
  # @return [::String,nil]
2473
+ # @!attribute [rw] logger
2474
+ # A custom logger to use for request/response debug logging, or the value
2475
+ # `:default` (the default) to construct a default logger, or `nil` to
2476
+ # explicitly disable logging.
2477
+ # @return [::Logger,:default,nil]
2459
2478
  #
2460
2479
  class Configuration
2461
2480
  extend ::Gapic::Config
@@ -2480,6 +2499,7 @@ module Google
2480
2499
  config_attr :retry_policy, nil, ::Hash, ::Proc, nil
2481
2500
  config_attr :quota_project, nil, ::String, nil
2482
2501
  config_attr :universe_domain, nil, ::String, nil
2502
+ config_attr :logger, :default, ::Logger, nil, :default
2483
2503
 
2484
2504
  # @private
2485
2505
  def initialize parent_config = nil
@@ -124,14 +124,6 @@ module Google
124
124
  # Lists operations that match the specified filter in the request. If the
125
125
  # server doesn't support this method, it returns `UNIMPLEMENTED`.
126
126
  #
127
- # NOTE: the `name` binding allows API services to override the binding
128
- # to use different resource name schemes, such as `users/*/operations`. To
129
- # override the binding, API services can add a binding such as
130
- # `"/v1/{name=users/*}/operations"` to their service configuration.
131
- # For backwards compatibility, the default name includes the operations
132
- # collection id, however overriding users must ensure the name binding
133
- # is the parent resource, without the operations collection id.
134
- #
135
127
  # @overload list_operations(request, options = nil)
136
128
  # Pass arguments to `list_operations` via a request object, either of type
137
129
  # {::Google::Longrunning::ListOperationsRequest} or an equivalent Hash.
@@ -221,7 +213,7 @@ module Google
221
213
  wrap_lro_operation = ->(op_response) { ::Gapic::Operation.new op_response, @operations_client }
222
214
  response = ::Gapic::PagedEnumerable.new @operations_stub, :list_operations, request, response, operation, options, format_resource: wrap_lro_operation
223
215
  yield response, operation if block_given?
224
- return response
216
+ throw :response, response
225
217
  end
226
218
  rescue ::GRPC::BadStatus => e
227
219
  raise ::Google::Cloud::Error.from_error(e)
@@ -317,7 +309,7 @@ module Google
317
309
  @operations_stub.call_rpc :get_operation, request, options: options do |response, operation|
318
310
  response = ::Gapic::Operation.new response, @operations_client, options: options
319
311
  yield response, operation if block_given?
320
- return response
312
+ throw :response, response
321
313
  end
322
314
  rescue ::GRPC::BadStatus => e
323
315
  raise ::Google::Cloud::Error.from_error(e)
@@ -406,7 +398,6 @@ module Google
406
398
 
407
399
  @operations_stub.call_rpc :delete_operation, request, options: options do |response, operation|
408
400
  yield response, operation if block_given?
409
- return response
410
401
  end
411
402
  rescue ::GRPC::BadStatus => e
412
403
  raise ::Google::Cloud::Error.from_error(e)
@@ -421,8 +412,9 @@ module Google
421
412
  # other methods to check whether the cancellation succeeded or whether the
422
413
  # operation completed despite cancellation. On successful cancellation,
423
414
  # the operation is not deleted; instead, it becomes an operation with
424
- # an {::Google::Longrunning::Operation#error Operation.error} value with a {::Google::Rpc::Status#code google.rpc.Status.code} of 1,
425
- # corresponding to `Code.CANCELLED`.
415
+ # an {::Google::Longrunning::Operation#error Operation.error} value with a
416
+ # {::Google::Rpc::Status#code google.rpc.Status.code} of `1`, corresponding to
417
+ # `Code.CANCELLED`.
426
418
  #
427
419
  # @overload cancel_operation(request, options = nil)
428
420
  # Pass arguments to `cancel_operation` via a request object, either of type
@@ -501,7 +493,6 @@ module Google
501
493
 
502
494
  @operations_stub.call_rpc :cancel_operation, request, options: options do |response, operation|
503
495
  yield response, operation if block_given?
504
- return response
505
496
  end
506
497
  rescue ::GRPC::BadStatus => e
507
498
  raise ::Google::Cloud::Error.from_error(e)
@@ -599,7 +590,7 @@ module Google
599
590
  @operations_stub.call_rpc :wait_operation, request, options: options do |response, operation|
600
591
  response = ::Gapic::Operation.new response, @operations_client, options: options
601
592
  yield response, operation if block_given?
602
- return response
593
+ throw :response, response
603
594
  end
604
595
  rescue ::GRPC::BadStatus => e
605
596
  raise ::Google::Cloud::Error.from_error(e)
@@ -688,6 +679,11 @@ module Google
688
679
  # default endpoint URL. The default value of nil uses the environment
689
680
  # universe (usually the default "googleapis.com" universe).
690
681
  # @return [::String,nil]
682
+ # @!attribute [rw] logger
683
+ # A custom logger to use for request/response debug logging, or the value
684
+ # `:default` (the default) to construct a default logger, or `nil` to
685
+ # explicitly disable logging.
686
+ # @return [::Logger,:default,nil]
691
687
  #
692
688
  class Configuration
693
689
  extend ::Gapic::Config
@@ -712,6 +708,7 @@ module Google
712
708
  config_attr :retry_policy, nil, ::Hash, ::Proc, nil
713
709
  config_attr :quota_project, nil, ::String, nil
714
710
  config_attr :universe_domain, nil, ::String, nil
711
+ config_attr :logger, :default, ::Logger, nil, :default
715
712
 
716
713
  # @private
717
714
  def initialize parent_config = nil