spandex-project / spandex

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

When using a struct to initialize Span.new(), some values are lost. #17

Closed zachdaniel closed 7 years ago

zachdaniel commented 7 years ago

@driv3r When we use a struct, it will always have all struct fields. This breaks the span inheritance which relies on the keys not being there:

    core = %Span{
      id:       default_if_blank(map, :id, &Utils.next_id/0),
      start:    default_if_blank(map, :start, &Utils.now/0),
      env:      default_if_blank(map, :env, &default_env/0),
      service:  default_if_blank(map, :service, &default_service/0),
      resource: default_if_blank(map, :resource, fn -> Map.get(map, :name, @default) end),
    }

    core
    |> Map.put(:type, default_if_blank(map, :type, fn -> default_type(core.service) end))
    |> Map.merge(Map.drop(map, [:id, :env, :service, :resource, :type])) # <- Map.drop(%Span{}, ...) this overwrites any values we just set.
coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 62.284% when pulling d97ce3106fb973e009fb400f59a2a8ad603b2580 on fix-default-bugs into 6a8fa98ef528b3910f82e67c233926c7ada3642c on master.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 62.284% when pulling 67996af9a2da0af6cd5e69112f585419e3059864 on fix-default-bugs into 6a8fa98ef528b3910f82e67c233926c7ada3642c on master.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 62.284% when pulling 67996af9a2da0af6cd5e69112f585419e3059864 on fix-default-bugs into 6a8fa98ef528b3910f82e67c233926c7ada3642c on master.