Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

80 Zeilen
2.8 KiB

  1. // Copyright 2018, OpenCensus 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 exemplar implements support for exemplars. Exemplars are additional
  15. // data associated with each measurement.
  16. //
  17. // Their purpose it to provide an example of the kind of thing
  18. // (request, RPC, trace span, etc.) that resulted in that measurement.
  19. package exemplar
  20. import (
  21. "context"
  22. "time"
  23. )
  24. // Exemplars keys.
  25. const (
  26. KeyTraceID = "trace_id"
  27. KeySpanID = "span_id"
  28. KeyPrefixTag = "tag:"
  29. )
  30. // Exemplar is an example data point associated with each bucket of a
  31. // distribution type aggregation.
  32. type Exemplar struct {
  33. Value float64 // the value that was recorded
  34. Timestamp time.Time // the time the value was recorded
  35. Attachments Attachments // attachments (if any)
  36. }
  37. // Attachments is a map of extra values associated with a recorded data point.
  38. // The map should only be mutated from AttachmentExtractor functions.
  39. type Attachments map[string]string
  40. // AttachmentExtractor is a function capable of extracting exemplar attachments
  41. // from the context used to record measurements.
  42. // The map passed to the function should be mutated and returned. It will
  43. // initially be nil: the first AttachmentExtractor that would like to add keys to the
  44. // map is responsible for initializing it.
  45. type AttachmentExtractor func(ctx context.Context, a Attachments) Attachments
  46. var extractors []AttachmentExtractor
  47. // RegisterAttachmentExtractor registers the given extractor associated with the exemplar
  48. // type name.
  49. //
  50. // Extractors will be used to attempt to extract exemplars from the context
  51. // associated with each recorded measurement.
  52. //
  53. // Packages that support exemplars should register their extractor functions on
  54. // initialization.
  55. //
  56. // RegisterAttachmentExtractor should not be called after any measurements have
  57. // been recorded.
  58. func RegisterAttachmentExtractor(e AttachmentExtractor) {
  59. extractors = append(extractors, e)
  60. }
  61. // AttachmentsFromContext extracts exemplars from the given context.
  62. // Each registered AttachmentExtractor (see RegisterAttachmentExtractor) is called in an
  63. // unspecified order to add attachments to the exemplar.
  64. func AttachmentsFromContext(ctx context.Context) Attachments {
  65. var a Attachments
  66. for _, extractor := range extractors {
  67. a = extractor(ctx, a)
  68. }
  69. return a
  70. }