Skip to content

Commit 00be214

Browse files
committed
Use anonymous creds in the test. Fix mypy type
issues with LogSeverity.
1 parent 1a8a1b6 commit 00be214

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

opentelemetry-exporter-gcp-logging/src/opentelemetry/exporter/cloud_logging/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
# Remove after this program no longer support Python 3.8.*
15+
from __future__ import annotations
1416
import datetime
1517
import logging
1618
import urllib.parse
@@ -59,7 +61,7 @@
5961

6062
# severityMapping maps the integer severity level values from OTel [0-24]
6163
# to matching Cloud Logging severity levels.
62-
SEVERITY_MAPPING: dict[int, int] = {
64+
SEVERITY_MAPPING = {
6365
0: LogSeverity.DEFAULT, # Default, 0
6466
1: LogSeverity.DEBUG, #
6567
2: LogSeverity.DEBUG, #
@@ -172,10 +174,10 @@ def export(self, batch: Sequence[LogData]):
172174
log_entry.span_id = str(hex(log_record.span_id))[2:]
173175
if (
174176
log_record.severity_number
175-
and log_record.severity_number in SEVERITY_MAPPING
177+
and log_record.severity_number.value in SEVERITY_MAPPING
176178
):
177-
log_entry.severity = SEVERITY_MAPPING[
178-
log_record.severity_number
179+
log_entry.severity = SEVERITY_MAPPING[ #type: ignore[assignment]
180+
log_record.severity_number.value #type: ignore[index]
179181
]
180182
log_entry.labels = {k: str(v) for k, v in attrs_map.items()}
181183
if type(log_record.body) is dict:

opentelemetry-exporter-gcp-logging/tests/__snapshots__/test_cloud_logging/test_convert_otlp.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"type": "generic_node"
2929
},
30+
"severity": "ERROR",
3031
"spanId": "16",
3132
"timestamp": "2025-01-15T21:25:10.997977393Z",
3233
"trace": "projects/fakeproject/traces/25"

opentelemetry-exporter-gcp-logging/tests/test_cloud_logging.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
2626
Be sure to review the changes.
2727
"""
28-
2928
import re
3029
from typing import List
3130

@@ -39,18 +38,19 @@
3938
from opentelemetry.sdk._logs._internal import LogRecord
4039
from opentelemetry.sdk.resources import Resource
4140
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
41+
from google.auth.credentials import AnonymousCredentials
4242

4343
PROJECT_ID = "fakeproject"
4444

4545

46-
def test_create_cloud_logging_exporter(caplog) -> None:
46+
def test_create_cloud_logging_exporter() -> None:
4747
CloudLoggingExporter(default_log_name="test")
48-
client = LoggingServiceV2Client()
48+
client = LoggingServiceV2Client(credentials=AnonymousCredentials())
4949
CloudLoggingExporter(project_id=PROJECT_ID, client=client)
5050

5151

5252
def test_invalid_otlp_entries_raise_warnings(caplog) -> None:
53-
client = LoggingServiceV2Client()
53+
client = LoggingServiceV2Client(credentials=AnonymousCredentials())
5454
no_default_logname = CloudLoggingExporter(
5555
project_id=PROJECT_ID, client=client
5656
)

0 commit comments

Comments
 (0)