open-telemetry / open-telemetry/opentelemetry-python

Time units are underdocumented in the API

Open
#4,193 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
2.6k
Forks
1k
Avg merge
4d 15h
Merged PRs (30d)
19

Description

Describe your environment

(not relevant)

What happened?

It is noted in the OpenTracing shim documentation that OTel internally uses an int of nanoseconds since epoch to represent time values:

https://github.com/open-telemetry/opentelemetry-python/blob/0c9c624327cddf046f1170add4818b805b7b7b30/shim/opentelemetry-opentracing-shim/src/opentelemetry/shim/opentracing_shim/__init__.py#L53-L59

However, the units are not described when working with time values in the API.

Steps to Reproduce

I will list the examples that I know of:

opentelemetry.trace.Tracer.start_span and opentelemetry.trace.Tracer.start_as_current_span:

https://github.com/open-telemetry/opentelemetry-python/blob/0c9c624327cddf046f1170add4818b805b7b7b30/opentelemetry-api/src/opentelemetry/trace/__init__.py#L327

https://github.com/open-telemetry/opentelemetry-python/blob/0c9c624327cddf046f1170add4818b805b7b7b30/opentelemetry-api/src/opentelemetry/trace/__init__.py#L400

opentelemetry.trace.span.Span.end: (this also fails to document the end_time argument)

https://github.com/open-telemetry/opentelemetry-python/blob/0c9c624327cddf046f1170add4818b805b7b7b30/opentelemetry-api/src/opentelemetry/trace/span.py#L62-L64

Expected Result

I would expect to understand how my time values ought to be represented by reading the API documentation.

Actual Result

The relevant units are not mentioned in the documentation and I must find out about them by other means (reading other parts of the documentation; searching on Stack Overflow; etc.)

Additional context

I have considered the possibility that these units are left intentionally unspecified in order that subclasses of Tracer and Span might be free to use their own representation of time. However, in this case I don't understand the motivation of requiring that this type must be int.

Would you like to implement a fix?

Yes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the docstrings for Tracer.start_span and Tracer.start_as_current_span in opentelemetry-api/src/opentelemetry/trace/init.py, then Span.end in opentelemetry-api/src/opentelemetry/trace/span.py. Compare them with the time-unit note in the OpenTracing shim and document the representation and end_time units consistently in the API documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.