Skip to content

Commit

Permalink
Sync with Remove time_ns from API (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl authored Mar 10, 2021
1 parent 9ef4410 commit 0917dad
Show file tree
Hide file tree
Showing 7 changed files with 30 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: 10dc3a8bc031d5b355f62a698094a03eedb2a8ee
CORE_REPO_SHA: d3694fc520f8542b232fd1065133286f4591dcec

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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
from opentelemetry.util._time import _time_ns

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -127,9 +127,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 @@ -58,8 +58,8 @@ def on_get(self, req, resp):
)
from opentelemetry.propagate import extract
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
from opentelemetry.util.time import time_ns

_logger = getLogger(__name__)

Expand Down Expand Up @@ -108,7 +108,7 @@ def __call__(self, env, start_response):
if _excluded_urls.url_disabled(env.get("PATH_INFO", "/")):
return super().__call__(env, start_response)

start_time = time_ns()
start_time = _time_ns()

token = context.attach(extract(otel_wsgi.carrier_getter, env))
span = self._tracer.start_span(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def hello():
from opentelemetry.instrumentation.flask.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.propagate import extract
from opentelemetry.util._time import _time_ns
from opentelemetry.util.http import get_excluded_urls
from opentelemetry.util.time import time_ns

_logger = getLogger(__name__)

Expand Down Expand Up @@ -85,7 +85,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()

def _start_response(status, response_headers, *args, **kwargs):
if not _excluded_urls.url_disabled(flask.request.url):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from logging import getLogger

from pyramid.events import BeforeTraversal
Expand All @@ -9,8 +23,8 @@
from opentelemetry import context, trace
from opentelemetry.instrumentation.pyramid.version import __version__
from opentelemetry.propagate import extract
from opentelemetry.util._time import _time_ns
from opentelemetry.util.http import get_excluded_urls
from opentelemetry.util.time import time_ns

TWEEN_NAME = "opentelemetry.instrumentation.pyramid.trace_tween_factory"
SETTING_TRACE_ENABLED = "opentelemetry-pyramid.trace_enabled"
Expand Down Expand Up @@ -112,7 +126,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()

try:
response = handler(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get(self):
tornado.ioloop.IOLoop.current().start()
"""


from collections import namedtuple
from functools import partial
from logging import getLogger
Expand All @@ -54,8 +55,8 @@ def get(self):
from opentelemetry.propagate import extract
from opentelemetry.propagators.textmap import DictGetter
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
from opentelemetry.util.time import time_ns

from .client import fetch_async # pylint: disable=E0401

Expand Down Expand Up @@ -148,7 +149,7 @@ def _wrap(cls, method_name, wrapper):


def _prepare(tracer, 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 @@ -225,7 +226,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())
if status_code != 404:
finish_args = (
type(error),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from opentelemetry.instrumentation.utils import http_status_to_status_code
from opentelemetry.propagate import inject
from opentelemetry.trace.status import Status
from opentelemetry.util.time import time_ns
from opentelemetry.util._time import _time_ns


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


def fetch_async(tracer, 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 0917dad

Please sign in to comment.