Skip to content

Type Inconsistency: capture_span() #2283

Open
@Masterdanielsan

Description

@Masterdanielsan

Describe the bug:

capture_span() types start as int instead of float

To Reproduce

  1. apm_client.start_transaction()
  2. t0 = time.time()
  3. do_something()
  4. t1 = time.time()
  5. dur = t1-t0
  6. do_something_else()
  7. span = elasticapm.capture_span(start=int(t0), duration=dur)
  8. with span as s: pass
  9. apm_client.end_transaction()
  10. Note that span will not fall in transaction time frame correctly.

Environment (please complete the following information)

  • OS: mac
  • Python version: 3.12.10
  • Framework and version: FastApi 0.111.1
  • APM Server version: 6.23.0
  • Agent version: N/A

Additional context

elasticapm.capture_span() takes an optional argument start, which is typed to be an int. This works well enough with a time.time() float, but if you are using mypy, you will realize that it needs an int. Only problem is that capture_span() passes start to Span(BaseSpan), which calls super().__init__() which initializes start as a float, passing it through time_to_perf_counter(start). This method fails miserably with an int representation of time.time().

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions