Add start_time and end_time parameters to OpenTelemetry scope classes#181
Merged
nikhilNava merged 4 commits intomainfrom Feb 25, 2026
Merged
Add start_time and end_time parameters to OpenTelemetry scope classes#181nikhilNava merged 4 commits intomainfrom
nikhilNava merged 4 commits intomainfrom
Conversation
This change implements support for custom start and end times on OpenTelemetry spans, mirroring the Node.js PR #205. Changes include: - Add TimeInput type alias supporting int (nanoseconds), float (seconds), tuple (HrTime), and datetime - Update OpenTelemetryScope base class with start_time and end_time constructor parameters - Add set_end_time() method for setting end time after construction - Update InferenceScope, InvokeAgentScope, ExecuteToolScope, and OutputScope to forward parameters - Add comprehensive unit tests for custom start/end time functionality Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
- Remove unused _wall_clock_start_ms variable - Fix documentation to accurately describe TimeInput accepted formats - Remove unused time import Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add start and end time implementation in Python
Add start_time and end_time parameters to OpenTelemetry scope classes
Feb 24, 2026
Based on user feedback, simplify the start_time/end_time parameters to only accept datetime objects instead of the complex TimeInput union type. This is more Pythonic and consistent with existing code in the LangChain tracer. Changes: - Remove TimeInput type alias - Change start_time/end_time parameters to datetime | None - Add simple _datetime_to_ns() conversion method - Remove unused _time_input_to_ns() and _time_input_to_ms() methods - Update all scope subclasses to use datetime | None - Simplify tests to only use datetime Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for explicit start and end timestamps to OpenTelemetry scope classes, porting functionality from Node.js PR #205. This enables post-hoc telemetry recording where operations complete before spans are created, such as in LangChain callbacks that use run.start_time and run.end_time.
Changes:
- Added
start_timeandend_timeparameters (typedatetime | None) to all OpenTelemetry scope classes - Implemented
_datetime_to_ns()helper for datetime-to-nanoseconds conversion - Added
set_end_time()method to allow dynamic end time updates - Created comprehensive test suite covering custom timestamps, time overrides, and fallback to wall-clock time
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/opentelemetry_scope.py | Core implementation: added start_time/end_time parameters, _datetime_to_ns() converter, and set_end_time() method to base OpenTelemetryScope class |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/execute_tool_scope.py | Forward start_time/end_time parameters through ExecuteToolScope constructor and start() method with detailed docstrings |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/inference_scope.py | Forward start_time/end_time parameters through InferenceScope constructor and start() method |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/invoke_agent_scope.py | Forward start_time/end_time parameters through InvokeAgentScope constructor and start() method |
| libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/spans_scopes/output_scope.py | Forward start_time/end_time parameters through OutputScope constructor and start() method |
| tests/observability/core/test_custom_start_end_time.py | Comprehensive test suite with 4 test cases covering datetime conversion, time overrides, wall-clock fallback, and partial custom times |
...ents-a365-observability-core/microsoft_agents_a365/observability/core/opentelemetry_scope.py
Show resolved
Hide resolved
...ents-a365-observability-core/microsoft_agents_a365/observability/core/opentelemetry_scope.py
Show resolved
Hide resolved
...ents-a365-observability-core/microsoft_agents_a365/observability/core/opentelemetry_scope.py
Show resolved
Hide resolved
fpfp100
approved these changes
Feb 24, 2026
juliomenendez
approved these changes
Feb 24, 2026
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.
Port of Node.js PR #205. Enables explicit span timestamps for operations recorded after completion (e.g., LangChain tracer using
run.start_time/run.end_time).Changes
start_time/end_timeconstructor params andset_end_time()methodInferenceScope,InvokeAgentScope,ExecuteToolScope,OutputScopedatetime | None(simpler than Node.jsTimeInputunion—more Pythonic)Usage
Note: LangChain tracer already uses
run.start_time/run.end_timeviaas_utc_nano()—no changes needed there.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
il-1234567812345678123456781234567.8.tenant.api.powerplatform.com/home/REDACTED/work/Agent365-python/Agent365-python/.venv/bin/pytest pytest tests/observability/ -v --tb=short -m not integration(dns block)/home/REDACTED/work/Agent365-python/Agent365-python/.venv/bin/pytest pytest tests/ -v --tb=short -m not integration(dns block)il-testtenan.t.tenant.api.powerplatform.com/home/REDACTED/work/Agent365-python/Agent365-python/.venv/bin/pytest pytest tests/observability/ -v --tb=short -m not integration(dns block)/home/REDACTED/work/Agent365-python/Agent365-python/.venv/bin/pytest pytest tests/ -v --tb=short -m not integration(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.