Skip to content

fix(tracing): use actual operation timestamps in OpenTelemetry spans #1320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

Pouyanpi
Copy link
Collaborator

@Pouyanpi Pouyanpi commented Aug 1, 2025

Description

OpenTelemetry spans were created with current timestamps during export instead of using he original timestamps from when operations actually occurred.

Fix:

Modified _create_span() to use tracer.start_span() with original start_time and span.end() with original end_time from span data, converting timestamps to nanoseconds as required by OpenTelemetry.

Test Plan:

tests/test_opentelemetry_timing_behavior.py contains timing-focused tests that verify spans use original operation timestamps (not current time). This test file is for verification and will be removed after review. The test fails on develop branch.

@Pouyanpi Pouyanpi added this to the v0.16.0 milestone Aug 1, 2025
@Pouyanpi Pouyanpi requested a review from Copilot August 1, 2025 12:37
@Pouyanpi Pouyanpi self-assigned this Aug 1, 2025
@Pouyanpi Pouyanpi added the bug Something isn't working label Aug 1, 2025
Copy link

@Copilot 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 fixes a timing issue in the OpenTelemetry adapter where spans were being created with current timestamps during export instead of using the original timestamps from when operations occurred.

  • Modified _create_span() to use tracer.start_span() with historical start_time and span.end() with historical end_time
  • Updated test cases to verify spans use original operation timestamps
  • Added comprehensive timing behavior tests to prevent regression

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
nemoguardrails/tracing/adapters/opentelemetry.py Fixed _create_span() to use historical timestamps instead of current time, converting to nanoseconds as required by OpenTelemetry
tests/test_tracing_adapters_opentelemetry.py Updated tests to verify proper timing behavior and removed deprecated import handling
tests/test_opentelemetry_timing_behavior.py Added comprehensive timing tests to verify spans use historical timestamps

@Pouyanpi Pouyanpi force-pushed the fix/opentelemetry-span-timing branch from fc840fe to 20fd070 Compare August 1, 2025 12:42
@codecov-commenter
Copy link

codecov-commenter commented Aug 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.53%. Comparing base (dd1ce5f) to head (15aabe4).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1320   +/-   ##
========================================
  Coverage    70.52%   70.53%           
========================================
  Files          161      161           
  Lines        16267    16268    +1     
========================================
+ Hits         11473    11474    +1     
  Misses        4794     4794           
Flag Coverage Δ
python 70.53% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
nemoguardrails/tracing/adapters/opentelemetry.py 94.00% <100.00%> (+0.12%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Fixes OpenTelemetry tracing issue where spans were created with current
  timestamps during export rather than original timestamps from when
  operations actually occurred. Changed from start_as_current_span() to
  start_span() with proper start_time and span.end() with end_time.
@Pouyanpi Pouyanpi force-pushed the fix/opentelemetry-span-timing branch from 20fd070 to 15aabe4 Compare August 1, 2025 13:56
@Pouyanpi
Copy link
Collaborator Author

close in favor of #1331

@Pouyanpi Pouyanpi closed this Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants