| 480 | func (ps clientLogs) Shutdown(context.Context) error { return nil } |
| 481 | |
| 482 | func insertLogRecordParam(rec *sdklog.Record) (*clientdb.InsertLogParams, error) { |
| 483 | traceID := rec.TraceID().String() |
| 484 | spanID := rec.SpanID().String() |
| 485 | timestamp := rec.Timestamp().UnixNano() |
| 486 | severity := int64(rec.Severity()) |
| 487 | |
| 488 | var body []byte |
| 489 | if !rec.Body().Empty() { |
| 490 | var err error |
| 491 | body, err = proto.Marshal(telemetry.LogValueToPB(rec.Body())) |
| 492 | if err != nil { |
| 493 | return nil, fmt.Errorf("marshal log record body: %w", err) |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | attrs := []*otlpcommonv1.KeyValue{} |
| 498 | rec.WalkAttributes(func(kv log.KeyValue) bool { |
| 499 | attrs = append(attrs, &otlpcommonv1.KeyValue{ |
| 500 | Key: kv.Key, |
| 501 | Value: telemetry.LogValueToPB(kv.Value), |
| 502 | }) |
| 503 | return true |
| 504 | }) |
| 505 | attributes, err := clientdb.MarshalProtoJSONs(attrs) |
| 506 | if err != nil { |
| 507 | return nil, fmt.Errorf("marshal log record attributes: %w", err) |
| 508 | } |
| 509 | |
| 510 | scope, err := protojson.Marshal(telemetry.InstrumentationScopeToPB(rec.InstrumentationScope())) |
| 511 | if err != nil { |
| 512 | return nil, fmt.Errorf("marshal log record instrumentation scope: %w", err) |
| 513 | } |
| 514 | |
| 515 | res := rec.Resource() |
| 516 | resource, err := protojson.Marshal(telemetry.ResourcePtrToPB(res)) |
| 517 | if err != nil { |
| 518 | return nil, fmt.Errorf("marshal log record resource: %w", err) |
| 519 | } |
| 520 | |
| 521 | return &clientdb.InsertLogParams{ |
| 522 | TraceID: sql.NullString{ |
| 523 | String: traceID, |
| 524 | Valid: rec.TraceID().IsValid(), |
| 525 | }, |
| 526 | SpanID: sql.NullString{ |
| 527 | String: spanID, |
| 528 | Valid: rec.SpanID().IsValid(), |
| 529 | }, |
| 530 | Timestamp: timestamp, |
| 531 | SeverityNumber: severity, |
| 532 | SeverityText: rec.SeverityText(), |
| 533 | Body: body, |
| 534 | Attributes: attributes, |
| 535 | InstrumentationScope: scope, |
| 536 | Resource: resource, |
| 537 | ResourceSchemaUrl: res.SchemaURL(), |
| 538 | }, nil |
| 539 | } |