data.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package testdata
  4. import (
  5. "bytes"
  6. "compress/gzip"
  7. "go.opentelemetry.io/collector/pdata/plog"
  8. "go.opentelemetry.io/collector/pdata/pmetric"
  9. "go.opentelemetry.io/collector/pdata/ptrace"
  10. )
  11. func CreateTraceExport() []byte {
  12. out := ptrace.NewTraces()
  13. resources := out.ResourceSpans()
  14. resource := resources.AppendEmpty()
  15. libs := resource.ScopeSpans()
  16. spans := libs.AppendEmpty().Spans()
  17. span := spans.AppendEmpty()
  18. span.SetName("test")
  19. marshaler := ptrace.ProtoMarshaler{}
  20. data, _ := marshaler.MarshalTraces(out)
  21. return data
  22. }
  23. func CreateMetricExport() []byte {
  24. out := pmetric.NewMetrics()
  25. resources := out.ResourceMetrics()
  26. resource := resources.AppendEmpty()
  27. libs := resource.ScopeMetrics()
  28. metrics := libs.AppendEmpty().Metrics()
  29. metric := metrics.AppendEmpty()
  30. metric.SetName("test")
  31. marshaler := pmetric.ProtoMarshaler{}
  32. data, _ := marshaler.MarshalMetrics(out)
  33. return data
  34. }
  35. func CreateLogExport() []byte {
  36. out := plog.NewLogs()
  37. resources := out.ResourceLogs()
  38. resource := resources.AppendEmpty()
  39. libs := resource.ScopeLogs()
  40. logs := libs.AppendEmpty()
  41. logs.LogRecords().AppendEmpty()
  42. marshaler := plog.ProtoMarshaler{}
  43. data, _ := marshaler.MarshalLogs(out)
  44. return data
  45. }
  46. func CreateGZippedLogExport() []byte {
  47. payload := CreateLogExport()
  48. var buf bytes.Buffer
  49. writer := gzip.NewWriter(&buf)
  50. writer.Write(payload)
  51. return buf.Bytes()
  52. }
  53. func CreateTextExport() []byte {
  54. return []byte("this is text")
  55. }