Skip to content

Commit eac5e2d

Browse files
committed
added upgrading notes
1 parent 8bce609 commit eac5e2d

File tree

1 file changed

+130
-1
lines changed

1 file changed

+130
-1
lines changed

UPGRADING.md

+130-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,134 @@
11
# 3.0.0 Migration Guide
22

3+
The v3.0.0 release of `google-cloud-logging` is focused on improving usability of the library,
4+
particularly on newer serverless environments.
5+
6+
If you experience 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+
Prior to v3.0.0, there were three `Handler` classes used for the Python logging standard library integration:
15+
16+
- [`AppEngineHandler`](https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/app_engine.py)
17+
- [`ContainerEngineHandler`](https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/container_engine.py)
18+
- [`CloudLoggingHandler`](https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/handlers.py)
19+
20+
Google Cloud has grown, and adding a new handler class for each new product does not scale.
21+
Recently, we have changed to support two more generic `Handler` classes instead:
22+
23+
- [`CloudLoggingHandler`](https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/handlers.py)
24+
- sends logs over the network (using gRPC or HTTP API calls)
25+
- replaces `AppEngineHandler`
26+
- [`StructuredLogHandler`](https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/structured_log.py)
27+
- exports logs in JSON format through standard out, to be parsed by an agent
28+
- replaces `ContainerEngineHandler`
29+
30+
As of v3.0.0, `AppEngineHandler` and `ContainerEngineHandler` have been marked as deprecated and will not be updated.
31+
They may be removed from the library in a future update.
32+
33+
### 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))
34+
35+
You can now log JSON data using the Python `logging` standard library integration.
36+
The library supports two different methods:
37+
38+
1. Using the `json_fields` `extra` argument:
39+
40+
```py
41+
import logging
42+
43+
data_dict = {"hello": "world"}
44+
logging.info("message field", extra={"json_fields": data_dict})
45+
```
46+
47+
2. Logging a JSON-parsable string:
48+
49+
```py
50+
import logging
51+
import json
52+
53+
data_dict = {"hello": "world"}
54+
logging.info(json.dumps(data_dict))
55+
```
56+
57+
### Metadata autodetection ([#315](https://github.com/googleapis/python-logging/pull/315))
58+
59+
> **WARNING**: Breaking change
60+
61+
Logs emitted by the library must be associated with a [montored-resource type](https://cloud.google.com/monitoring/api/resources),
62+
indicating the compute environment the log originated from. Previously, the logs would default to
63+
["global"](https://cloud.google.com/monitoring/api/resources#tag_global) when left unspecified.
64+
Going forward, the library will attempt to determine the monitored-resource automatically if not explicitly set.
65+
66+
### New `Logger.log` method ([#316](https://github.com/googleapis/python-logging/pull/316))
67+
68+
Previously, the Logger class had four methods for sending logs of different types:
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+
In v3.0.0, the library adds a generic `log()` method that will attempt to infer and log any type:
78+
79+
```py
80+
logger.log("hello world")
81+
```
82+
83+
### More permissive arguments ([#422](https://github.com/googleapis/python-logging/pull/422))
84+
85+
> **WARNING**: Breaking change
86+
87+
In v3.0.0, the library will be more forgiving if inputs are given in a different format than expected
88+
89+
```py
90+
# lowercase severity strings will be accepted
91+
logger.log("hello world", severity="warning")
92+
```
93+
94+
```py
95+
# a severity will be pulled out of the JSON payload if not otherwise set
96+
logger.log({"hello": "world", "severity":"warning"})
97+
```
98+
99+
```py
100+
# resource data can be passed as a dict instead of a Resource object
101+
logger.log("hello world", resource={"type":"global", "labels":[]})
102+
```
103+
104+
### Allow reading from non-project resources ([#444](https://github.com/googleapis/python-logging/pull/444))
105+
106+
Prior to v3.0.0, there was a crashing bug when attempting to read logs from non-project resources:
107+
108+
- `organizations/[ORGANIZATION_ID]/logs/[LOG_ID]`
109+
- `billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]`
110+
- `folders/[FOLDER_ID]/logs/[LOG_ID]`
111+
112+
The v3.0.0 update fixes this issue.
113+
114+
### Internal Gapic and HTTP implementation changes ([#375](https://github.com/googleapis/python-logging/pull/375))
115+
116+
> **WARNING**: Breaking change
117+
118+
The library supports sending logs using two different network protocols: gRPC and HTTP. Previously, there was an \
119+
inconsistency in the implementations, resulting in unexpected behaviour when in HTTP mode.
120+
121+
As part of these changes, we introduced a new `max_size` argument to `list_entries` calls, which can be used to determine
122+
how many results should be returned:
123+
124+
```py
125+
from google.cloud import logging_v2
126+
127+
client = logging_v2.Client()
128+
client.list_entries(max_size=5)
129+
```
130+
131+
---
3132

4133
# 2.0.0 Migration Guide
5134

@@ -337,4 +466,4 @@ The following resource name helpers have been renamed.
337466

338467
**`ConfigServiceV2Client`**
339468
* `sink_path` -> `log_sink_path`
340-
* `exclusion_path` -> `log_exclusion_path`
469+
* `exclusion_path` -> `log_exclusion_path`

0 commit comments

Comments
 (0)