Skip to content

Commit 7564072

Browse files
committed
changed code
1 parent fe9f8a5 commit 7564072

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/opentelemetry_mcp/backends/dynatrace.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ async def search_traces(self, query: TraceQuery) -> list[TraceData]:
9191

9292
# Add time range (Dynatrace uses milliseconds since epoch)
9393
if query.start_time:
94-
params["from"] = int(
95-
(datetime.now(timezone.utc) - timedelta(days=1)).timestamp() * 1000
96-
)
94+
params["from"] = int(query.start_time.timestamp() * 1000)
9795
else:
9896
# Default to last 24 hours if not specified
9997
params["from"] = int((datetime.now() - timedelta(days=1)).timestamp() * 1000)
@@ -336,7 +334,7 @@ async def get_service_operations(self, service_name: str) -> list[str]:
336334
"from": int(
337335
(datetime.now(timezone.utc) - timedelta(days=1)).timestamp() * 1000
338336
),
339-
"to": int(datetime.now().timestamp(timezone.utc) * 1000),
337+
"to": int(datetime.now(timezone.utc).timestamp() * 1000),
340338
"limit": 1000,
341339
}
342340

@@ -423,7 +421,12 @@ def _parse_dynatrace_trace(
423421

424422
# Calculate trace duration
425423
start_times = [s.start_time for s in spans]
426-
end_times = [s.start_time + timedelta(milliseconds=s.duration_ms) for s in spans]
424+
end_times = [
425+
datetime.fromtimestamp(
426+
s.start_time.timestamp() + (s.duration_ms / 1000), tz=s.start_time.tzinfo
427+
)
428+
for s in spans
429+
]
427430
trace_start = min(start_times)
428431
trace_end = max(end_times)
429432
trace_duration_ms = (trace_end - trace_start).total_seconds() * 1000
@@ -479,7 +482,7 @@ def _parse_dynatrace_span(
479482
except Exception:
480483
start_time = datetime.fromtimestamp(int(start_time_ms) / 1000)
481484
else:
482-
start_time = datetime.fromtimestamp(start_time_ms / 1000)
485+
start_time = datetime.fromtimestamp(start_time_ms / 1000, tz=timezone.utc)
483486

484487
duration_ms = span_data.get("duration", span_data.get("duration_ms", 0))
485488
if isinstance(duration_ms, str):

0 commit comments

Comments
 (0)