metrics.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright (c) 2016 Uber Technologies, Inc.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. package jaeger
  21. import (
  22. "github.com/uber/jaeger-lib/metrics"
  23. )
  24. // Metrics is a container of all stats emitted by Jaeger tracer.
  25. type Metrics struct {
  26. // Number of traces started by this tracer as sampled
  27. TracesStartedSampled metrics.Counter `metric:"traces" tags:"state=started,sampled=y"`
  28. // Number of traces started by this tracer as not sampled
  29. TracesStartedNotSampled metrics.Counter `metric:"traces" tags:"state=started,sampled=n"`
  30. // Number of externally started sampled traces this tracer joined
  31. TracesJoinedSampled metrics.Counter `metric:"traces" tags:"state=joined,sampled=y"`
  32. // Number of externally started not-sampled traces this tracer joined
  33. TracesJoinedNotSampled metrics.Counter `metric:"traces" tags:"state=joined,sampled=n"`
  34. // Number of sampled spans started by this tracer
  35. SpansStarted metrics.Counter `metric:"spans" tags:"group=lifecycle,state=started"`
  36. // Number of sampled spans finished by this tracer
  37. SpansFinished metrics.Counter `metric:"spans" tags:"group=lifecycle,state=finished"`
  38. // Number of sampled spans started by this tracer
  39. SpansSampled metrics.Counter `metric:"spans" tags:"group=sampling,sampled=y"`
  40. // Number of not-sampled spans started by this tracer
  41. SpansNotSampled metrics.Counter `metric:"spans" tags:"group=sampling,sampled=n"`
  42. // Number of errors decoding tracing context
  43. DecodingErrors metrics.Counter `metric:"decoding-errors"`
  44. // Number of spans successfully reported
  45. ReporterSuccess metrics.Counter `metric:"reporter-spans" tags:"state=success"`
  46. // Number of spans in failed attempts to report
  47. ReporterFailure metrics.Counter `metric:"reporter-spans" tags:"state=failure"`
  48. // Number of spans dropped due to internal queue overflow
  49. ReporterDropped metrics.Counter `metric:"reporter-spans" tags:"state=dropped"`
  50. // Current number of spans in the reporter queue
  51. ReporterQueueLength metrics.Gauge `metric:"reporter-queue"`
  52. // Number of times the Sampler succeeded to retrieve sampling strategy
  53. SamplerRetrieved metrics.Counter `metric:"sampler" tags:"state=retrieved"`
  54. // Number of times the Sampler succeeded to retrieve and update sampling strategy
  55. SamplerUpdated metrics.Counter `metric:"sampler" tags:"state=updated"`
  56. // Number of times the Sampler failed to update sampling strategy
  57. SamplerUpdateFailure metrics.Counter `metric:"sampler" tags:"state=failure,phase=updating"`
  58. // Number of times the Sampler failed to retrieve sampling strategy
  59. SamplerQueryFailure metrics.Counter `metric:"sampler" tags:"state=failure,phase=query"`
  60. // Number of times baggage was successfully written or updated on spans.
  61. BaggageUpdateSuccess metrics.Counter `metric:"baggage-update" tags:"result=ok"`
  62. // Number of times baggage failed to write or update on spans.
  63. BaggageUpdateFailure metrics.Counter `metric:"baggage-update" tags:"result=err"`
  64. // Number of times baggage was truncated as per baggage restrictions.
  65. BaggageTruncate metrics.Counter `metric:"baggage-truncate"`
  66. // Number of times baggage restrictions were successfully updated.
  67. BaggageRestrictionsUpdateSuccess metrics.Counter `metric:"baggage-restrictions-update" tags:"result=ok"`
  68. // Number of times baggage restrictions failed to update.
  69. BaggageRestrictionsUpdateFailure metrics.Counter `metric:"baggage-restrictions-update" tags:"result=err"`
  70. }
  71. // NewMetrics creates a new Metrics struct and initializes it.
  72. func NewMetrics(factory metrics.Factory, globalTags map[string]string) *Metrics {
  73. m := &Metrics{}
  74. metrics.Init(m, factory.Namespace("jaeger", nil), globalTags)
  75. return m
  76. }
  77. // NewNullMetrics creates a new Metrics struct that won't report any metrics.
  78. func NewNullMetrics() *Metrics {
  79. return NewMetrics(metrics.NullFactory, nil)
  80. }