Skip to content

Commit 8266de1

Browse files
committed
docs: update usage guide for v3.0.0 (#456)
1 parent a24a515 commit 8266de1

21 files changed

+808
-490
lines changed

UPGRADING.md

+129-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,131 @@
1+
# 3.0.0 Migration Guide
2+
3+
The v3.0.0 release of `google-cloud-logging` improves usability of the library,
4+
particularly on serverless environments.
5+
6+
If you experience technical issues or have questions, please file an [issue](https://github.com/googleapis/python-logging/issues).
7+
8+
## Primary Changes
9+
10+
### Handler deprecations ([#310](https://github.com/googleapis/python-logging/pull/310))
11+
12+
> **WARNING**: Breaking change
13+
14+
We have changed our design policy to support more generic `Handler` classes instead of product-specific classes:
15+
16+
- [`CloudLoggingHandler`](https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/handlers.py)
17+
- Sends logs over the network (using gRPC or HTTP API calls)
18+
- Replaces `AppEngineHandler`
19+
- [`StructuredLogHandler`](https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/structured_log.py)
20+
- Exports logs in JSON format through standard out, to be parsed by an agent
21+
- Replaces `ContainerEngineHandler`
22+
23+
As of v3.0.0, [`AppEngineHandler`](https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/app_engine.py)
24+
and [`ContainerEngineHandler`](https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/container_engine.py)
25+
are deprecated and won't be updated. These handlers might be removed from the library in a future update.
26+
27+
### Full JSON log support in standard library integration ([#316](https://github.com/googleapis/python-logging/pull/316), [#339](https://github.com/googleapis/python-logging/pull/339), [#447](https://github.com/googleapis/python-logging/pull/447))
28+
29+
You can now log JSON data using the Python `logging` standard library integration.
30+
To log JSON data, do one of the following:
31+
32+
1. Use `json_fields` `extra` argument:
33+
34+
```py
35+
import logging
36+
37+
data_dict = {"hello": "world"}
38+
logging.info("message field", extra={"json_fields": data_dict})
39+
```
40+
41+
2. Log a JSON-parsable string:
42+
43+
```py
44+
import logging
45+
import json
46+
47+
data_dict = {"hello": "world"}
48+
logging.info(json.dumps(data_dict))
49+
```
50+
51+
### Metadata autodetection ([#315](https://github.com/googleapis/python-logging/pull/315))
52+
53+
> **WARNING**: Breaking change
54+
55+
Logs emitted by the library must be associated with a [montored-resource type](https://cloud.google.com/monitoring/api/resources)
56+
that indicates the compute environment the log originated from.
57+
- Prior to 3.0.0, when a log doesn't specify a monitored resource, that field is set to ["global"](https://cloud.google.com/monitoring/api/resources#tag_global).
58+
- With 3.0.0, when a log doesn't specify a monitored resource, the library attempts to identify the resource. If a resource can't be detected, the field will still default to ["global"](https://cloud.google.com/monitoring/api/resources#tag_global).
59+
60+
### New `Logger.log` method ([#316](https://github.com/googleapis/python-logging/pull/316))
61+
62+
In v3.0.0, the library adds a generic `log()` method that will attempt to infer and log any type:
63+
64+
```py
65+
logger.log("hello world")
66+
```
67+
68+
v3.0.0 also supports the Logging class methods from previous releases:
69+
70+
```py
71+
logger.log_text("hello world")
72+
logger.log_struct({"hello": "world"})
73+
logger.log_proto(proto_message)
74+
logger.log_empty()
75+
```
76+
77+
### More permissive arguments ([#422](https://github.com/googleapis/python-logging/pull/422))
78+
79+
> **WARNING**: Breaking change
80+
81+
In v3.0.0, the library supports a wider variety of input formats:
82+
83+
```py
84+
# lowercase severity strings will be accepted
85+
logger.log("hello world", severity="warning")
86+
```
87+
88+
```py
89+
# a severity will be pulled out of the JSON payload if not otherwise set
90+
logger.log({"hello": "world", "severity":"warning"})
91+
```
92+
93+
```py
94+
# resource data can be passed as a dict instead of a Resource object
95+
logger.log("hello world", resource={"type":"global", "labels":[]})
96+
```
97+
98+
### Allow reading from non-project resources ([#444](https://github.com/googleapis/python-logging/pull/444))
99+
100+
Prior to v3.0.0, there was a crashing bug when attempting to read logs from non-project resources:
101+
102+
- `organizations/[ORGANIZATION_ID]/logs/[LOG_ID]`
103+
- `billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]`
104+
- `folders/[FOLDER_ID]/logs/[LOG_ID]`
105+
106+
The v3.0.0 update fixes this issue.
107+
108+
### Internal Gapic and HTTP implementation changes ([#375](https://github.com/googleapis/python-logging/pull/375))
109+
110+
> **WARNING**: Breaking change
111+
112+
The library supports sending logs using two network protocols: gRPC and HTTP. Prior to v3.0.0, there was an
113+
inconsistency in the implementations, resulting in unexpected behavior when in HTTP mode.
114+
115+
### Max_size argument when listing entries ([#375](https://github.com/googleapis/python-logging/pull/375))
116+
117+
v3.0.0 introduces a new `max_size` argument to `list_entries` calls, which can be used to specify an upper bound
118+
on how many logs should be returned:
119+
120+
```py
121+
from google.cloud import logging_v2
122+
123+
client = logging_v2.Client()
124+
client.list_entries(max_size=5)
125+
```
126+
127+
---
128+
1129
# 2.0.0 Migration Guide
2130

3131
The 2.0 release of the `google-cloud-logging` client is a significant upgrade based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-python), and includes substantial interface changes. Existing code written for earlier versions of this library will likely require updates to use this version. This document describes the changes that have been made, and what you need to do to update your usage.
@@ -334,4 +462,4 @@ The following resource name helpers have been renamed.
334462

335463
**`ConfigServiceV2Client`**
336464
* `sink_path` -> `log_sink_path`
337-
* `exclusion_path` -> `log_exclusion_path`
465+
* `exclusion_path` -> `log_exclusion_path`

0 commit comments

Comments
 (0)