Skip to content

Commit 27f602b

Browse files
committed
Initial commit to handle event name attr key
1 parent 54cb8a6 commit 27f602b

File tree

1 file changed

+6
-7
lines changed
  • opentelemetry-exporter-gcp-logging/src/opentelemetry/exporter/cloud_logging

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
HTTP_REQUEST_ATTRIBUTE_KEY = "gcp.http_request"
5959
LOG_NAME_ATTRIBUTE_KEY = "gcp.log_name"
60+
EVENT_NAME_ATTRIBUTE_KEY = "event.name"
6061
SOURCE_LOCATION_ATTRIBUTE_KEY = "gcp.source_location"
6162
TRACE_SAMPLED_ATTRIBUTE_KEY = "gcp.trace_sampled"
6263
PROJECT_ID_ATTRIBUTE_KEY = "gcp.project_id"
@@ -197,13 +198,11 @@ def export(self, batch: Sequence[LogData]):
197198
project_id = str(
198199
attributes.get(PROJECT_ID_ATTRIBUTE_KEY, self.project_id)
199200
)
200-
log_suffix = urllib.parse.quote_plus(
201-
str(
202-
attributes.get(
203-
LOG_NAME_ATTRIBUTE_KEY, self.default_log_name
204-
)
205-
)
206-
)
201+
log_suffix = self.default_log_name
202+
if attributes.get(LOG_NAME_ATTRIBUTE_KEY):
203+
log_suffix = urllib.parse.quote_plus(attributes.get(LOG_NAME_ATTRIBUTE_KEY))
204+
elif attributes.get(EVENT_NAME_ATTRIBUTE_KEY):
205+
log_suffix = urllib.parse.quote_plus(attributes.get(EVENT_NAME_ATTRIBUTE_KEY))
207206
log_entry.log_name = f"projects/{project_id}/logs/{log_suffix}"
208207
# If timestamp is unset fall back to observed_time_unix_nano as recommended,
209208
# see https://github.com/open-telemetry/opentelemetry-proto/blob/4abbb78/opentelemetry/proto/logs/v1/logs.proto#L176-L179

0 commit comments

Comments
 (0)