Skip to content

Use LogRecord.event_name to set the log ID when the gcp log name attribute is not present. #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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.30.0
opentelemetry-sdk==1.30.0
opentelemetry-api==1.35.0
opentelemetry-sdk==1.35.0
3 changes: 3 additions & 0 deletions opentelemetry-exporter-gcp-logging/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
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.

The suffix part of `LogEntry.log_name` will be the `LogRecord.event_name` when
that is present and the `gcp.log_name` attribute is not.

## Version 1.9.0a0

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

[options.packages.find]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,14 @@ def export(self, batch: Sequence[LogData]):
project_id = str(
attributes.get(PROJECT_ID_ATTRIBUTE_KEY, self.project_id)
)
log_suffix = urllib.parse.quote_plus(
str(
attributes.get(
LOG_NAME_ATTRIBUTE_KEY, self.default_log_name
)
log_suffix = self.default_log_name
log_name_attr = attributes.get(LOG_NAME_ATTRIBUTE_KEY)
if log_name_attr and isinstance(log_name_attr, str):
log_suffix = urllib.parse.quote_plus(log_name_attr)
elif log_record.event_name:
log_suffix = urllib.parse.quote_plus(
log_record.event_name.replace(".", "_")
)
)
log_entry.log_name = f"projects/{project_id}/logs/{log_suffix}"
# If timestamp is unset fall back to observed_time_unix_nano as recommended,
# see https://github.com/open-telemetry/opentelemetry-proto/blob/4abbb78/opentelemetry/proto/logs/v1/logs.proto#L176-L179
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"gen_ai.system": "true",
"test": "23"
},
"logName": "projects/fakeproject/logs/test",
"logName": "projects/fakeproject/logs/random_genai_event",
"resource": {
"labels": {
"location": "global",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_convert_otlp_dict_body(
log_data = [
LogData(
log_record=LogRecord(
event_name="random.genai.event",
timestamp=1736976310997977393,
severity_number=SeverityNumber(20),
trace_id=25,
Expand Down