Skip to content

Commit

Permalink
Merge branch 'master' into check-response-type
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Jan 5, 2021
2 parents 9670a95 + 5a6c4f6 commit 6e40d53
Show file tree
Hide file tree
Showing 26 changed files with 111 additions and 52 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CodeQL Analysis

on:
workflow_dispatch:
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: '30 1 * * *'

jobs:
CodeQL-Build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: python

- name: Autobuild
uses: github/codeql-action/autobuild@v1

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ __pycache__
venv*/
.venv*/
opentelemetry-python-core*/
/opentelemetry-python-core

# Installer logs
pip-log.txt
Expand Down
3 changes: 2 additions & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=79
profile=black

; 3 stands for Vertical Hanging Indent, e.g.
; from third_party import (
Expand All @@ -13,6 +14,6 @@ line_length=79
; docs: https://github.com/timothycrosley/isort#multi-line-output-modes
multi_line_output=3
skip=target
skip_glob=**/gen/*,.venv*/*,venv*/*,reference*/*,opentelemetry-python-core/*
skip_glob=**/gen/*,.venv*/*,venv*/*,reference*/*,opentelemetry-python-core/*,.tox/*
known_first_party=opentelemetry
known_third_party=psutil,pytest,redis,redis_opentracing
12 changes: 10 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ disable=missing-docstring,
wrong-import-order, # Leave this up to isort
bad-continuation, # Leave this up to black
line-too-long, # Leave this up to black
exec-used
exec-used,
super-with-arguments, # temp-pylint-upgrade
isinstance-second-argument-not-valid-type, # temp-pylint-upgrade
raise-missing-from, # temp-pylint-upgrade
unused-argument, # temp-pylint-upgrade
protected-access, # temp-pylint-upgrade
super-init-not-called, # temp-pylint-upgrade
invalid-overridden-method, # temp-pylint-upgrade
missing-module-docstring, # temp-pylint-upgrad, # temp-pylint-upgradee

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down Expand Up @@ -165,7 +173,7 @@ contextmanager-decorators=contextlib.contextmanager
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=*_pb2.py
generated-members=types_pb2.*

# Tells whether missing members accessed in mixin class should be ignored. A
# mixin class is detected if its name ends with "mixin" (case insensitive).
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python-contrib/compare/v0.16b1...HEAD)

### Added
- `opentelemetry-instrumentation-sqlalchemy` Ensure spans have kind set to "CLIENT"
([#278](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/278))
- `opentelemetry-instrumentation-celery` Add support for Celery version 5.x
([#266](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/266))
- `opentelemetry-instrumentation-urllib` Add urllib instrumentation
Expand Down Expand Up @@ -46,7 +48,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `opentelemetry-instrumentation-flask` Do not emit a warning message for request contexts created with `app.test_request_context`
([#253](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/253))
- `opentelemetry-instrumentation-requests`, `opentelemetry-instrumentation-urllib` Fix span name callback parameters
- ([#259](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/259))
([#259](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/259))
- `opentelemetry-exporter-datadog` Fix unintentional type change of span trace flags
([#261](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/261))

## [0.16b1](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.16b1) - 2020-11-26

Expand Down
7 changes: 4 additions & 3 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pylint==2.4.4
pylint~=2.6
flake8~=3.7
isort~=4.3
isort~=5.6
black>=19.3b0,==19.*
mypy==0.740
httpretty~=1.0
mypy==0.790
sphinx~=2.1
sphinx-rtd-theme~=0.4
sphinx-autodoc-typehints~=1.10.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@
from ddtrace.span import Span as DatadogSpan

import opentelemetry.trace as trace_api
from opentelemetry.sdk.trace import sampling
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult

# pylint:disable=relative-beyond-top-level
from .constants import (
from opentelemetry.exporter.datadog.constants import (
DD_ORIGIN,
ENV_KEY,
SAMPLE_RATE_METRIC_KEY,
SERVICE_NAME_TAG,
VERSION_KEY,
)
from opentelemetry.sdk.trace import sampling
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from opentelemetry import trace
from opentelemetry.context import Context
from opentelemetry.exporter.datadog import constants
from opentelemetry.trace import get_current_span, set_span_in_context
from opentelemetry.trace.propagation.textmap import (
Getter,
Expand All @@ -24,9 +25,6 @@
TextMapPropagatorT,
)

# pylint:disable=relative-beyond-top-level
from . import constants


class DatadogFormat(TextMapPropagator):
"""Propagator for the Datadog HTTP header format.
Expand Down Expand Up @@ -62,7 +60,7 @@ def extract(
constants.AUTO_KEEP,
constants.USER_KEEP,
):
trace_flags |= trace.TraceFlags.SAMPLED
trace_flags = trace.TraceFlags(trace.TraceFlags.SAMPLED)

if trace_id is None or span_id is None:
return set_span_in_context(trace.INVALID_SPAN, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ package_dir=
=src
packages=find_namespace:
install_requires =
snappy >= 2.8
protobuf >= 3.13.0
requests == 2.25.0
opentelemetry-api == 0.17.dev0
opentelemetry-sdk == 0.17.dev0
python-snappy >= 0.5.4
[options.packages.find]
where = src

[options.extras_require]
test =
[options.packages.find]
where = src
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def _convert_from_quantile(
) -> Sequence[TimeSeries]:
raise NotImplementedError()

# pylint: disable=no-member
# pylint: disable=no-member,no-self-use
def _create_timeseries(
self,
export_record: ExportRecord,
Expand Down Expand Up @@ -317,6 +317,7 @@ def add_label(label_name: str, label_value: str):
timeseries.samples.append(sample)
return timeseries

# pylint: disable=no-member,no-self-use
def _build_message(self, timeseries: Sequence[TimeSeries]) -> bytes:
write_request = WriteRequest()
write_request.timeseries.extend(timeseries)
Expand Down Expand Up @@ -370,7 +371,7 @@ def _send_message(
)
if not response.ok:
response.raise_for_status()
except requests.exceptions.RequestException as e:
logger.error("Export POST request failed with reason: %s", e)
except requests.exceptions.RequestException as err:
logger.error("Export POST request failed with reason: %s", err)
return MetricsExportResult.FAILURE
return MetricsExportResult.SUCCESS
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
# limitations under the License.

import unittest
from logging import Logger
from unittest.mock import MagicMock, Mock, patch
from unittest.mock import patch

from opentelemetry.exporter.prometheus_remote_write import (
PrometheusRemoteWriteMetricsExporter,
)
from opentelemetry.exporter.prometheus_remote_write.gen.types_pb2 import (
Label,
Sample,
TimeSeries,
)
from opentelemetry.sdk.metrics import Counter
Expand Down Expand Up @@ -339,15 +337,17 @@ def create_label(name, value):
)

expected_timeseries = TimeSeries()
expected_timeseries.labels.append(create_label("__name__", "testname"))
expected_timeseries.labels.append(
expected_timeseries.labels.append( # pylint:disable=E1101
create_label("__name__", "testname")
)
expected_timeseries.labels.append( # pylint:disable=E1101
create_label("resource_name", "resource_value")
)
expected_timeseries.labels.append(
expected_timeseries.labels.append( # pylint:disable=E1101
create_label("record_name", "record_value")
)

sample = expected_timeseries.samples.add()
sample = expected_timeseries.samples.add() # pylint:disable=E1101
sample.timestamp = int(sum_aggregator.last_update_timestamp / 1000000)
sample.value = 5.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

try:
from django.core.urlresolvers import ( # pylint: disable=no-name-in-module
resolve,
Resolver404,
resolve,
)
except ImportError:
from django.urls import resolve, Resolver404
from django.urls import Resolver404, resolve

try:
from django.utils.deprecation import MiddlewareMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def _(param: str):
return {"message": param}

@app.get("/healthzz")
async def health():
async def _():
return {"message": "ok"}

return app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def serve():
"""
from functools import partial

import grpc
import grpc # pylint:disable=import-self
from wrapt import wrap_function_wrapper as _wrap

from opentelemetry import trace
Expand All @@ -142,7 +142,6 @@ def serve():
# pylint:disable=import-outside-toplevel
# pylint:disable=import-self
# pylint:disable=unused-argument
# isort:skip


class GrpcInstrumentorServer(BaseInstrumentor):
Expand All @@ -156,7 +155,7 @@ class GrpcInstrumentorServer(BaseInstrumentor):
"""

# pylint:disable=attribute-defined-outside-init
# pylint:disable=attribute-defined-outside-init, redefined-outer-name

def _instrument(self, **kwargs):
self._original_func = grpc.server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import grpc

from opentelemetry import metrics, propagators, trace
from opentelemetry.instrumentation.grpc import grpcext
from opentelemetry.instrumentation.grpc._utilities import (
RpcInfo,
TimedMetricRecorder,
)
from opentelemetry.sdk.metrics.export.controller import PushController
from opentelemetry.trace.status import Status, StatusCode

from . import grpcext
from ._utilities import RpcInfo, TimedMetricRecorder


class _GuardedSpan:
def __init__(self, span):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ def record_bytes_out(self, bytes_out, method):
@contextmanager
def record_latency(self, method):
start_time = time()
labels = {"method": method, "status_code": grpc.StatusCode.OK}
labels = {
"method": method,
"status_code": grpc.StatusCode.OK, # pylint:disable=no-member
}
try:
yield labels
except grpc.RpcError as exc:
except grpc.RpcError as exc: # pylint:disable=no-member
if self._meter:
# pylint: disable=no-member
labels["status_code"] = exc.code()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import grpc

from .. import grpcext
from opentelemetry.instrumentation.grpc import grpcext


class _UnaryClientInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
import grpc

from tests.protobuf import test_server_pb2 as test__server__pb2


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import grpc
from tests.protobuf import test_server_pb2_grpc

import opentelemetry.instrumentation.grpc
from opentelemetry import trace
Expand All @@ -22,7 +23,6 @@
SumAggregator,
)
from opentelemetry.test.test_base import TestBase
from tests.protobuf import test_server_pb2_grpc

from ._client import (
bidirectional_streaming_method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def __init__(self, tracer, engine):

# pylint: disable=unused-argument
def _before_cur_exec(self, conn, cursor, statement, *args):
self.current_span = self.tracer.start_span(statement)
self.current_span = self.tracer.start_span(
statement, kind=trace.SpanKind.CLIENT
)
with self.tracer.use_span(self.current_span, end_on_exit=False):
if self.current_span.is_recording():
self.current_span.set_attribute(_STMT, statement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from sqlalchemy import create_engine

from opentelemetry import trace
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
from opentelemetry.test.test_base import TestBase

Expand All @@ -35,6 +36,7 @@ def test_trace_integration(self):

self.assertEqual(len(spans), 1)
self.assertEqual(spans[0].name, "SELECT 1 + 1;")
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)

def test_not_recording(self):
mock_tracer = mock.Mock()
Expand Down Expand Up @@ -67,3 +69,4 @@ def test_create_engine_wrapper(self):

self.assertEqual(len(spans), 1)
self.assertEqual(spans[0].name, "SELECT 1 + 1;")
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
Loading

0 comments on commit 6e40d53

Please sign in to comment.