feat(tracing): allow explicit observation start times#1774
Open
ShellWen wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for explicitly setting observation start timestamps (nanoseconds since epoch) when manually creating root and child observations, enabling accurate historical durations for delayed span emission workflows (e.g., replaying OpenTelemetry spans from stored exports).
Changes:
- Extend
start_observation(...)(client + child observations) to accept an optionalstart_time: Optional[int]and forward it to the underlying OpenTelemetry tracer. - Ensure
event-type child observations can use an explicitstart_time(otherwise defaulting totime_ns()). - Add a unit test asserting that provided historical
start_timevalues are preserved on exported spans.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
langfuse/_client/client.py |
Adds start_time to root observation creation and forwards it to _otel_tracer.start_span(...). |
langfuse/_client/span.py |
Adds start_time to child observation creation (including event handling) and forwards it to _otel_tracer.start_span(...). |
tests/unit/test_otel.py |
Adds coverage verifying historical start/end timestamps are preserved for manual root + child observations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds an optional nanosecond
start_timeto manual root and child observations. This makes manual observation creation symmetric withend(end_time=...)and preserves historical durations when an integration emits spans after the underlying work has completedFixes #1377
Type of change
Verification
Checklist
code_review.md..env.templateif needed.Greptile Summary
This PR adds explicit start times for manually created observations. The main changes are:
start_timeto root and child observation APIs.Confidence Score: 5/5
This looks safe to merge.
start_timeis omitted.Reviews (1): Last reviewed commit: "feat(tracing): allow explicit observatio..." | Re-trigger Greptile