Skip to content
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

Test: Upgrade Otel #3

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.46b0.dev",
"opentelemetry-instrumentation-wsgi == 0.46b0.dev",
"opentelemetry-semantic-conventions == 0.46b0.dev",
"opentelemetry-util-http == 0.46b0.dev",
"opentelemetry-instrumentation@git+https://github.com/tammy-baylis-swi/opentelemetry-python-contrib.git@sw-upgrade-otel#subdirectory=opentelemetry-instrumentation",
"opentelemetry-instrumentation-wsgi@git+https://github.com/tammy-baylis-swi/opentelemetry-python-contrib.git@sw-upgrade-otel#subdirectory=instrumentation/opentelemetry-instrumentation-wsgi",
"opentelemetry-semantic-conventions@git+https://github.com/tammy-baylis-swi/opentelemetry-python.git@sw-upgrade-otel#subdirectory=opentelemetry-semantic-conventions",
"opentelemetry-util-http@git+https://github.com/tammy-baylis-swi/opentelemetry-python-contrib.git@sw-upgrade-otel#subdirectory=util/opentelemetry-util-http",
"packaging >= 21.0",
"importlib-metadata >= 4.0",
]
Expand All @@ -47,6 +47,9 @@ Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/
[tool.hatch.version]
path = "src/opentelemetry/instrumentation/flask/version.py"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.targets.sdist]
include = [
"/src",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.46b0.dev"
__version__ = "0.45b0"
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.46b0.dev",
"opentelemetry-instrumentation == 0.45b0",
]

[project.optional-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.46b0.dev"
__version__ = "0.45b0"

_instruments = tuple()
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.46b0.dev",
"opentelemetry-semantic-conventions == 0.46b0.dev",
"opentelemetry-util-http == 0.46b0.dev",
"opentelemetry-instrumentation@git+https://github.com/tammy-baylis-swi/opentelemetry-python-contrib.git@sw-upgrade-otel#subdirectory=opentelemetry-instrumentation",
"opentelemetry-semantic-conventions@git+https://github.com/tammy-baylis-swi/opentelemetry-python.git@sw-upgrade-otel#subdirectory=opentelemetry-semantic-conventions",
"opentelemetry-util-http@git+https://github.com/tammy-baylis-swi/opentelemetry-python-contrib.git@sw-upgrade-otel#subdirectory=util/opentelemetry-util-http",
]

[project.optional-dependencies]
Expand All @@ -44,6 +44,9 @@ Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/
[tool.hatch.version]
path = "src/opentelemetry/instrumentation/requests/version.py"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.targets.sdist]
include = [
"/src",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def _instrument(
:code:`requests.session.Session.request` (this includes
:code:`requests.get`, etc.)."""

print("!!! init.py _instrument with opt_in_mode:")
print("%s", sem_conv_opt_in_mode)

# Since
# https://github.com/psf/requests/commit/d72d1162142d1bf8b1b5711c664fbbd674f349d1
# (v0.7.0, Oct 23, 2011), get, post, etc are implemented via request which
Expand Down Expand Up @@ -209,6 +212,9 @@ def get_or_create_headers():
except ValueError:
pass

print("!!! RequestsInstrumentor start_as_current_span with span_attributes:")
print("%s", span_attributes)

with tracer.start_as_current_span(
span_name, kind=SpanKind.CLIENT, attributes=span_attributes
) as span, set_ip_on_next_http_connection(span):
Expand Down Expand Up @@ -312,6 +318,8 @@ def get_or_create_headers():
if exception is not None:
raise exception.with_traceback(exception.__traceback__)

print("Attributes updated: %s", span_attributes)

return result

instrumented_send.opentelemetry_instrumentation_requests_applied = True
Expand Down Expand Up @@ -376,9 +384,16 @@ def _instrument(self, **kwargs):
``excluded_urls``: A string containing a comma-delimited
list of regexes used to exclude URLs from tracking
"""
print("!!! RequestsInstrumentor _instrument with kwargs:")
print("%s", kwargs)

semconv_opt_in_mode = _OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.HTTP,
)

print("Then got semconv_opt_in_mode (no hyphen):")
print("%s", semconv_opt_in_mode)

schema_url = _get_schema_url(semconv_opt_in_mode)
tracer_provider = kwargs.get("tracer_provider")
tracer = get_tracer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.46b0.dev"
__version__ = "0.45b0"
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ classifiers = [
]
dependencies = [
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.46b0.dev",
"opentelemetry-semantic-conventions == 0.46b0.dev",
"opentelemetry-util-http == 0.46b0.dev",
"opentelemetry-instrumentation@git+https://github.com/tammy-baylis-swi/opentelemetry-python-contrib.git@sw-upgrade-otel#subdirectory=opentelemetry-instrumentation",
"opentelemetry-semantic-conventions@git+https://github.com/tammy-baylis-swi/opentelemetry-python.git@sw-upgrade-otel#subdirectory=opentelemetry-semantic-conventions",
"opentelemetry-util-http@git+https://github.com/tammy-baylis-swi/opentelemetry-python-contrib.git@sw-upgrade-otel#subdirectory=util/opentelemetry-util-http",
]

[project.optional-dependencies]
Expand All @@ -39,6 +39,9 @@ Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/
[tool.hatch.version]
path = "src/opentelemetry/instrumentation/wsgi/version.py"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.targets.sdist]
include = [
"/src",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ def collect_request_attributes(
"""Collects HTTP request attributes from the PEP3333-conforming
WSGI environ and returns a dictionary to be used as span creation attributes.
"""
print("!!! wsgi.collect_request_attrs with %s", sem_conv_opt_in_mode)

result = {}
_set_http_method(
result,
Expand Down Expand Up @@ -380,6 +382,7 @@ def collect_request_attributes(
if flavor:
_set_http_flavor_version(result, flavor, sem_conv_opt_in_mode)

print("!!! wsgi.collect_request_attrs result: %s", result)
return result


Expand Down Expand Up @@ -543,11 +546,16 @@ def __init__(
tracer_provider=None,
meter_provider=None,
):
print("!!! Middleware init (wsgi)")

# initialize semantic conventions opt-in if needed
_OpenTelemetrySemanticConventionStability._initialize()
sem_conv_opt_in_mode = _OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.HTTP,
)

print("with sem_conv_opt_in_mode: %s", sem_conv_opt_in_mode)

self.wsgi = wsgi
self.tracer = trace.get_tracer(
__name__,
Expand Down Expand Up @@ -623,6 +631,8 @@ def __call__(self, environ, start_response):
environ: A WSGI environment.
start_response: The WSGI start_response callable.
"""
print("!!! __call__ with self.mode %s", self._sem_conv_opt_in_mode)

req_attrs = collect_request_attributes(
environ, self._sem_conv_opt_in_mode
)
Expand All @@ -631,6 +641,8 @@ def __call__(self, environ, start_response):
self._sem_conv_opt_in_mode,
)

print("req_attrs: %s", req_attrs)

span, token = _start_internal_or_server_span(
tracer=self.tracer,
span_name=get_default_span_name(environ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.46b0.dev"
__version__ = "0.45b0"
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def _initialize(cls):
# Users can pass in comma delimited string for opt-in options
# Only values for http stability are supported for now
opt_in = os.environ.get(OTEL_SEMCONV_STABILITY_OPT_IN, "")

print("!!! SemconvStability._initialize")
print("Got opt_in from env var: %s", opt_in)

opt_in_list = []
if opt_in:
opt_in_list = [s.strip() for s in opt_in.split(",")]
Expand All @@ -130,6 +134,9 @@ def _initialize(cls):
http_opt_in = _HTTPStabilityMode.HTTP_DUP
elif _HTTPStabilityMode.HTTP.value in opt_in_list:
http_opt_in = _HTTPStabilityMode.HTTP

print("Using http_opt_in %s", http_opt_in)

_OpenTelemetrySemanticConventionStability._OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING[
_OpenTelemetryStabilitySignalType.HTTP
] = http_opt_in
Expand All @@ -141,6 +148,16 @@ def _get_opentelemetry_stability_opt_in_mode(
cls,
signal_type: _OpenTelemetryStabilitySignalType,
) -> _HTTPStabilityMode:
print("!!! _semconv.get_otel_stability")
print("signal_type: %s", signal_type)
print("_OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING: %s", _OpenTelemetrySemanticConventionStability._OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING)
print(
"retval: %s",
_OpenTelemetrySemanticConventionStability._OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING.get(
signal_type, _HTTPStabilityMode.DEFAULT
)
)

return _OpenTelemetrySemanticConventionStability._OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING.get(
signal_type, _HTTPStabilityMode.DEFAULT
)
Expand Down Expand Up @@ -224,10 +241,14 @@ def _set_http_status_code(result, code, sem_conv_opt_in_mode):


def _set_http_url(result, url, sem_conv_opt_in_mode):
print("!!! _semconv._set_http_url got opt_in_mode: %s", sem_conv_opt_in_mode)

if _report_old(sem_conv_opt_in_mode):
set_string_attribute(result, SpanAttributes.HTTP_URL, url)
print("set_string_attr with key %s, url %s", SpanAttributes.HTTP_URL, url)
if _report_new(sem_conv_opt_in_mode):
set_string_attribute(result, SpanAttributes.URL_FULL, url)
print("set_string_attr with key %s, url %s", SpanAttributes.URL_FULL, url)


def _set_http_scheme(result, scheme, sem_conv_opt_in_mode):
Expand Down Expand Up @@ -275,8 +296,10 @@ def _set_http_network_protocol_version(result, version, sem_conv_opt_in_mode):

def _set_http_net_host(result, host, sem_conv_opt_in_mode):
if _report_old(sem_conv_opt_in_mode):
print("!!! _semconv._set_http_net host via mode %s as %s", sem_conv_opt_in_mode, SpanAttributes.NET_HOST_NAME)
set_string_attribute(result, SpanAttributes.NET_HOST_NAME, host)
if _report_new(sem_conv_opt_in_mode):
print("!!! _semconv._set_http_net host via mode %s as %s", sem_conv_opt_in_mode, SpanAttributes.SERVER_ADDRESS)
set_string_attribute(result, SpanAttributes.SERVER_ADDRESS, host)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@

import argparse
import logging
import subprocess
import sys
from subprocess import (
PIPE,
CalledProcessError,
Popen,
SubprocessError,
check_call,
)

import pkg_resources

Expand All @@ -34,7 +40,7 @@ def wrapper(package=None):
if package:
return func(package)
return func()
except subprocess.SubprocessError as exp:
except SubprocessError as exp:
cmd = getattr(exp, "cmd", None)
if cmd:
msg = f'Error calling system command "{" ".join(cmd)}"'
Expand All @@ -48,18 +54,21 @@ def wrapper(package=None):
@_syscall
def _sys_pip_install(package):
# explicit upgrade strategy to override potential pip config
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
"-U",
"--upgrade-strategy",
"only-if-needed",
package,
]
)
try:
check_call(
[
sys.executable,
"-m",
"pip",
"install",
"-U",
"--upgrade-strategy",
"only-if-needed",
package,
]
)
except CalledProcessError as error:
print(error)


def _pip_check():
Expand All @@ -70,8 +79,8 @@ def _pip_check():
'opentelemetry-instrumentation-flask 1.0.1 has requirement opentelemetry-sdk<2.0,>=1.0, but you have opentelemetry-sdk 0.5.'
To not be too restrictive, we'll only check for relevant packages.
"""
with subprocess.Popen(
[sys.executable, "-m", "pip", "check"], stdout=subprocess.PIPE
with Popen(
[sys.executable, "-m", "pip", "check"], stdout=PIPE
) as check_pipe:
pip_check = check_pipe.communicate()[0].decode()
pip_check_lower = pip_check.lower()
Expand Down
Loading
Loading