Skip to content

Conversation

@keith-decker
Copy link
Contributor

Description

Add duration and token metrics to LLMInvocation traces.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Unit tests show metrics exporting.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

return time.time_ns()


def _get_span_start_time_ns(span: Optional[Span]) -> Optional[int]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally measure the durations separately with default_timer() which is monotonic clock and more accurate when absolute timestamps are not needed. https://github.com/search?q=repo%3Aopen-telemetry%2Fopentelemetry-python-contrib%20default_timer&type=code

It would also work even if the Tracing SDK is not set up and start_time can't be read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that led me down a rabbit hole of monotonic clocks for duration versus wall clocks for times. Interesting stuff.

I used to calculate the duration based on the span start. That used a wall clock based on the tracer setting it and metrics should use the monotonic clock, I had to add a property and set it on start_llm.

Take a look at these changes and let me know if you think they are too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants