spandex-project/spandex

Spandex.update_span unexpectedly resets :service of the current span

Closed this issue ยท 2 comments

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" ๐Ÿ‘

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.

This is resolved in version 1.6.2