unmarshaler.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package kafkareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kafkareceiver"
  4. import (
  5. "go.opentelemetry.io/collector/pdata/plog"
  6. "go.opentelemetry.io/collector/pdata/pmetric"
  7. "go.opentelemetry.io/collector/pdata/ptrace"
  8. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/zipkinv1"
  9. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/zipkinv2"
  10. )
  11. // TracesUnmarshaler deserializes the message body.
  12. type TracesUnmarshaler interface {
  13. // Unmarshal deserializes the message body into traces.
  14. Unmarshal([]byte) (ptrace.Traces, error)
  15. // Encoding of the serialized messages.
  16. Encoding() string
  17. }
  18. // MetricsUnmarshaler deserializes the message body
  19. type MetricsUnmarshaler interface {
  20. // Unmarshal deserializes the message body into traces
  21. Unmarshal([]byte) (pmetric.Metrics, error)
  22. // Encoding of the serialized messages
  23. Encoding() string
  24. }
  25. // LogsUnmarshaler deserializes the message body.
  26. type LogsUnmarshaler interface {
  27. // Unmarshal deserializes the message body into traces.
  28. Unmarshal([]byte) (plog.Logs, error)
  29. // Encoding of the serialized messages.
  30. Encoding() string
  31. }
  32. type LogsUnmarshalerWithEnc interface {
  33. LogsUnmarshaler
  34. // WithEnc sets the character encoding (UTF-8, GBK, etc.) of the unmarshaler.
  35. WithEnc(string) (LogsUnmarshalerWithEnc, error)
  36. }
  37. // defaultTracesUnmarshalers returns map of supported encodings with TracesUnmarshaler.
  38. func defaultTracesUnmarshalers() map[string]TracesUnmarshaler {
  39. otlpPb := newPdataTracesUnmarshaler(&ptrace.ProtoUnmarshaler{}, defaultEncoding)
  40. jaegerProto := jaegerProtoSpanUnmarshaler{}
  41. jaegerJSON := jaegerJSONSpanUnmarshaler{}
  42. zipkinProto := newPdataTracesUnmarshaler(zipkinv2.NewProtobufTracesUnmarshaler(false, false), "zipkin_proto")
  43. zipkinJSON := newPdataTracesUnmarshaler(zipkinv2.NewJSONTracesUnmarshaler(false), "zipkin_json")
  44. zipkinThrift := newPdataTracesUnmarshaler(zipkinv1.NewThriftTracesUnmarshaler(), "zipkin_thrift")
  45. return map[string]TracesUnmarshaler{
  46. otlpPb.Encoding(): otlpPb,
  47. jaegerProto.Encoding(): jaegerProto,
  48. jaegerJSON.Encoding(): jaegerJSON,
  49. zipkinProto.Encoding(): zipkinProto,
  50. zipkinJSON.Encoding(): zipkinJSON,
  51. zipkinThrift.Encoding(): zipkinThrift,
  52. }
  53. }
  54. func defaultMetricsUnmarshalers() map[string]MetricsUnmarshaler {
  55. otlpPb := newPdataMetricsUnmarshaler(&pmetric.ProtoUnmarshaler{}, defaultEncoding)
  56. return map[string]MetricsUnmarshaler{
  57. otlpPb.Encoding(): otlpPb,
  58. }
  59. }
  60. func defaultLogsUnmarshalers() map[string]LogsUnmarshaler {
  61. otlpPb := newPdataLogsUnmarshaler(&plog.ProtoUnmarshaler{}, defaultEncoding)
  62. raw := newRawLogsUnmarshaler()
  63. text := newTextLogsUnmarshaler()
  64. json := newJSONLogsUnmarshaler()
  65. return map[string]LogsUnmarshaler{
  66. otlpPb.Encoding(): otlpPb,
  67. raw.Encoding(): raw,
  68. text.Encoding(): text,
  69. json.Encoding(): json,
  70. }
  71. }