Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6dde48c
Add space to logging exporter README. Make minor
DylanRussell Feb 4, 2025
ec8a0d6
Merge branch 'GoogleCloudPlatform:main' into main
DylanRussell Feb 24, 2025
34a98ff
Merge branch 'GoogleCloudPlatform:main' into main
DylanRussell Mar 11, 2025
a05a651
Merge branch 'GoogleCloudPlatform:main' into main
DylanRussell May 8, 2025
5ddc159
Fix byes in LogRecord bug
DylanRussell Jun 4, 2025
a7819d8
Merge branch 'main' into fix_bytes
DylanRussell Jun 4, 2025
c8edae9
Run linter
DylanRussell Jun 4, 2025
8a6c452
Merge branch 'fix_bytes' of github.com:DylanRussell/opentelemetry-ope…
DylanRussell Jun 4, 2025
a483967
fix pulint
DylanRussell Jun 4, 2025
b037b80
Respond to comments
DylanRussell Jun 4, 2025
2da59b8
Update opentelemetry-exporter-gcp-logging/src/opentelemetry/exporter/…
DylanRussell Jun 5, 2025
a65eaf2
Update opentelemetry-exporter-gcp-logging/src/opentelemetry/exporter/…
DylanRussell Jun 5, 2025
8618228
Address comments
DylanRussell Jun 5, 2025
bc83e4a
Update constraints
DylanRussell Jun 5, 2025
a0f95e4
Fix constraints
DylanRussell Jun 5, 2025
2ef718d
FIx lint issues in cloud monitoring exporter and add changelog entry
DylanRussell Jun 5, 2025
55baba7
Bump api/sdk versions to 1.3
DylanRussell Jun 5, 2025
196de33
Merge branch 'GoogleCloudPlatform:main' into fix_bytes
DylanRussell Jun 6, 2025
4a18f05
Fix broken trace exporter test
DylanRussell Jun 6, 2025
76411fa
Merge branch 'fix_bytes' of github.com:DylanRussell/opentelemetry-ope…
DylanRussell Jun 6, 2025
a6b8c48
Update constraints.txt
DylanRussell Jun 6, 2025
445a9f2
Update constraints again
DylanRussell Jun 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import json
import logging
import urllib.parse
from typing import Any, Mapping, Optional, Sequence
from typing import Any, Mapping, MutableMapping, Optional, Sequence

import google.auth
from google.api.monitored_resource_pb2 import ( # pylint: disable = no-name-in-module
Expand Down Expand Up @@ -117,10 +117,29 @@ def _convert_any_value_to_string(value: Any) -> str:
return ""


def _convert_bytes_to_b64(body: Mapping, new_body: dict) -> dict:
for key, value in list(body.items()):
if (
isinstance(value, Sequence)
and len(value) > 0
and isinstance(value[0], bytes)
):
new_body[key] = [base64.b64encode(v).decode() for v in value]
elif isinstance(value, bytes):
new_body[key] = base64.b64encode(value).decode()
elif isinstance(value, MutableMapping):
new_subbody = {}
new_body[key] = _convert_bytes_to_b64(value, new_subbody)
else:
new_body[key] = value
return new_body


def _set_payload_in_log_entry(log_entry: LogEntry, body: Any | None):
struct = Struct()
if isinstance(body, Mapping):
struct.update(body)
new_body = {}
struct.update(_convert_bytes_to_b64(body, new_body))
log_entry.json_payload = struct
elif isinstance(body, bytes):
json_str = body.decode("utf-8", errors="replace")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
{
"jsonPayload": {
"kvlistValue": {
"bytes_field": "Ynl0ZXM=",
"repeated_bytes_field": [
"Ynl0ZXM=",
"Ynl0ZXM=",
"Ynl0ZXM="
],
"values": [
{
"key": "content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def test_convert_otlp_dict_body(
"stringValue": "You're a helpful assistant."
},
}
]
],
"bytes_field": b"bytes",
"repeated_bytes_field": [b"bytes", b"bytes", b"bytes"],
}
},
),
Expand Down
Loading