Skip to content

Commit

Permalink
Remove usage of _time_ns
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Aug 25, 2022
1 parent 858e7b8 commit 0dc372e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'release/*'
pull_request:
env:
CORE_REPO_SHA: 75846aa0e0a5960661b1d8d7441d2df921e6a97b
CORE_REPO_SHA: a6324d891365f61e3631dabd68f3321482f15c51

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import logging
import threading
import typing
from time import time_ns

from opentelemetry.context import Context, attach, detach, set_value
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY
from opentelemetry.sdk.trace import Span, SpanProcessor
from opentelemetry.sdk.trace.export import SpanExporter
from opentelemetry.trace import INVALID_TRACE_ID
from opentelemetry.util._time import _time_ns

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -128,9 +128,9 @@ def worker(self):
break

# substract the duration of this export call to the next timeout
start = _time_ns()
start = time_ns()
self.export()
end = _time_ns()
end = time_ns()
duration = (end - start) / 1e9
timeout = self.schedule_delay_millis / 1e3 - duration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def response_hook(span, req, resp):
---
"""

from time import time_ns
from logging import getLogger
from sys import exc_info
from typing import Collection
Expand All @@ -164,7 +165,6 @@ def response_hook(span, req, resp):
)
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace.status import Status
from opentelemetry.util._time import _time_ns
from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs

_logger = getLogger(__name__)
Expand Down Expand Up @@ -253,7 +253,7 @@ def __call__(self, env, start_response):
if self._otel_excluded_urls.url_disabled(env.get("PATH_INFO", "/")):
return super().__call__(env, start_response)

start_time = _time_ns()
start_time = time_ns()

span, token = _start_internal_or_server_span(
tracer=self._otel_tracer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def response_hook(span: Span, status: str, response_headers: List):
from logging import getLogger
from timeit import default_timer
from typing import Collection
from time import time_ns

import flask

Expand All @@ -157,7 +158,6 @@ def response_hook(span: Span, status: str, response_headers: List):
from opentelemetry.instrumentation.utils import _start_internal_or_server_span
from opentelemetry.metrics import get_meter
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.util._time import _time_ns
from opentelemetry.util.http import get_excluded_urls, parse_excluded_urls

_logger = getLogger(__name__)
Expand Down Expand Up @@ -191,7 +191,7 @@ def _wrapped_app(wrapped_app_environ, start_response):
# In theory, we could start the span here and use
# update_name later but that API is "highly discouraged" so
# we better avoid it.
wrapped_app_environ[_ENVIRON_STARTTIME_KEY] = _time_ns()
wrapped_app_environ[_ENVIRON_STARTTIME_KEY] = time_ns()
start = default_timer()
attributes = otel_wsgi.collect_request_attributes(wrapped_app_environ)
active_requests_count_attrs = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from logging import getLogger
from time import time_ns

from pyramid.events import BeforeTraversal
from pyramid.httpexceptions import HTTPException, HTTPServerError
Expand All @@ -27,7 +28,6 @@
from opentelemetry.instrumentation.pyramid.version import __version__
from opentelemetry.instrumentation.utils import _start_internal_or_server_span
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.util._time import _time_ns
from opentelemetry.util.http import get_excluded_urls

TWEEN_NAME = "opentelemetry.instrumentation.pyramid.trace_tween_factory"
Expand Down Expand Up @@ -144,7 +144,7 @@ def trace_tween(request):
return handler(request)

request.environ[_ENVIRON_ENABLED_KEY] = True
request.environ[_ENVIRON_STARTTIME_KEY] = _time_ns()
request.environ[_ENVIRON_STARTTIME_KEY] = time_ns()

response = None
status = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def client_resposne_hook(span, future):
from functools import partial
from logging import getLogger
from typing import Collection
from time import time_ns

import tornado.web
import wrapt
Expand All @@ -179,7 +180,6 @@ def client_resposne_hook(span, future):
from opentelemetry.propagators import textmap
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace.status import Status, StatusCode
from opentelemetry.util._time import _time_ns
from opentelemetry.util.http import (
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST,
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE,
Expand Down Expand Up @@ -290,7 +290,7 @@ def _wrap(cls, method_name, wrapper):


def _prepare(tracer, request_hook, func, handler, args, kwargs):
start_time = _time_ns()
start_time = time_ns()
request = handler.request
if _excluded_urls.url_disabled(request.uri):
return func(*args, **kwargs)
Expand Down Expand Up @@ -423,7 +423,7 @@ def _finish_span(tracer, handler, error=None):
if isinstance(error, tornado.web.HTTPError):
status_code = error.status_code
if not ctx and status_code == 404:
ctx = _start_span(tracer, handler, _time_ns())
ctx = _start_span(tracer, handler, time_ns())
else:
status_code = 500
reason = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import functools
from time import time_ns

from tornado.httpclient import HTTPError, HTTPRequest

Expand All @@ -21,7 +22,6 @@
from opentelemetry.propagate import inject
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace.status import Status
from opentelemetry.util._time import _time_ns
from opentelemetry.util.http import remove_url_credentials


Expand All @@ -42,7 +42,7 @@ def _normalize_request(args, kwargs):


def fetch_async(tracer, request_hook, response_hook, func, _, args, kwargs):
start_time = _time_ns()
start_time = time_ns()

# Return immediately if no args were provided (error)
# or original_request is set (meaning we are in a redirect step).
Expand Down

0 comments on commit 0dc372e

Please sign in to comment.