serializer.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2022 The OpenZipkin Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package reporter
  15. import (
  16. "encoding/json"
  17. "github.com/openzipkin/zipkin-go/model"
  18. )
  19. // SpanSerializer describes the methods needed for allowing to set Span encoding
  20. // type for the various Zipkin transports.
  21. type SpanSerializer interface {
  22. Serialize([]*model.SpanModel) ([]byte, error)
  23. ContentType() string
  24. }
  25. // JSONSerializer implements the default JSON encoding SpanSerializer.
  26. type JSONSerializer struct{}
  27. // Serialize takes an array of Zipkin SpanModel objects and returns a JSON
  28. // encoding of it.
  29. func (JSONSerializer) Serialize(spans []*model.SpanModel) ([]byte, error) {
  30. return json.Marshal(spans)
  31. }
  32. // ContentType returns the ContentType needed for this encoding.
  33. func (JSONSerializer) ContentType() string {
  34. return "application/json"
  35. }