Skip to content
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

[receiver/googlepubsub] fix span and trace id parsing crash #33247

Closed
Closed
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
29 changes: 29 additions & 0 deletions .chloggen/googlepubsubreceiver-logenhance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: googlecloudpubsubreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: fix span and trace id parsing crash when encountering corrupt data in `cloud_logging` encoding

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [ 32007 ]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Fixed span and trace id parsing crash when encountering corrupt data. Enhanced the `cloud_logging` parsing so it's
better testable and include additional tests.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
59 changes: 56 additions & 3 deletions receiver/googlecloudpubsubreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ must the `encoding` field in the configuration be set.
|-----------------------------------|----------------------|-------------------|------------------------------------------------|
| org.opentelemetry.otlp.traces.v1 | application/protobuf | | Decode OTLP trace message |
| org.opentelemetry.otlp.metrics.v1 | application/protobuf | | Decode OTLP metric message |
| org.opentelemetry.otlp.logs.v1 | application/json | | Decode OTLP log message |
| org.opentelemetry.otlp.logs.v1 | application/protobuf | | Decode OTLP log message |
| - | - | otlp_proto_trace | Decode OTLP trace message |
| - | - | otlp_proto_metric | Decode OTLP trace message |
| - | - | otlp_proto_log | Decode OTLP trace message |
| - | - | otlp_proto_metric | Decode OTLP metric message |
| - | - | otlp_proto_log | Decode OTLP log message |
| - | - | cloud_logging | Decode [Cloud Logging] [LogEntry] message type |
| - | - | raw_text | Wrap in an OTLP log message |

Expand Down Expand Up @@ -89,3 +89,56 @@ AND
attributes.content-type = "application/protobuf"
```

# Google Cloud Logging

**Status**: Experimental

Google Cloud logging uses the [LogEntry] to carry log information. In this section, the mapping of the fields to
OpenTelemetry fields and attributes are documented.

## Semantic Mapping

Some of the attributes can be moved to OpenTelemetry Semantic Conventions. Note, however, that all the attributes are
considered experimental and are subject to change.

| Field | Type | Description | Maps to Unified Model Field |
|-------------|-----------|----------------------------------------|--------------------------------|
| `insert_id` | `boolean` | A unique identifier for the log entry. | `Attributes["log.record.uid"]` |

## Attribute and Field mapping

The rest of the JSON body is either mapped to attributes with a `gcp` prefix or directly mapped to the LogRecord.

| Field | Type | Description | Maps to Unified Model Field |
|--------------------|--------------------------|------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `timestamp` | `string` | The time the event described by the log entry occurred. | `Timestamp` |
| `receiveTimestamp` | `string` | The time the log entry was received. | `ObservedTimestamp` |
| `logName` | `string` | The URL-encoded log ID suffix of the log_name field identifies which log stream this entry belongs to. | `Attributes["gcp.log_name"]` (string) |
| `jsonPayload` | `google.protobuf.Struct` | The log entry payload, represented as a structure that is expressed as a JSON object. | `Body` (KVList) |
| `protoPayload` | `google.protobuf.Any` | The log entry payload, represented as a protocol buffer. | `Body` (KVList, key from JSON representation) |
| `textPayload` | `string` | The log entry payload, represented as a Unicode string (UTF-8). | `Body` (string) |
| `trace` | `string` | The trace associated with the log entry, if any. | `TraceId` |
| `spanId` | `string` | The span ID within the trace associated with the log entry. | `SpanId` |
| `traceSampled` | `boolean` | The sampling decision of the trace associated with the log entry. | `TraceFlags.SAMPLED` |
| `labels` | `map<string,string>` | A set of user-defined (key, value) data that provides additional information about the log entry. | `Attributes["gcp.*"]` |
| `resource` | `MonitoredResource` | The monitored resource that produced this log entry. | `Resource["gcp.*"]` |
| `httpRequest` | `HttpRequest` | The HTTP request associated with the log entry, if any. | `Attributes["gcp.http_request"]` (KVList) |
| `operation` | `LogEntryOperation` | Information about a operation associated with the log entry. | `Attributes["gcp.operation"]` (KVList) |
| `sourceLocation` | `LogEntrySourceLocation` | Source code location information associated with the log entry. | `Attributes["gcp.source_location"]` (KVList) |
| `split` | `LogSplit` | Information indicating this LogEntry is part of a sequence of multiple log entries split from a single LogEntry. | `Attributes["gcp.log_split"]` (KVList) |

## Severity Mapping

The severity is mapping from [Google Cloud Log Severity](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity) to the OpenTelemetry Severity Number.

| CloudLog | Severity Number | CloudLog Description |
|------------------|------------------|----------------------------------------------------------------------------------------|
| `DEFAULT`(0) | `UNSPECIFIED`(0) | The log entry has no assigned severity level. |
| `DEBUG`(100) | `DEBUG`(5) | Debug or trace information. |
| `INFO`(200) | `INFO`(9) | Routine information, such as ongoing status or performance. |
| `NOTICE`(300) | `INFO2`(10) | Normal but significant events, such as start up, shut down, or a configuration change. |
| `WARNING`(400) | `WARN`(13) | Warning events might cause problems. |
| `ERROR`(500) | `ERROR`(17) | Error events are likely to cause problems. |
| `CRITICAL`(600) | `FATAL`(21) | Critical events cause more severe problems or outages. |
| `ALERT`(700) | `FATAL2`(22) | A person must take an action immediately. |
| `EMERGENCY`(800) | `FATAL4`(24) | One or more systems are unusable. |
Loading