Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions dev-constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ setuptools==69.5.1

# pinned for snapshot tests. this should be bumped regularly and snapshots updated by running
# tox -f py311-test -- --snapshot-update
opentelemetry-api==1.20.0
opentelemetry-sdk==1.20.0
opentelemetry-api==1.30.0
opentelemetry-sdk==1.30.0
6 changes: 3 additions & 3 deletions e2e-test-server/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ importlib-metadata==6.8.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
opentelemetry-api==1.20.0
opentelemetry-sdk==1.20.0
opentelemetry-semantic-conventions==0.41b0
opentelemetry-api==1.30.0
opentelemetry-sdk==1.30.0
opentelemetry-semantic-conventions==0.51b0
packaging==24.1
proto-plus==1.22.3
protobuf==4.24.4
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-exporter-gcp-logging/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

Added support for when `bytes` or `list['bytes']` is in `LogRecord.body` and
body is of type Mapping. Update opentelemetry-api/sdk dependencies to 1.3.

## Version 1.9.0a0

Released 2025-02-03
3 changes: 2 additions & 1 deletion opentelemetry-exporter-gcp-logging/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ package_dir=
packages=find_namespace:
install_requires =
google-cloud-logging ~= 3.0
opentelemetry-sdk ~= 1.0
opentelemetry-sdk ~= 1.30
opentelemetry-api ~= 1.30
opentelemetry-resourcedetector-gcp >= 1.5.0dev0, == 1.*

[options.packages.find]
Expand Down
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 @@ -50,6 +50,7 @@
from opentelemetry.sdk._logs.export import LogExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.trace import format_span_id, format_trace_id
from opentelemetry.util.types import AnyValue

DEFAULT_MAX_ENTRY_SIZE = 256000 # 256 KB
DEFAULT_MAX_REQUEST_SIZE = 10000000 # 10 MB
Expand Down Expand Up @@ -117,10 +118,37 @@ def _convert_any_value_to_string(value: Any) -> str:
return ""


def _set_payload_in_log_entry(log_entry: LogEntry, body: Any | None):
# Be careful not to mutate original body. Make copies of anything that needs to change.
def _sanitized_body(
body: Mapping[str, AnyValue]
) -> MutableMapping[str, AnyValue]:
new_body: MutableMapping[str, AnyValue] = {}
for key, value in body.items():
if (
isinstance(value, Sequence)
and len(value) > 0
and isinstance(value[0], bytes)
):
# Should not be possible for a non-bytes value to be present. AnyValue requires Sequence be of one type, and above
# we verified the first value is type bytes.
new_body[key] = [
base64.b64encode(v).decode()
for v in value
if isinstance(v, bytes)
]
elif isinstance(value, bytes):
new_body[key] = base64.b64encode(value).decode()
elif isinstance(value, Mapping):
new_body[key] = _sanitized_body(value)
else:
new_body[key] = value
return new_body


def _set_payload_in_log_entry(log_entry: LogEntry, body: AnyValue):
struct = Struct()
if isinstance(body, Mapping):
struct.update(body)
struct.update(_sanitized_body(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
2 changes: 2 additions & 0 deletions opentelemetry-exporter-gcp-monitoring/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

Update opentelemetry-api/sdk dependencies to 1.3.

## Version 1.9.0a0

Released 2025-02-03
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-exporter-gcp-monitoring/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ package_dir=
packages=find_namespace:
install_requires =
google-cloud-monitoring ~= 2.0
opentelemetry-api ~= 1.0
opentelemetry-sdk ~= 1.0
opentelemetry-api ~= 1.30
opentelemetry-sdk ~= 1.30
opentelemetry-resourcedetector-gcp >= 1.5.0dev0, == 1.*

[options.packages.find]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
)
from opentelemetry.sdk import version as opentelemetry_sdk_version
from opentelemetry.sdk.metrics.export import (
ExponentialHistogram,
ExponentialHistogramDataPoint,
Gauge,
Histogram,
HistogramDataPoint,
Expand Down Expand Up @@ -209,6 +211,12 @@ def _get_metric_descriptor(
descriptor.metric_kind = MetricDescriptor.MetricKind.GAUGE
elif isinstance(data, Histogram):
descriptor.metric_kind = MetricDescriptor.MetricKind.CUMULATIVE
elif isinstance(data, ExponentialHistogram):
logger.warning(
"Unsupported metric data type %s, ignoring it",
type(data).__name__,
)
return None
else:
# Exhaustive check
_: NoReturn = data
Expand Down Expand Up @@ -342,6 +350,10 @@ def export(
continue

for data_point in metric.data.data_points:
if isinstance(
data_point, ExponentialHistogramDataPoint
):
continue
labels = {
_normalize_label_key(key): str(value)
for key, value in (
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-exporter-gcp-trace/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

Update opentelemetry-api/sdk dependencies to 1.3.

## Version 1.9.0

Released 2025-02-03
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-exporter-gcp-trace/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ package_dir=
packages=find_namespace:
install_requires =
google-cloud-trace ~= 1.1
opentelemetry-api ~= 1.0
opentelemetry-sdk ~= 1.0
opentelemetry-api ~= 1.30
opentelemetry-sdk ~= 1.30
opentelemetry-resourcedetector-gcp >= 1.5.0dev0, == 1.*

[options.packages.find]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ def test_extract_multiple_links(self):
),
attributes={"illegal_attr_value": dict(), "int_attr_value": 123},
)
print(link3.attributes)
self.assertEqual(
_extract_links([link1, link2, link3]),
ProtoSpan.Links(
Expand All @@ -571,6 +572,7 @@ def test_extract_multiple_links(self):
"span_id": span_id2,
"type": "TYPE_UNSPECIFIED",
"attributes": {
"dropped_attributes_count": 1,
"attribute_map": {
"int_attr_value": AttributeValue(int_value=123)
},
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-propagator-gcp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

Update opentelemetry-api/sdk dependencies to 1.3.

## Version 1.9.0

Released 2025-02-03
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-resourcedetector-gcp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

Update opentelemetry-api/sdk dependencies to 1.3.

## Version 1.9.0a0

Released 2025-02-03
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-resourcedetector-gcp/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ package_dir=
=src
packages=find_namespace:
install_requires =
opentelemetry-api ~= 1.0
opentelemetry-sdk ~= 1.0
opentelemetry-api ~= 1.30
opentelemetry-sdk ~= 1.30
requests ~= 2.24
# TODO: remove when Python 3.7 is dropped
typing_extensions ~= 4.0
Expand Down