spandex-project / spandex

A platform agnostic tracing library
MIT License
333 stars 53 forks source link

Spandex.update_span unexpectedly resets :service of the current span #57

Closed vovayartsev closed 6 years ago

vovayartsev commented 6 years ago

Reproduced in v1.6.1 and edge version from Github.

Let's assume the following:

# config/dev.exs
config :my_app, MyApp.Tracer,
  service: :my_app,

# in the module I'm tracing
@tracer_opts [service: :etl, type: :custom, resource: "MyApp.SalesStatsETL"]

Example 1

MyApp.Tracer.trace "trace_name", @tracer_opts do ... end

OUTCOME: in Datadog there's a trace with service="etl", which is expected 👍

Example 2

MyApp.Tracer.trace "trace_name", @tracer_opts do 
  MyApp.Tracer.update_span(
     sql_query: [query: "SELECT ..", db: "some_db", rows: "42"]
  )
end

OUTCOME: in Datadog there's a trace with service="my_app" 👎 EXPECTED OUTCOME service should remain "etl" since it was not overridden explicitely

Example 3

MyApp.Tracer.trace "trace_name", @tracer_opts do 
  %{service: service} = Core.Tracer.current_span()
  MyApp.Tracer.update_span(
     sql_query: [query: "SELECT ..", db: "some_db", rows: "42"],
     service: service
  )
end

OUTCOME: in Datadog there's a trace with service="etl" 👍

zachdaniel commented 6 years ago

Still a bit too busy to look at this, but from what I can tell this should be a relatively simple bug in Span.update_span/2. I will try and find some time tomorrow to look closer.

zachdaniel commented 6 years ago

This is resolved in version 1.6.2