google-cloud-logging 3.10.0__tar.gz → 3.11.1__tar.gz
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.
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/MANIFEST.in +1 -1
- {google-cloud-logging-3.10.0/google_cloud_logging.egg-info → google_cloud_logging-3.11.1}/PKG-INFO +3 -2
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging/gapic_version.py +1 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/__init__.py +1 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/_gapic.py +1 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/_http.py +1 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/gapic_version.py +1 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/_helpers.py +56 -6
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/_monitored_resources.py +70 -2
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/handlers.py +19 -16
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/transports/sync.py +1 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/logger.py +2 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/config_service_v2/async_client.py +276 -309
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/config_service_v2/client.py +130 -170
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/config_service_v2/pagers.py +143 -10
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/config_service_v2/transports/base.py +3 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py +17 -11
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py +260 -11
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/logging_service_v2/async_client.py +64 -113
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/logging_service_v2/client.py +45 -34
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/logging_service_v2/pagers.py +91 -6
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/logging_service_v2/transports/base.py +3 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py +17 -11
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py +119 -11
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +59 -88
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/metrics_service_v2/client.py +43 -36
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/metrics_service_v2/pagers.py +39 -2
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py +3 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py +17 -11
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py +92 -11
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1/google_cloud_logging.egg-info}/PKG-INFO +3 -2
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google_cloud_logging.egg-info/requires.txt +2 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/setup.py +2 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/system/test_system.py +58 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/gapic/logging_v2/test_config_service_v2.py +4547 -176
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/gapic/logging_v2/test_logging_service_v2.py +787 -20
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +715 -14
- google_cloud_logging-3.11.1/tests/unit/handlers/__init__.py +54 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/handlers/test__helpers.py +143 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/handlers/test__monitored_resources.py +47 -14
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/handlers/test_app_engine.py +1 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/handlers/test_handlers.py +138 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/handlers/test_structured_log.py +102 -1
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test__instrumentation.py +7 -7
- google-cloud-logging-3.10.0/tests/unit/handlers/transports/__init__.py +0 -13
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/LICENSE +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/README.rst +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging/handlers/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging/handlers/middleware/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging/handlers/transports/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging/py.typed +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/_helpers.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/_instrumentation.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/client.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/entries.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/gapic_metadata.json +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/app_engine.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/container_engine.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/middleware/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/middleware/request.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/structured_log.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/transports/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/transports/background_thread.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/handlers/transports/base.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/metric.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/py.typed +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/resource.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/config_service_v2/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/config_service_v2/transports/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/logging_service_v2/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/logging_service_v2/transports/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/metrics_service_v2/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/services/metrics_service_v2/transports/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/sink.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/types/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/types/log_entry.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/types/logging.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/types/logging_config.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/types/logging_metrics.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google_cloud_logging.egg-info/SOURCES.txt +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google_cloud_logging.egg-info/dependency_links.txt +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google_cloud_logging.egg-info/not-zip-safe +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google_cloud_logging.egg-info/top_level.txt +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/setup.cfg +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/performance/noxfile.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/performance/test_performance.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/system/gapic/v2/test_system_logging_service_v2_v2.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/gapic/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/gapic/logging_v2/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/handlers/middleware/test_request.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/handlers/test_container_engine.py +0 -0
- {google-cloud-logging-3.10.0/tests/unit/handlers → google_cloud_logging-3.11.1/tests/unit/handlers/transports}/__init__.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/handlers/transports/test_background_thread.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/handlers/transports/test_base.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/handlers/transports/test_sync.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test__gapic.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test__helpers.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test__http.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test_client.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test_entries.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test_logger.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test_logging_shim.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test_metric.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test_packaging.py +0 -0
- {google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/tests/unit/test_sink.py +0 -0
{google-cloud-logging-3.10.0/google_cloud_logging.egg-info → google_cloud_logging-3.11.1}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: google-cloud-logging
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.11.1
|
|
4
4
|
Summary: Stackdriver Logging API client library
|
|
5
5
|
Home-page: https://github.com/googleapis/python-logging
|
|
6
6
|
Author: Google LLC
|
|
@@ -28,9 +28,10 @@ Requires-Dist: google-cloud-appengine-logging<2.0.0dev,>=0.1.0
|
|
|
28
28
|
Requires-Dist: google-cloud-audit-log<1.0.0dev,>=0.1.0
|
|
29
29
|
Requires-Dist: google-cloud-core<3.0.0dev,>=2.0.0
|
|
30
30
|
Requires-Dist: grpc-google-iam-v1<1.0.0dev,>=0.12.4
|
|
31
|
+
Requires-Dist: opentelemetry-api>=1.0.0
|
|
31
32
|
Requires-Dist: proto-plus<2.0.0dev,>=1.22.0
|
|
32
33
|
Requires-Dist: proto-plus<2.0.0dev,>=1.22.2; python_version >= "3.11"
|
|
33
|
-
Requires-Dist: protobuf!=
|
|
34
|
+
Requires-Dist: protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<6.0.0dev,>=3.20.2
|
|
34
35
|
|
|
35
36
|
Python Client for Cloud Logging
|
|
36
37
|
=====================================
|
{google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/__init__.py
RENAMED
|
@@ -36,7 +36,7 @@ from google.cloud.logging_v2 import types
|
|
|
36
36
|
ASCENDING = "timestamp asc"
|
|
37
37
|
"""Query string to order by ascending timestamps."""
|
|
38
38
|
DESCENDING = "timestamp desc"
|
|
39
|
-
"""Query string to order by
|
|
39
|
+
"""Query string to order by descending timestamps."""
|
|
40
40
|
_instrumentation_emitted = False
|
|
41
41
|
"""Flag for whether instrumentation info has been emitted"""
|
|
42
42
|
|
{google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/_gapic.py
RENAMED
|
@@ -331,7 +331,7 @@ class _SinksAPI(object):
|
|
|
331
331
|
dict: The sink resource returned from the API (converted from a
|
|
332
332
|
protobuf to a dictionary).
|
|
333
333
|
"""
|
|
334
|
-
name = sink_name.split("/")[-1] # parse name out of full
|
|
334
|
+
name = sink_name.split("/")[-1] # parse name out of full resource name
|
|
335
335
|
sink_pb = LogSink(
|
|
336
336
|
name=name,
|
|
337
337
|
filter=filter_,
|
{google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/_http.py
RENAMED
|
@@ -347,7 +347,7 @@ class _SinksAPI(object):
|
|
|
347
347
|
dict: The returned (updated) resource.
|
|
348
348
|
"""
|
|
349
349
|
target = f"/{sink_name}"
|
|
350
|
-
name = sink_name.split("/")[-1] # parse name out of full
|
|
350
|
+
name = sink_name.split("/")[-1] # parse name out of full resource name
|
|
351
351
|
data = {"name": name, "filter": filter_, "destination": destination}
|
|
352
352
|
query_params = {"uniqueWriterIdentity": unique_writer_identity}
|
|
353
353
|
return self.api_request(
|
|
@@ -24,6 +24,8 @@ try:
|
|
|
24
24
|
except ImportError: # pragma: NO COVER
|
|
25
25
|
flask = None
|
|
26
26
|
|
|
27
|
+
import opentelemetry.trace
|
|
28
|
+
|
|
27
29
|
from google.cloud.logging_v2.handlers.middleware.request import _get_django_request
|
|
28
30
|
|
|
29
31
|
_DJANGO_CONTENT_LENGTH = "CONTENT_LENGTH"
|
|
@@ -191,23 +193,71 @@ def _parse_xcloud_trace(header):
|
|
|
191
193
|
return trace_id, span_id, trace_sampled
|
|
192
194
|
|
|
193
195
|
|
|
196
|
+
def _retrieve_current_open_telemetry_span():
|
|
197
|
+
"""Helper to retrieve trace, span ID, and trace sampled information from the current
|
|
198
|
+
OpenTelemetry span.
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
Tuple[Optional[str], Optional[str], bool]:
|
|
202
|
+
Data related to the current trace_id, span_id, and trace_sampled for the
|
|
203
|
+
current OpenTelemetry span. If a span is not found, return None/False for all
|
|
204
|
+
fields.
|
|
205
|
+
"""
|
|
206
|
+
span = opentelemetry.trace.get_current_span()
|
|
207
|
+
if span != opentelemetry.trace.span.INVALID_SPAN:
|
|
208
|
+
context = span.get_span_context()
|
|
209
|
+
trace_id = opentelemetry.trace.format_trace_id(context.trace_id)
|
|
210
|
+
span_id = opentelemetry.trace.format_span_id(context.span_id)
|
|
211
|
+
trace_sampled = context.trace_flags.sampled
|
|
212
|
+
|
|
213
|
+
return trace_id, span_id, trace_sampled
|
|
214
|
+
|
|
215
|
+
return None, None, False
|
|
216
|
+
|
|
217
|
+
|
|
194
218
|
def get_request_data():
|
|
195
219
|
"""Helper to get http_request and trace data from supported web
|
|
196
|
-
frameworks (currently supported: Flask and Django).
|
|
220
|
+
frameworks (currently supported: Flask and Django), as well as OpenTelemetry. Attempts
|
|
221
|
+
to retrieve trace/spanID from OpenTelemetry first, before going to Traceparent then XCTC.
|
|
222
|
+
HTTP request data is taken from a supporting web framework (currently Flask or Django).
|
|
223
|
+
Because HTTP request data is decoupled from OpenTelemetry, it is possible to get as a
|
|
224
|
+
return value the HTTP request from the web framework of choice, and trace/span data from
|
|
225
|
+
OpenTelemetry, even if trace data is present in the HTTP request headers.
|
|
197
226
|
|
|
198
227
|
Returns:
|
|
199
228
|
Tuple[Optional[dict], Optional[str], Optional[str], bool]:
|
|
200
229
|
Data related to the current http request, trace_id, span_id, and trace_sampled
|
|
201
230
|
for the request. All fields will be None if a http request isn't found.
|
|
202
231
|
"""
|
|
232
|
+
|
|
233
|
+
(
|
|
234
|
+
otel_trace_id,
|
|
235
|
+
otel_span_id,
|
|
236
|
+
otel_trace_sampled,
|
|
237
|
+
) = _retrieve_current_open_telemetry_span()
|
|
238
|
+
|
|
239
|
+
# Get HTTP request data
|
|
203
240
|
checkers = (
|
|
204
241
|
get_request_data_from_django,
|
|
205
242
|
get_request_data_from_flask,
|
|
206
243
|
)
|
|
207
244
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
245
|
+
http_request, http_trace_id, http_span_id, http_trace_sampled = (
|
|
246
|
+
None,
|
|
247
|
+
None,
|
|
248
|
+
None,
|
|
249
|
+
False,
|
|
250
|
+
)
|
|
212
251
|
|
|
213
|
-
|
|
252
|
+
for checker in checkers:
|
|
253
|
+
http_request, http_trace_id, http_span_id, http_trace_sampled = checker()
|
|
254
|
+
if http_request is None:
|
|
255
|
+
http_trace_id, http_span_id, http_trace_sampled = None, None, False
|
|
256
|
+
else:
|
|
257
|
+
break
|
|
258
|
+
|
|
259
|
+
# otel_trace_id existing means the other return values are non-null
|
|
260
|
+
if otel_trace_id:
|
|
261
|
+
return http_request, otel_trace_id, otel_span_id, otel_trace_sampled
|
|
262
|
+
else:
|
|
263
|
+
return http_request, http_trace_id, http_span_id, http_trace_sampled
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
import functools
|
|
16
|
+
import logging
|
|
15
17
|
import os
|
|
16
18
|
|
|
17
19
|
from google.cloud.logging_v2.resource import Resource
|
|
@@ -67,6 +69,20 @@ _GKE_CLUSTER_LOCATION = "instance/attributes/cluster-location"
|
|
|
67
69
|
_PROJECT_NAME = "project/project-id"
|
|
68
70
|
"""Attribute in metadata server when in GKE environment."""
|
|
69
71
|
|
|
72
|
+
_GAE_RESOURCE_TYPE = "gae_app"
|
|
73
|
+
"""Resource type for App Engine environment."""
|
|
74
|
+
|
|
75
|
+
_CLOUD_RUN_JOB_RESOURCE_TYPE = "cloud_run_job"
|
|
76
|
+
"""Resource type for Cloud Run Jobs."""
|
|
77
|
+
|
|
78
|
+
_GAE_TRACE_ID_LABEL = "appengine.googleapis.com/trace_id"
|
|
79
|
+
"""Extra trace label to be added on App Engine environments"""
|
|
80
|
+
|
|
81
|
+
_CLOUD_RUN_JOBS_EXECUTION_NAME_LABEL = "run.googleapis.com/execution_name"
|
|
82
|
+
_CLOUD_RUN_JOBS_TASK_INDEX_LABEL = "run.googleapis.com/task_index"
|
|
83
|
+
_CLOUD_RUN_JOBS_TASK_ATTEMPT_LABEL = "run.googleapis.com/task_attempt"
|
|
84
|
+
"""Extra labels for Cloud Run environments to be recognized by Cloud Run Jobs web UI."""
|
|
85
|
+
|
|
70
86
|
|
|
71
87
|
def _create_functions_resource():
|
|
72
88
|
"""Create a standardized Cloud Functions resource.
|
|
@@ -159,7 +175,7 @@ def _create_cloud_run_job_resource():
|
|
|
159
175
|
region = retrieve_metadata_server(_REGION_ID)
|
|
160
176
|
project = retrieve_metadata_server(_PROJECT_NAME)
|
|
161
177
|
resource = Resource(
|
|
162
|
-
type=
|
|
178
|
+
type=_CLOUD_RUN_JOB_RESOURCE_TYPE,
|
|
163
179
|
labels={
|
|
164
180
|
"project_id": project if project else "",
|
|
165
181
|
"job_name": os.environ.get(_CLOUD_RUN_JOB_ID, ""),
|
|
@@ -177,7 +193,7 @@ def _create_app_engine_resource():
|
|
|
177
193
|
zone = retrieve_metadata_server(_ZONE_ID)
|
|
178
194
|
project = retrieve_metadata_server(_PROJECT_NAME)
|
|
179
195
|
resource = Resource(
|
|
180
|
-
type=
|
|
196
|
+
type=_GAE_RESOURCE_TYPE,
|
|
181
197
|
labels={
|
|
182
198
|
"project_id": project if project else "",
|
|
183
199
|
"module_id": os.environ.get(_GAE_SERVICE_ENV, ""),
|
|
@@ -233,3 +249,55 @@ def detect_resource(project=""):
|
|
|
233
249
|
else:
|
|
234
250
|
# use generic global resource
|
|
235
251
|
return _create_global_resource(project)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@functools.lru_cache(maxsize=None)
|
|
255
|
+
def _get_environmental_labels(resource_type):
|
|
256
|
+
"""Builds a dictionary of labels to be inserted into a LogRecord of the given resource type.
|
|
257
|
+
This function should only build a dict of items that are consistent across multiple logging statements
|
|
258
|
+
of the same resource type, such as environment variables. Th
|
|
259
|
+
|
|
260
|
+
Returns:
|
|
261
|
+
dict:
|
|
262
|
+
A dict representation of labels and the values of those labels
|
|
263
|
+
"""
|
|
264
|
+
labels = {}
|
|
265
|
+
environ_vars = {
|
|
266
|
+
_CLOUD_RUN_JOB_RESOURCE_TYPE: {
|
|
267
|
+
_CLOUD_RUN_JOBS_EXECUTION_NAME_LABEL: _CLOUD_RUN_EXECUTION_ID,
|
|
268
|
+
_CLOUD_RUN_JOBS_TASK_INDEX_LABEL: _CLOUD_RUN_TASK_INDEX,
|
|
269
|
+
_CLOUD_RUN_JOBS_TASK_ATTEMPT_LABEL: _CLOUD_RUN_TASK_ATTEMPT,
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if resource_type in environ_vars:
|
|
274
|
+
for key, env_var in environ_vars[resource_type].items():
|
|
275
|
+
val = os.environ.get(env_var, "")
|
|
276
|
+
if val:
|
|
277
|
+
labels[key] = val
|
|
278
|
+
|
|
279
|
+
return labels
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def add_resource_labels(resource: Resource, record: logging.LogRecord):
|
|
283
|
+
"""Returns additional labels to be appended on to a LogRecord object based on the
|
|
284
|
+
local environment. Defaults to an empty dictionary if none apply. This is only to be
|
|
285
|
+
used for CloudLoggingHandler, as the structured logging daemon already does this.
|
|
286
|
+
|
|
287
|
+
Args:
|
|
288
|
+
resource (google.cloud.logging.Resource): Resource based on the environment
|
|
289
|
+
record (logging.LogRecord): A LogRecord object representing a log record
|
|
290
|
+
Returns:
|
|
291
|
+
Dict[str, str]: New labels to append to the labels of the LogRecord
|
|
292
|
+
"""
|
|
293
|
+
if not resource:
|
|
294
|
+
return None
|
|
295
|
+
|
|
296
|
+
# Get environmental labels from the resource type
|
|
297
|
+
labels = _get_environmental_labels(resource.type)
|
|
298
|
+
|
|
299
|
+
# Add labels from log record
|
|
300
|
+
if resource.type == _GAE_RESOURCE_TYPE and record._trace is not None:
|
|
301
|
+
labels[_GAE_TRACE_ID_LABEL] = record._trace
|
|
302
|
+
|
|
303
|
+
return labels
|
|
@@ -18,9 +18,19 @@ import collections
|
|
|
18
18
|
import json
|
|
19
19
|
import logging
|
|
20
20
|
|
|
21
|
-
from
|
|
22
|
-
|
|
21
|
+
from typing import Optional, IO
|
|
22
|
+
|
|
23
|
+
from google.cloud.logging_v2.handlers.transports import (
|
|
24
|
+
BackgroundThreadTransport,
|
|
25
|
+
Transport,
|
|
26
|
+
)
|
|
27
|
+
from google.cloud.logging_v2.handlers._monitored_resources import (
|
|
28
|
+
detect_resource,
|
|
29
|
+
add_resource_labels,
|
|
30
|
+
)
|
|
23
31
|
from google.cloud.logging_v2.handlers._helpers import get_request_data
|
|
32
|
+
from google.cloud.logging_v2.resource import Resource
|
|
33
|
+
|
|
24
34
|
|
|
25
35
|
DEFAULT_LOGGER_NAME = "python"
|
|
26
36
|
|
|
@@ -40,12 +50,6 @@ _INTERNAL_LOGGERS = (
|
|
|
40
50
|
"""These environments require us to remove extra handlers on setup"""
|
|
41
51
|
_CLEAR_HANDLER_RESOURCE_TYPES = ("gae_app", "cloud_function")
|
|
42
52
|
|
|
43
|
-
"""Extra trace label to be added on App Engine environments"""
|
|
44
|
-
_GAE_TRACE_ID_LABEL = "appengine.googleapis.com/trace_id"
|
|
45
|
-
|
|
46
|
-
"""Resource name for App Engine environments"""
|
|
47
|
-
_GAE_RESOURCE_TYPE = "gae_app"
|
|
48
|
-
|
|
49
53
|
|
|
50
54
|
class CloudLoggingFilter(logging.Filter):
|
|
51
55
|
"""Python standard ``logging`` Filter class to add Cloud Logging
|
|
@@ -152,11 +156,11 @@ class CloudLoggingHandler(logging.StreamHandler):
|
|
|
152
156
|
self,
|
|
153
157
|
client,
|
|
154
158
|
*,
|
|
155
|
-
name=DEFAULT_LOGGER_NAME,
|
|
156
|
-
transport=BackgroundThreadTransport,
|
|
157
|
-
resource=None,
|
|
158
|
-
labels=None,
|
|
159
|
-
stream=None,
|
|
159
|
+
name: str = DEFAULT_LOGGER_NAME,
|
|
160
|
+
transport: Transport = BackgroundThreadTransport,
|
|
161
|
+
resource: Resource = None,
|
|
162
|
+
labels: Optional[dict] = None,
|
|
163
|
+
stream: Optional[IO] = None,
|
|
160
164
|
**kwargs,
|
|
161
165
|
):
|
|
162
166
|
"""
|
|
@@ -206,9 +210,8 @@ class CloudLoggingHandler(logging.StreamHandler):
|
|
|
206
210
|
labels = record._labels
|
|
207
211
|
message = _format_and_parse_message(record, self)
|
|
208
212
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
labels = {_GAE_TRACE_ID_LABEL: record._trace, **(labels or {})}
|
|
213
|
+
labels = {**add_resource_labels(resource, record), **(labels or {})} or None
|
|
214
|
+
|
|
212
215
|
# send off request
|
|
213
216
|
self.transport.send(
|
|
214
217
|
record,
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
"""Transport for Python logging handler.
|
|
16
16
|
|
|
17
|
-
Logs directly to the
|
|
17
|
+
Logs directly to the Cloud Logging API with a synchronous call.
|
|
18
18
|
"""
|
|
19
19
|
from google.cloud.logging_v2 import _helpers
|
|
20
20
|
from google.cloud.logging_v2.handlers.transports.base import Transport
|
{google-cloud-logging-3.10.0 → google_cloud_logging-3.11.1}/google/cloud/logging_v2/logger.py
RENAMED
|
@@ -29,6 +29,7 @@ from google.cloud.logging_v2._instrumentation import _add_instrumentation
|
|
|
29
29
|
from google.api_core.exceptions import InvalidArgument
|
|
30
30
|
from google.rpc.error_details_pb2 import DebugInfo
|
|
31
31
|
|
|
32
|
+
import google.cloud.logging_v2
|
|
32
33
|
import google.protobuf.message
|
|
33
34
|
|
|
34
35
|
_GLOBAL_RESOURCE = Resource(type="global", labels={})
|
|
@@ -359,7 +360,7 @@ class Batch(object):
|
|
|
359
360
|
Args:
|
|
360
361
|
logger (logging_v2.logger.Logger):
|
|
361
362
|
the logger to which entries will be logged.
|
|
362
|
-
client (~logging_V2.client.
|
|
363
|
+
client (~logging_V2.client.Client):
|
|
363
364
|
The client to use.
|
|
364
365
|
resource (Optional[~logging_v2.resource.Resource]):
|
|
365
366
|
Monitored resource of the batch, defaults
|