- 
                Notifications
    You must be signed in to change notification settings 
- Fork 758
[logs-sdk] Remove LogData and extend SDK LogRecord to have instrumentation scope #4676
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
base: main
Are you sure you want to change the base?
Changes from 29 commits
5333893
              c3c3bac
              b7cda72
              489fb85
              9d61737
              748d50a
              59a4f7e
              7591d05
              9ed04bb
              13f927d
              180c189
              671eb69
              5f9e550
              ba283ab
              292c70f
              c3f1607
              540bfe7
              d1cd9e5
              9387ff1
              940f642
              dbef47b
              0e0b451
              d7a467a
              5955465
              9da84bc
              34d2a1b
              b232ac8
              d7f58f0
              4ca4db8
              1025fb1
              7eb9f58
              53ecfa5
              5f24b77
              8b6efb8
              2146d3d
              7ff66d1
              49540d2
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -30,51 +30,55 @@ | |
| ResourceLogs, | ||
| ScopeLogs, | ||
| ) | ||
| from opentelemetry.sdk._logs import LogData | ||
| from opentelemetry.sdk._logs import ReadableLogRecord | ||
|  | ||
|  | ||
| def encode_logs(batch: Sequence[LogData]) -> ExportLogsServiceRequest: | ||
| def encode_logs( | ||
| batch: Sequence[ReadableLogRecord], | ||
| ) -> ExportLogsServiceRequest: | ||
| return ExportLogsServiceRequest(resource_logs=_encode_resource_logs(batch)) | ||
|  | ||
|  | ||
| def _encode_log(log_data: LogData) -> PB2LogRecord: | ||
| def _encode_log(readable_log_record: ReadableLogRecord) -> PB2LogRecord: | ||
| span_id = ( | ||
| None | ||
| if log_data.log_record.span_id == 0 | ||
| else _encode_span_id(log_data.log_record.span_id) | ||
| if readable_log_record.log_record.span_id == 0 | ||
| else _encode_span_id(readable_log_record.log_record.span_id) | ||
| ) | ||
| trace_id = ( | ||
| None | ||
| if log_data.log_record.trace_id == 0 | ||
| else _encode_trace_id(log_data.log_record.trace_id) | ||
| if readable_log_record.log_record.trace_id == 0 | ||
| else _encode_trace_id(readable_log_record.log_record.trace_id) | ||
| ) | ||
| body = log_data.log_record.body | ||
| body = readable_log_record.log_record.body | ||
| return PB2LogRecord( | ||
| time_unix_nano=log_data.log_record.timestamp, | ||
| observed_time_unix_nano=log_data.log_record.observed_timestamp, | ||
| time_unix_nano=readable_log_record.log_record.timestamp, | ||
| observed_time_unix_nano=readable_log_record.log_record.observed_timestamp, | ||
| span_id=span_id, | ||
| trace_id=trace_id, | ||
| flags=int(log_data.log_record.trace_flags), | ||
| flags=int(readable_log_record.log_record.trace_flags), | ||
| body=_encode_value(body, allow_null=True), | ||
| severity_text=log_data.log_record.severity_text, | ||
| severity_text=readable_log_record.log_record.severity_text, | ||
| attributes=_encode_attributes( | ||
| log_data.log_record.attributes, allow_null=True | ||
| readable_log_record.log_record.attributes, allow_null=True | ||
| ), | ||
| dropped_attributes_count=log_data.log_record.dropped_attributes, | ||
| dropped_attributes_count=readable_log_record.dropped_attributes, | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 | ||
| severity_number=getattr( | ||
| log_data.log_record.severity_number, "value", None | ||
| readable_log_record.log_record.severity_number, "value", None | ||
| ), | ||
| event_name=log_data.log_record.event_name, | ||
| event_name=readable_log_record.log_record.event_name, | ||
| ) | ||
|  | ||
|  | ||
| def _encode_resource_logs(batch: Sequence[LogData]) -> List[ResourceLogs]: | ||
| def _encode_resource_logs( | ||
| batch: Sequence[ReadableLogRecord], | ||
| ) -> List[ResourceLogs]: | ||
| sdk_resource_logs = defaultdict(lambda: defaultdict(list)) | ||
|  | ||
| for sdk_log in batch: | ||
| sdk_resource = sdk_log.log_record.resource | ||
| sdk_instrumentation = sdk_log.instrumentation_scope or None | ||
| pb2_log = _encode_log(sdk_log) | ||
| for readable_log in batch: | ||
| sdk_resource = readable_log.resource | ||
| sdk_instrumentation = readable_log.instrumentation_scope or None | ||
| pb2_log = _encode_log(readable_log) | ||
|  | ||
| sdk_resource_logs[sdk_resource][sdk_instrumentation].append(pb2_log) | ||
|  | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.