Skip to content

Add start_time and end_time parameters to OpenTelemetry scope classes#181

Merged
nikhilNava merged 4 commits intomainfrom
copilot/add-start-and-end-time-python
Feb 25, 2026
Merged

Add start_time and end_time parameters to OpenTelemetry scope classes#181
nikhilNava merged 4 commits intomainfrom
copilot/add-start-and-end-time-python

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

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

  • OpenTelemetryScope: Add start_time/end_time constructor params and set_end_time() method
  • Scope subclasses: Forward params through InferenceScope, InvokeAgentScope, ExecuteToolScope, OutputScope
  • Type: Use datetime | None (simpler than Node.js TimeInput union—more Pythonic)

Usage

from datetime import datetime, UTC
from microsoft_agents_a365.observability.core import ExecuteToolScope

# Pass datetime objects for custom timestamps
scope = ExecuteToolScope.start(
    details, agent, tenant,
    start_time=datetime(2023, 11, 14, 22, 13, 20, tzinfo=UTC),
    end_time=datetime(2023, 11, 14, 22, 13, 25, tzinfo=UTC),
)

# Or override end time before dispose
scope.set_end_time(custom_end)
scope.dispose()

Note: LangChain tracer already uses run.start_time/run.end_time via as_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
    • Triggering command: /home/REDACTED/work/Agent365-python/Agent365-python/.venv/bin/pytest pytest tests/observability/ -v --tb=short -m not integration (dns block)
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/Agent365-python/Agent365-python/.venv/bin/pytest pytest tests/observability/ -v --tb=short -m not integration (dns block)
    • Triggering command: /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.

Copilot AI and others added 2 commits February 24, 2026 19:15
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>
@nikhilNava nikhilNava marked this pull request as ready for review February 24, 2026 19:36
@nikhilNava nikhilNava requested a review from a team as a code owner February 24, 2026 19:37
Copilot AI review requested due to automatic review settings February 24, 2026 19:37
@github-actions
Copy link

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_time and end_time parameters (type datetime | 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

@nikhilNava nikhilNava merged commit 1c44d8c into main Feb 25, 2026
13 checks passed
@nikhilNava nikhilNava deleted the copilot/add-start-and-end-time-python branch February 25, 2026 10:03
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.

5 participants