Skip to content

Commit

Permalink
Add GetLightStepReporterID helper (#141)
Browse files Browse the repository at this point in the history
* Add GetLightStepReporterID helper

* Test three cases
  • Loading branch information
jmacd authored Jan 17, 2018
1 parent c9dcbe5 commit f9f54d4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tracer_0_14._test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/lightstep/lightstep-tracer-go/lightstepfakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
opentracing "github.com/opentracing/opentracing-go"
)

var _ = Describe("Tracerv0_14", func() {
Expand Down Expand Up @@ -71,4 +72,12 @@ var _ = Describe("Tracerv0_14", func() {
Expect(err).ToNot(HaveOccurred())
})
})

Describe("provides its ReporterID", func() {
It("is non-zero", func() {
rid, err := lightstep.GetLightStepReporterID(opentracing.Tracer(tracer))
Expect(err).To(BeNil())
Expect(rid).To(Not(BeZero()))
})
})
})
12 changes: 12 additions & 0 deletions tracer_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ func CloseTracer(tracer opentracing.Tracer) error {
return newEventUnsupportedTracer(tracer)
}
}

// GetLightStepReporterID returns the currently configured Reporter ID.
func GetLightStepReporterID(tracer opentracing.Tracer) (uint64, error) {
switch lsTracer := tracer.(type) {
case *tracerImpl:
return lsTracer.reporterID, nil
case *tracerv0_14:
return GetLightStepReporterID(lsTracer.Tracer)
default:
return 0, newEventUnsupportedTracer(tracer)
}
}
33 changes: 33 additions & 0 deletions tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/lightstep/lightstep-tracer-go/lightstepfakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
opentracing "github.com/opentracing/opentracing-go"
)

var _ = Describe("Tracer", func() {
Expand Down Expand Up @@ -284,4 +285,36 @@ var _ = Describe("Tracer", func() {
Expect(span.Finish).ToNot(Panic())
})
})

Describe("provides its ReporterID", func() {
BeforeEach(func() {
opts = Options{
AccessToken: accessToken,
ConnFactory: fakeConn,
Recorder: nil,
}
})

It("is non-zero", func() {
rid, err := GetLightStepReporterID(tracer)
Expect(err).To(BeNil())
Expect(rid).To(Not(BeZero()))
})
})
})

var _ = Describe("UnsupportedTracer", func() {
type unsupportedTracer struct {
opentracing.Tracer
}

tracer := unsupportedTracer{}

Describe("has no ReporterID", func() {
It("is an error", func() {
rid, err := GetLightStepReporterID(tracer)
Expect(err).To(Not(BeNil()))
Expect(rid).To(BeZero())
})
})
})

0 comments on commit f9f54d4

Please sign in to comment.