Exemple #1
0
func (z *zipkin) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
	defer next(rw, r)
	if !z.zipkinEnabled {
		return
	}
	router_http.SetB3Headers(r, z.logger)

	if !contains(*z.headersToLog, router_http.B3TraceIdHeader) {
		*z.headersToLog = append(*z.headersToLog, router_http.B3TraceIdHeader)
	}

	if !contains(*z.headersToLog, router_http.B3SpanIdHeader) {
		*z.headersToLog = append(*z.headersToLog, router_http.B3SpanIdHeader)
	}

	if !contains(*z.headersToLog, router_http.B3ParentSpanIdHeader) {
		*z.headersToLog = append(*z.headersToLog, router_http.B3ParentSpanIdHeader)
	}
}
	})

	Describe("SetB3Headers", func() {
		var (
			logger lager.Logger
			req    *http.Request
		)

		BeforeEach(func() {
			var err error
			req, err = http.NewRequest("GET", "test.endpoint", nil)
			Expect(err).ToNot(HaveOccurred())
		})

		JustBeforeEach(func() {
			commonhttp.SetB3Headers(req, logger)
		})

		Context("when logger is set", func() {
			BeforeEach(func() {
				logger = lagertest.NewTestLogger("headers-test")
			})

			It("generates a new b3 span id", func() {
				reqID := req.Header.Get(commonhttp.B3SpanIdHeader)
				Expect(reqID).ToNot(BeEmpty())
				Expect(reqID).To(MatchRegexp(b3_id_regex))
			})

			Context("when X-B3-TraceId is not set", func() {
				It("generates a new b3 id and sets the X-B3-TraceId header and X-B3-SpanId to the same value", func() {