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

[WIP] Span name provider #5

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/faraday/tracer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
require 'uri'
require 'faraday'
require 'opentracing'

module Faraday
class Tracer < Faraday::Middleware
MethodOnly = ->(env) { env[:method].to_s.upcase }
MethodWithHost = ->(env) { "#{env[:method].to_s.upcase} #{URI(env[:url].to_s).host}".strip }

# Create a new Faraday Tracer middleware.
#
# @param app The faraday application/middlewares stack.
Expand All @@ -13,15 +17,16 @@ class Tracer < Faraday::Middleware
# is called.
# @param errors [Array<Class>] An array of error classes to be captured by the tracer
# as errors. Errors are **not** muted by the middleware.
def initialize(app, span: nil, tracer: OpenTracing.global_tracer, errors: [StandardError])
def initialize(app, span: nil, tracer: OpenTracing.global_tracer, errors: [StandardError], span_name_provider: MethodWithHost)
super(app)
@tracer = tracer
@parent_span = span
@errors = errors
@span_name_provider = span_name_provider
end

def call(env)
span = @tracer.start_span(env[:method].to_s.upcase,
span = @tracer.start_span(@span_name_provider.call(env),
child_of: @parent_span.respond_to?(:call) ? @parent_span.call : @parent_span,
tags: {
'component' => 'faraday',
Expand Down