Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should omit ParentSpanId header for root spans #115

Closed
sullerandras opened this issue Aug 31, 2017 · 2 comments · Fixed by #166
Closed

Should omit ParentSpanId header for root spans #115

sullerandras opened this issue Aug 31, 2017 · 2 comments · Fixed by #166

Comments

@sullerandras
Copy link

There are services which throw error when an empty X-B3-ParentSpanId header sent with the HTTP request.

From the openzipkin specification:

The X-B3-ParentSpanId header must be present on a child span and absent on the root span.

How to reproduce

conn = Faraday.new() do |faraday|
  faraday.use ZipkinTracer::FaradayHandler, 'service_name'
  faraday.request :url_encoded
  faraday.adapter Faraday.default_adapter
end
conn.get('http://logs-01.loggly.com/inputs/TOKEN/tag/http/')

Result is 400 Bad request.

If we don't send tracing headers, the response is the expected 403 Invalid API key:

conn = Faraday.new() do |faraday|
  faraday.request :url_encoded
  faraday.adapter Faraday.default_adapter
end
conn.get('http://logs-01.loggly.com/inputs/TOKEN/tag/http/')

Workaround

The only workaround i found so far is to monkey patch FaradayHandler with unless trace_id.send(method).to_s.empty? as below:

require 'zipkin-tracer/faraday/zipkin-tracer'
module ZipkinTracer
  class FaradayHandler < ::Faraday::Middleware
    def call(env)
      trace_id = TraceGenerator.new.next_trace_id
      TraceContainer.with_trace_id(trace_id) do
        b3_headers.each do |method, header|
          env[:request_headers][header] = trace_id.send(method).to_s unless trace_id.send(method).to_s.empty?
        end
        if Trace.tracer && trace_id.sampled?
          trace!(env, trace_id)
        else
          @app.call(env)
        end
      end
    end
  end
end
@codefromthecrypt
Copy link
Member

codefromthecrypt commented Aug 31, 2017 via email

@sullerandras
Copy link
Author

sullerandras commented Aug 31, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants