diff --git a/README.md b/README.md index 38d76b07..2eb1e83c 100644 --- a/README.md +++ b/README.md @@ -63,19 +63,28 @@ The tracer emits a number of different metrics, defined in tag-based metric names, e.g. instead of `statsd`-style string names like `counters.my-service.jaeger.spans.started.sampled`, the metrics are defined by a short name and a collection of key/value tags, for -example: `name:traces, state:started, sampled:true`. +example: `name:jaeger.traces, state:started, sampled:y`. See [metrics.go](./metrics.go) +file for the full list and descriptions of emitted metrics. -The monitoring backend is represented by the -[StatsReporter](stats_reporter.go) interface. An implementation -of that interface should be passed to the `New` method during -tracer initialization: +The monitoring backend is represented by the `metrics.Factory` interface from package +[`"github.com/uber/jaeger-lib/metrics"`](github.com/uber/jaeger-lib/metrics). An implementation +of that interface can be passed as an option to either the Configuration object or the Tracer +constructor, for example: ```go - stats := // create StatsReporter implementation - tracer := config.Tracing.New("your-service-name", stats) +import ( + "github.com/uber/jaeger-client-go/config" + "github.com/uber/jaeger-lib/metrics/prometheus" +) + + metricsFactory := prometheus.New() + tracer, closer, err := new(config.Configuration).New( + "your-service-name", + config.Metrics(metricsFactory), + ) ``` -By default, a no-op `NullStatsReporter` is used. +By default, a no-op `metrics.NullFactory` is used. ### Logging @@ -143,18 +152,15 @@ are available: ### Baggage Injection -The OpenTracing spec allows for [baggage](https://github.com/opentracing/specification/blob/master/specification.md#set-a-baggage-item), -which are key value pairs that are added to the span context and propagated -throughout the trace. -An external process can inject baggage by setting the special -HTTP Header `jaeger-baggage` on a request +The OpenTracing spec allows for [baggage][baggage], which are key value pairs that are added +to the span context and propagated throughout the trace. An external process can inject baggage +by setting the special HTTP Header `jaeger-baggage` on a request: ```sh curl -H "jaeger-baggage: key1=value1, key2=value2" http://myhost.com ``` -Baggage can also be programatically set inside your service by doing -the following +Baggage can also be programatically set inside your service: ```go if span := opentracing.SpanFromContext(ctx); span != nil { @@ -229,3 +235,4 @@ However it is not the default propagation format, see [here](zipkin/README.md#Ne [cov]: https://codecov.io/gh/jaegertracing/jaeger-client-go [ot-img]: https://img.shields.io/badge/OpenTracing--1.0-enabled-blue.svg [ot-url]: http://opentracing.io +[baggage]: https://github.com/opentracing/specification/blob/master/specification.md#set-a-baggage-item diff --git a/baggage_setter_test.go b/baggage_setter_test.go index 0e48b6d9..c0454edf 100644 --- a/baggage_setter_test.go +++ b/baggage_setter_test.go @@ -53,11 +53,11 @@ func TestTruncateBaggage(t *testing.T) { testutils.AssertCounterMetrics(t, factory, testutils.ExpectedMetric{ - Name: "jaeger.baggage-truncate", + Name: "jaeger.baggage_truncations", Value: 1, }, testutils.ExpectedMetric{ - Name: "jaeger.baggage-update", + Name: "jaeger.baggage_updates", Tags: map[string]string{"result": "ok"}, Value: 1, }, @@ -85,7 +85,7 @@ func TestInvalidBaggage(t *testing.T) { testutils.AssertCounterMetrics(t, factory, testutils.ExpectedMetric{ - Name: "jaeger.baggage-update", + Name: "jaeger.baggage_updates", Tags: map[string]string{"result": "err"}, Value: 1, }, diff --git a/config/config_test.go b/config/config_test.go index a6c1f8e8..cff5bf32 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -218,7 +218,7 @@ func TestBaggageRestrictionsConfig(t *testing.T) { require.NoError(t, err) defer closer.Close() - metricName := "jaeger.baggage-restrictions-update" + metricName := "jaeger.baggage_restrictions_updates" metricTags := map[string]string{"result": "err"} key := metrics.GetKey(metricName, metricTags, "|", "=") for i := 0; i < 100; i++ { diff --git a/crossdock/docker-compose.yml b/crossdock/docker-compose.yml index bbbc371e..6aa2964c 100644 --- a/crossdock/docker-compose.yml +++ b/crossdock/docker-compose.yml @@ -40,9 +40,9 @@ services: image: jaegertracing/xdock-java ports: - "8080-8082" +# Udp sender needs to know agent's address depends_on: -# Udp sender needs to know agent's address - - jaeger-agent + - jaeger-agent python: image: jaegertracing/xdock-py diff --git a/glide.lock b/glide.lock index 912d2c54..9ad7a140 100644 --- a/glide.lock +++ b/glide.lock @@ -1,10 +1,14 @@ -hash: 4abcf83a509c003112c27a131eafde7d4fa11aeb17decb43ac0746593890ff85 -updated: 2017-08-22T14:21:39.649697305-04:00 +hash: af5e193de27f73f5a8cef66ae2f0c013bcb9e48ecd69db4a595221f88ba99a71 +updated: 2017-11-21T19:49:03.248636345-05:00 imports: - name: github.com/apache/thrift version: b2a4d4ae21c789b689dd162deb819665567f481c subpackages: - lib/go/thrift +- name: github.com/beorn7/perks + version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 + subpackages: + - quantile - name: github.com/codahale/hdrhistogram version: f8ad88b59a584afeee9d334eff879b104439117b - name: github.com/crossdock/crossdock-go @@ -13,18 +17,44 @@ imports: - assert - require - name: github.com/davecgh/go-spew - version: adab96458c51a58dc1783b3335dcce5461522e75 + version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: - spew +- name: github.com/golang/protobuf + version: 7cc19b78d562895b13596ddce7aafb59dd789318 + subpackages: + - proto +- name: github.com/matttproud/golang_protobuf_extensions + version: c12348ce28de40eed0136aa2b644d0ee0650e56c + subpackages: + - pbutil - name: github.com/opentracing/opentracing-go version: 1949ddbfd147afd4d964a9f00b24eb291e0e7c38 subpackages: - ext - log - name: github.com/pmezard/go-difflib - version: 792786c7400a136282c1664665ae0a8db921c6c2 + version: d8ed2627bdf02c080bf22230dbb337003b7aba2d subpackages: - difflib +- name: github.com/prometheus/client_golang + version: c5b7fccd204277076155f10851dad72b76a49317 + subpackages: + - prometheus +- name: github.com/prometheus/client_model + version: 6f3806018612930941127f2a7c6c453ba2c527d2 + subpackages: + - go +- name: github.com/prometheus/common + version: 49fee292b27bfff7f354ee0f64e1bc4850462edf + subpackages: + - expfmt + - internal/bitbucket.org/ww/goautoneg + - model +- name: github.com/prometheus/procfs + version: a1dba9ce8baed984a2495b658c82687f8157b98f + subpackages: + - xfs - name: github.com/stretchr/testify version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: @@ -32,14 +62,17 @@ imports: - require - suite - name: github.com/uber-go/atomic - version: 0c9e689d64f004564b79d9a663634756df322902 + version: 8474b86a5a6f79c443ce4b2992817ff32cf208b8 + subpackages: + - utils - name: github.com/uber/jaeger-lib - version: 575c678b2873b62aaadd0fa5817a2aeb3155dc4d + version: c48167d9cae5887393dd5e61efd06a4a48b7fbb3 subpackages: - metrics + - metrics/prometheus - metrics/testutils - name: github.com/uber/tchannel-go - version: a7ad9ecb640b5f10a0395b38d6319175172b3ab2 + version: cc230a2942d078a8b01f4a79895dad62e6c572f1 subpackages: - atomic - internal/argreader @@ -52,18 +85,19 @@ imports: - trand - typed - name: go.uber.org/atomic - version: 4e336646b2ef9fc6e47be8e21594178f98e5ebcf + version: 8474b86a5a6f79c443ce4b2992817ff32cf208b8 +- name: go.uber.org/multierr + version: 3c4937480c32f4c13a875a1829af76c98ca3d40a - name: go.uber.org/zap - version: 9cabc84638b70e564c3dab2766efcb1ded2aac9f + version: 35aad584952c3e7020db7b839f6b102de6271f89 subpackages: - buffer - internal/bufferpool - internal/color - internal/exit - - internal/multierror - zapcore - name: golang.org/x/net - version: f5079bd7f6f74e23c4d65efa0f4ce14cbd6a3c0f + version: a337091b0525af65de94df2eb7e98bd9962dcbe2 subpackages: - bpf - context diff --git a/glide.yaml b/glide.yaml index fa30bded..c0b6bcbf 100644 --- a/glide.yaml +++ b/glide.yaml @@ -29,6 +29,9 @@ import: - suite - package: github.com/crossdock/crossdock-go - package: github.com/uber/jaeger-lib - version: ^1.0.0 + version: ^1.2.1 subpackages: - metrics +testImport: +- package: github.com/prometheus/client_golang + version: v0.8.0 diff --git a/internal/baggage/remote/restriction_manager_test.go b/internal/baggage/remote/restriction_manager_test.go index 6d5b865f..c0091eb4 100644 --- a/internal/baggage/remote/restriction_manager_test.go +++ b/internal/baggage/remote/restriction_manager_test.go @@ -121,7 +121,7 @@ func TestNewRemoteRestrictionManager(t *testing.T) { testutils.AssertCounterMetrics(t, factory, testutils.ExpectedMetric{ - Name: "jaeger.baggage-restrictions-update", + Name: "jaeger.baggage_restrictions_updates", Tags: map[string]string{"result": "ok"}, Value: 1, }, @@ -147,7 +147,7 @@ func TestDenyBaggageOnInitializationFailure(t *testing.T) { ) require.False(t, mgr.isReady()) - metricName := "jaeger.baggage-restrictions-update" + metricName := "jaeger.baggage_restrictions_updates" metricTags := map[string]string{"result": "err"} key := metrics.GetKey(metricName, metricTags, "|", "=") for i := 0; i < 100; i++ { diff --git a/metrics.go b/metrics.go index 93f24478..8c0e6321 100644 --- a/metrics.go +++ b/metrics.go @@ -33,63 +33,61 @@ type Metrics struct { TracesJoinedNotSampled metrics.Counter `metric:"traces" tags:"state=joined,sampled=n"` // Number of sampled spans started by this tracer - SpansStarted metrics.Counter `metric:"spans" tags:"group=lifecycle,state=started"` + SpansStartedSampled metrics.Counter `metric:"started_spans" tags:"sampled=y"` - // Number of sampled spans finished by this tracer - SpansFinished metrics.Counter `metric:"spans" tags:"group=lifecycle,state=finished"` + // Number of unsampled spans started by this tracer + SpansStartedNotSampled metrics.Counter `metric:"started_spans" tags:"sampled=n"` - // Number of sampled spans started by this tracer - SpansSampled metrics.Counter `metric:"spans" tags:"group=sampling,sampled=y"` - - // Number of not-sampled spans started by this tracer - SpansNotSampled metrics.Counter `metric:"spans" tags:"group=sampling,sampled=n"` + // Number of spans finished by this tracer + SpansFinished metrics.Counter `metric:"finished_spans"` // Number of errors decoding tracing context - DecodingErrors metrics.Counter `metric:"decoding-errors"` + DecodingErrors metrics.Counter `metric:"span_context_decoding_errors"` // Number of spans successfully reported - ReporterSuccess metrics.Counter `metric:"reporter-spans" tags:"state=success"` + ReporterSuccess metrics.Counter `metric:"reporter_spans" tags:"result=ok"` - // Number of spans in failed attempts to report - ReporterFailure metrics.Counter `metric:"reporter-spans" tags:"state=failure"` + // Number of spans not reported due to a Sender failure + ReporterFailure metrics.Counter `metric:"reporter_spans" tags:"result=err"` // Number of spans dropped due to internal queue overflow - ReporterDropped metrics.Counter `metric:"reporter-spans" tags:"state=dropped"` + ReporterDropped metrics.Counter `metric:"reporter_spans" tags:"result=dropped"` // Current number of spans in the reporter queue - ReporterQueueLength metrics.Gauge `metric:"reporter-queue"` + ReporterQueueLength metrics.Gauge `metric:"reporter_queue_length"` // Number of times the Sampler succeeded to retrieve sampling strategy - SamplerRetrieved metrics.Counter `metric:"sampler" tags:"state=retrieved"` + SamplerRetrieved metrics.Counter `metric:"sampler_queries" tags:"result=ok"` + + // Number of times the Sampler failed to retrieve sampling strategy + SamplerQueryFailure metrics.Counter `metric:"sampler_queries" tags:"result=err"` // Number of times the Sampler succeeded to retrieve and update sampling strategy - SamplerUpdated metrics.Counter `metric:"sampler" tags:"state=updated"` + SamplerUpdated metrics.Counter `metric:"sampler_updates" tags:"result=ok"` // Number of times the Sampler failed to update sampling strategy - SamplerUpdateFailure metrics.Counter `metric:"sampler" tags:"state=failure,phase=updating"` - - // Number of times the Sampler failed to retrieve sampling strategy - SamplerQueryFailure metrics.Counter `metric:"sampler" tags:"state=failure,phase=query"` + SamplerUpdateFailure metrics.Counter `metric:"sampler_updates" tags:"result=err"` // Number of times baggage was successfully written or updated on spans. - BaggageUpdateSuccess metrics.Counter `metric:"baggage-update" tags:"result=ok"` + BaggageUpdateSuccess metrics.Counter `metric:"baggage_updates" tags:"result=ok"` // Number of times baggage failed to write or update on spans. - BaggageUpdateFailure metrics.Counter `metric:"baggage-update" tags:"result=err"` + BaggageUpdateFailure metrics.Counter `metric:"baggage_updates" tags:"result=err"` // Number of times baggage was truncated as per baggage restrictions. - BaggageTruncate metrics.Counter `metric:"baggage-truncate"` + BaggageTruncate metrics.Counter `metric:"baggage_truncations"` // Number of times baggage restrictions were successfully updated. - BaggageRestrictionsUpdateSuccess metrics.Counter `metric:"baggage-restrictions-update" tags:"result=ok"` + BaggageRestrictionsUpdateSuccess metrics.Counter `metric:"baggage_restrictions_updates" tags:"result=ok"` // Number of times baggage restrictions failed to update. - BaggageRestrictionsUpdateFailure metrics.Counter `metric:"baggage-restrictions-update" tags:"result=err"` + BaggageRestrictionsUpdateFailure metrics.Counter `metric:"baggage_restrictions_updates" tags:"result=err"` } // NewMetrics creates a new Metrics struct and initializes it. func NewMetrics(factory metrics.Factory, globalTags map[string]string) *Metrics { m := &Metrics{} + // TODO the namespace "jaeger" should be configurable (e.g. in all-in-one "jaeger-client" would make more sense) metrics.Init(m, factory.Namespace("jaeger", nil), globalTags) return m } diff --git a/metrics/prometheus/metrics_test.go b/metrics/prometheus/metrics_test.go new file mode 100644 index 00000000..3abd0904 --- /dev/null +++ b/metrics/prometheus/metrics_test.go @@ -0,0 +1,36 @@ +// Copyright (c) 2017 Uber Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package prometheus_test + +import ( + "testing" + + "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/require" + jprom "github.com/uber/jaeger-lib/metrics/prometheus" + + "github.com/uber/jaeger-client-go" +) + +// TestNewPrometheusMetrics ensures that the metrics do not have conflicting dimensions and will work with Prometheus. +func TestNewPrometheusMetrics(t *testing.T) { + tags := map[string]string{"lib": "jaeger"} + + factory := jprom.New(jprom.WithRegisterer(prometheus.NewPedanticRegistry())) + m := jaeger.NewMetrics(factory, tags) + + require.NotNil(t, m.SpansStartedSampled, "counter not initialized") + require.NotNil(t, m.ReporterQueueLength, "gauge not initialized") +} diff --git a/metrics_test.go b/metrics_test.go index 1a0274eb..09dbb372 100644 --- a/metrics_test.go +++ b/metrics_test.go @@ -23,26 +23,24 @@ import ( ) func TestNewMetrics(t *testing.T) { - tags := map[string]string{"lib": "jaeger"} - factory := metrics.NewLocalFactory(0) - m := NewMetrics(factory, tags) + m := NewMetrics(factory, map[string]string{"lib": "jaeger"}) - require.NotNil(t, m.SpansSampled, "counter not initialized") + require.NotNil(t, m.SpansStartedSampled, "counter not initialized") require.NotNil(t, m.ReporterQueueLength, "gauge not initialized") - m.SpansSampled.Inc(1) + m.SpansStartedSampled.Inc(1) m.ReporterQueueLength.Update(11) testutils.AssertCounterMetrics(t, factory, testutils.ExpectedMetric{ - Name: "jaeger.spans", - Tags: map[string]string{"group": "sampling", "lib": "jaeger", "sampled": "y"}, + Name: "jaeger.started_spans", + Tags: map[string]string{"lib": "jaeger", "sampled": "y"}, Value: 1, }, ) testutils.AssertGaugeMetrics(t, factory, testutils.ExpectedMetric{ - Name: "jaeger.reporter-queue", + Name: "jaeger.reporter_queue_length", Tags: map[string]string{"lib": "jaeger"}, Value: 11, }, diff --git a/propagation_test.go b/propagation_test.go index 0cc62753..08724db5 100644 --- a/propagation_test.go +++ b/propagation_test.go @@ -119,9 +119,8 @@ func TestSpanPropagator(t *testing.T) { } testutils.AssertCounterMetrics(t, metricsFactory, []testutils.ExpectedMetric{ - {Name: "jaeger.spans", Tags: map[string]string{"group": "sampling", "sampled": "y"}, Value: 1 + 2*len(tests)}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "started"}, Value: 1 + 2*len(tests)}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "finished"}, Value: 1 + len(tests)}, + {Name: "jaeger.started_spans", Tags: map[string]string{"sampled": "y"}, Value: 1 + 2*len(tests)}, + {Name: "jaeger.finished_spans", Value: 1 + len(tests)}, {Name: "jaeger.traces", Tags: map[string]string{"state": "started", "sampled": "y"}, Value: 1}, {Name: "jaeger.traces", Tags: map[string]string{"state": "joined", "sampled": "y"}, Value: len(tests)}, }...) @@ -152,7 +151,7 @@ func TestDecodingError(t *testing.T) { _, err := tracer.Extract(opentracing.HTTPHeaders, tmc) assert.Error(t, err) - testutils.AssertCounterMetrics(t, metricsFactory, testutils.ExpectedMetric{Name: "jaeger.decoding-errors", Value: 1}) + testutils.AssertCounterMetrics(t, metricsFactory, testutils.ExpectedMetric{Name: "jaeger.span_context_decoding_errors", Value: 1}) } func TestBaggagePropagationHTTP(t *testing.T) { diff --git a/reporter_test.go b/reporter_test.go index 77ce0f86..b4146f19 100644 --- a/reporter_test.go +++ b/reporter_test.go @@ -97,8 +97,8 @@ func (s *reporterSuite) TestRootSpanTags() { mTestutils.AssertCounterMetrics(s.T(), s.metricsFactory, mTestutils.ExpectedMetric{ - Name: "jaeger.reporter-spans", - Tags: map[string]string{"state": "success"}, + Name: "jaeger.reporter_spans", + Tags: map[string]string{"result": "ok"}, Value: 1, }, ) @@ -123,8 +123,8 @@ func (s *reporterSuite) TestClientSpan() { mTestutils.AssertCounterMetrics(s.T(), s.metricsFactory, mTestutils.ExpectedMetric{ - Name: "jaeger.reporter-spans", - Tags: map[string]string{"state": "success"}, + Name: "jaeger.reporter_spans", + Tags: map[string]string{"result": "ok"}, Value: 2, }, ) @@ -213,8 +213,8 @@ func testRemoteReporter( assert.Equal(t, "downstream", *tag.VStr) mTestutils.AssertCounterMetrics(t, metricsFactory, []mTestutils.ExpectedMetric{ - {Name: "jaeger.reporter-spans", Tags: map[string]string{"state": "success"}, Value: 1}, - {Name: "jaeger.reporter-spans", Tags: map[string]string{"state": "failure"}, Value: 0}, + {Name: "jaeger.reporter_spans", Tags: map[string]string{"result": "ok"}, Value: 1}, + {Name: "jaeger.reporter_spans", Tags: map[string]string{"result": "err"}, Value: 0}, }...) } diff --git a/sampler_test.go b/sampler_test.go index d1707254..ae7ab543 100644 --- a/sampler_test.go +++ b/sampler_test.go @@ -317,8 +317,8 @@ func TestRemotelyControlledSampler(t *testing.T) { getSamplingStrategyResponse(sampling.SamplingStrategyType_PROBABILISTIC, testDefaultSamplingProbability)) remoteSampler.updateSampler() mTestutils.AssertCounterMetrics(t, metricsFactory, []mTestutils.ExpectedMetric{ - {Name: "jaeger.sampler", Tags: map[string]string{"state": "retrieved"}, Value: 1}, - {Name: "jaeger.sampler", Tags: map[string]string{"state": "updated"}, Value: 1}, + {Name: "jaeger.sampler_queries", Tags: map[string]string{"result": "ok"}, Value: 1}, + {Name: "jaeger.sampler_updates", Tags: map[string]string{"result": "ok"}, Value: 1}, }...) _, ok = remoteSampler.sampler.(*ProbabilisticSampler) assert.True(t, ok) @@ -429,7 +429,7 @@ func TestRemotelyControlledSampler_updateSampler(t *testing.T) { mTestutils.AssertCounterMetrics(t, metricsFactory, mTestutils.ExpectedMetric{ - Name: "jaeger.sampler" + "|state=updated", Value: 1, + Name: "jaeger.sampler_updates", Tags: map[string]string{"result": "ok"}, Value: 1, }, ) @@ -486,11 +486,7 @@ func TestSamplerQueryError(t *testing.T) { assert.Equal(t, initSampler, sampler.sampler, "Sampler should not have been updated due to query error") mTestutils.AssertCounterMetrics(t, metricsFactory, - mTestutils.ExpectedMetric{ - Name: "jaeger.sampler", - Tags: map[string]string{"phase": "query", "state": "failure"}, - Value: 1, - }, + mTestutils.ExpectedMetric{Name: "jaeger.sampler_queries", Tags: map[string]string{"result": "err"}, Value: 1}, ) } @@ -543,16 +539,8 @@ func TestRemotelyControlledSampler_updateSamplerFromAdaptiveSampler(t *testing.T remoteSampler.updateSampler() mTestutils.AssertCounterMetrics(t, metricsFactory, - mTestutils.ExpectedMetric{ - Name: "jaeger.sampler", - Tags: map[string]string{"state": "retrieved"}, - Value: 3, - }, - mTestutils.ExpectedMetric{ - Name: "jaeger.sampler", - Tags: map[string]string{"state": "updated"}, - Value: 3, - }, + mTestutils.ExpectedMetric{Name: "jaeger.sampler_queries", Tags: map[string]string{"result": "ok"}, Value: 3}, + mTestutils.ExpectedMetric{Name: "jaeger.sampler_updates", Tags: map[string]string{"result": "ok"}, Value: 3}, ) } diff --git a/tracer.go b/tracer.go index 69307ed2..49fb099e 100644 --- a/tracer.go +++ b/tracer.go @@ -348,9 +348,8 @@ func (t *Tracer) startSpanInternal( } } // emit metrics - t.metrics.SpansStarted.Inc(1) if sp.context.IsSampled() { - t.metrics.SpansSampled.Inc(1) + t.metrics.SpansStartedSampled.Inc(1) if newTrace { // We cannot simply check for parentID==0 because in Zipkin model the // server-side RPC span has the exact same trace/span/parent IDs as the @@ -361,7 +360,7 @@ func (t *Tracer) startSpanInternal( t.metrics.TracesJoinedSampled.Inc(1) } } else { - t.metrics.SpansNotSampled.Inc(1) + t.metrics.SpansStartedNotSampled.Inc(1) if newTrace { t.metrics.TracesStartedNotSampled.Inc(1) } else if sp.firstInProcess { diff --git a/tracer_test.go b/tracer_test.go index 631b664c..6c0ea503 100644 --- a/tracer_test.go +++ b/tracer_test.go @@ -90,9 +90,8 @@ func (s *tracerSuite) TestBeginRootSpan() { s.NotNil(ss.duration) testutils.AssertCounterMetrics(s.T(), s.metricsFactory, []testutils.ExpectedMetric{ - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "started"}, Value: 1}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "finished"}, Value: 1}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "sampling", "sampled": "y"}, Value: 1}, + {Name: "jaeger.finished_spans", Value: 1}, + {Name: "jaeger.started_spans", Tags: map[string]string{"sampled": "y"}, Value: 1}, {Name: "jaeger.traces", Tags: map[string]string{"sampled": "y", "state": "started"}, Value: 1}, }...) } @@ -114,10 +113,9 @@ func (s *tracerSuite) TestStartChildSpan() { s.NotNil(sp2.(*Span).duration) sp1.Finish() testutils.AssertCounterMetrics(s.T(), s.metricsFactory, []testutils.ExpectedMetric{ - {Name: "jaeger.spans", Tags: map[string]string{"group": "sampling", "sampled": "y"}, Value: 2}, + {Name: "jaeger.started_spans", Tags: map[string]string{"sampled": "y"}, Value: 2}, {Name: "jaeger.traces", Tags: map[string]string{"sampled": "y", "state": "started"}, Value: 1}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "started"}, Value: 2}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "finished"}, Value: 2}, + {Name: "jaeger.finished_spans", Value: 2}, }...) } @@ -146,10 +144,9 @@ func (s *tracerSuite) TestStartSpanWithMultipleReferences() { sp2.Finish() sp1.Finish() testutils.AssertCounterMetrics(s.T(), s.metricsFactory, []testutils.ExpectedMetric{ - {Name: "jaeger.spans", Tags: map[string]string{"group": "sampling", "sampled": "y"}, Value: 4}, + {Name: "jaeger.started_spans", Tags: map[string]string{"sampled": "y"}, Value: 4}, {Name: "jaeger.traces", Tags: map[string]string{"sampled": "y", "state": "started"}, Value: 3}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "started"}, Value: 4}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "finished"}, Value: 4}, + {Name: "jaeger.finished_spans", Value: 4}, }...) assert.Len(s.T(), sp4.(*Span).references, 3) } @@ -167,10 +164,9 @@ func (s *tracerSuite) TestStartSpanWithOnlyFollowFromReference() { s.NotNil(sp2.(*Span).duration) sp1.Finish() testutils.AssertCounterMetrics(s.T(), s.metricsFactory, []testutils.ExpectedMetric{ - {Name: "jaeger.spans", Tags: map[string]string{"group": "sampling", "sampled": "y"}, Value: 2}, + {Name: "jaeger.started_spans", Tags: map[string]string{"sampled": "y"}, Value: 2}, {Name: "jaeger.traces", Tags: map[string]string{"sampled": "y", "state": "started"}, Value: 1}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "started"}, Value: 2}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "finished"}, Value: 2}, + {Name: "jaeger.finished_spans", Value: 2}, }...) assert.Len(s.T(), sp2.(*Span).references, 1) } @@ -198,9 +194,8 @@ func (s *tracerSuite) TestTraceStartedOrJoinedMetrics() { s.Equal(test.sampled, sp2.Context().(SpanContext).IsSampled()) testutils.AssertCounterMetrics(s.T(), s.metricsFactory, []testutils.ExpectedMetric{ - {Name: "jaeger.spans", Tags: map[string]string{"group": "sampling", "sampled": test.label}, Value: 3}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "started"}, Value: 3}, - {Name: "jaeger.spans", Tags: map[string]string{"group": "lifecycle", "state": "finished"}, Value: 3}, + {Name: "jaeger.started_spans", Tags: map[string]string{"sampled": test.label}, Value: 3}, + {Name: "jaeger.finished_spans", Value: 3}, {Name: "jaeger.traces", Tags: map[string]string{"sampled": test.label, "state": "started"}, Value: 1}, {Name: "jaeger.traces", Tags: map[string]string{"sampled": test.label, "state": "joined"}, Value: 1}, }...) @@ -317,51 +312,6 @@ func TestGen128Bit(t *testing.T) { assert.True(t, traceID.Low != 0) } -func TestHighTraceIDGenerator(t *testing.T) { - id := uint64(12345) - calledGenerator := false - highTraceIDGenerator := func() uint64 { - calledGenerator = true - return id - } - - tracer, tc := NewTracer("x", NewConstSampler(true), NewNullReporter(), TracerOptions.HighTraceIDGenerator(highTraceIDGenerator), TracerOptions.Gen128Bit(true)) - defer tc.Close() - - span := tracer.StartSpan("test", opentracing.ChildOf(emptyContext)) - defer span.Finish() - traceID := span.Context().(SpanContext).TraceID() - assert.Equal(t, id, traceID.High) - assert.True(t, calledGenerator) -} - -// TODO: Remove mockLogger in favor of testutils/logger.go once it is refactored -// from jaeger into jaeger-lib. - -type mockLogger struct { - msg string -} - -func (l *mockLogger) Error(msg string) { - l.msg = msg -} - -func (l *mockLogger) Infof(msg string, args ...interface{}) { -} - -func TestHighTraceIDGeneratorNotGen128Bit(t *testing.T) { - highTraceIDGenerator := func() uint64 { - return 0 - } - logger := &mockLogger{} - NewTracer("x", NewConstSampler(true), NewNullReporter(), TracerOptions.HighTraceIDGenerator(highTraceIDGenerator), TracerOptions.Gen128Bit(false), TracerOptions.Logger(logger)) - msg := "Overriding high trace ID generator but not generating " + - "128 bit trace IDs, consider enabling the \"Gen128Bit\" option" - assert.Equal(t, - msg, - logger.msg) -} - func TestZipkinSharedRPCSpan(t *testing.T) { tracer, tc := NewTracer("x", NewConstSampler(true), NewNullReporter(), TracerOptions.ZipkinSharedRPCSpan(false))