Skip to content

Commit

Permalink
Merge branch 'master' into exclude_lists
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Jul 2, 2020
2 parents 54bb85c + 2a9c3ac commit 61e753f
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
# might have already been updated, this would be bad.
- name: Publish to TestPyPI
env:
TWINE_USERNAME: ${{ secrets.test_pypi_username }}
TWINE_PASSWORD: ${{ secrets.test_pypi_password }}
TWINE_USERNAME: '__token__'
TWINE_PASSWORD: ${{ secrets.test_pypi_token }}
run: |
twine upload --repository testpypi --skip-existing --verbose dist/*
- name: Publish to PyPI
Expand Down
4 changes: 4 additions & 0 deletions ext/opentelemetry-ext-boto/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

## Unreleased

- ext/boto and ext/botocore: fails to export spans via jaeger
([#866](https://github.com/open-telemetry/opentelemetry-python/pull/866))

## 0.9b0

Released 2020-06-10

- Initial release

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

from opentelemetry.ext.boto.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.sdk.trace import Resource
from opentelemetry.trace import SpanKind, get_tracer

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -123,9 +124,14 @@ def _common_request( # pylint: disable=too-many-locals
) as span:
if args:
http_method = args[0]
span.resource = "%s.%s" % (endpoint_name, http_method.lower())
span.resource = Resource(
labels={
"endpoint": endpoint_name,
"http_method": http_method.lower(),
}
)
else:
span.resource = endpoint_name
span.resource = Resource(labels={"endpoint": endpoint_name})

add_span_arg_tags(
span, endpoint_name, args, args_name, traced_args,
Expand Down
49 changes: 40 additions & 9 deletions ext/opentelemetry-ext-boto/tests/test_boto_instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)

from opentelemetry.ext.boto import BotoInstrumentor
from opentelemetry.sdk.resources import Resource
from opentelemetry.test.test_base import TestBase


Expand Down Expand Up @@ -69,7 +70,12 @@ def test_ec2_client(self):
span = spans[1]
self.assertEqual(span.attributes["aws.operation"], "RunInstances")
assert_span_http_status_code(span, 200)
self.assertEqual(span.resource, "ec2.runinstances")
self.assertEqual(
span.resource,
Resource(
labels={"endpoint": "ec2", "http_method": "runinstances"}
),
)
self.assertEqual(span.attributes["http.method"], "POST")
self.assertEqual(span.attributes["aws.region"], "us-west-2")
self.assertEqual(span.name, "ec2.command")
Expand Down Expand Up @@ -123,7 +129,10 @@ def test_s3_client(self):
self.assertEqual(len(spans), 3)
span = spans[2]
assert_span_http_status_code(span, 200)
self.assertEqual(span.resource, "s3.head")
self.assertEqual(
span.resource,
Resource(labels={"endpoint": "s3", "http_method": "head"}),
)
self.assertEqual(span.attributes["http.method"], "HEAD")
self.assertEqual(span.attributes["aws.operation"], "head_bucket")
self.assertEqual(span.name, "s3.command")
Expand All @@ -135,7 +144,10 @@ def test_s3_client(self):
spans = self.memory_exporter.get_finished_spans()
assert spans
span = spans[2]
self.assertEqual(span.resource, "s3.head")
self.assertEqual(
span.resource,
Resource(labels={"endpoint": "s3", "http_method": "head"}),
)

@mock_s3_deprecated
def test_s3_put(self):
Expand All @@ -152,15 +164,24 @@ def test_s3_put(self):
self.assertEqual(len(spans), 3)
self.assertEqual(spans[0].attributes["aws.operation"], "create_bucket")
assert_span_http_status_code(spans[0], 200)
self.assertEqual(spans[0].resource, "s3.put")
self.assertEqual(
spans[0].resource,
Resource(labels={"endpoint": "s3", "http_method": "put"}),
)
# get bucket
self.assertEqual(spans[1].attributes["aws.operation"], "head_bucket")
self.assertEqual(spans[1].resource, "s3.head")
self.assertEqual(
spans[1].resource,
Resource(labels={"endpoint": "s3", "http_method": "head"}),
)
# put object
self.assertEqual(
spans[2].attributes["aws.operation"], "_send_file_internal"
)
self.assertEqual(spans[2].resource, "s3.put")
self.assertEqual(
spans[2].resource,
Resource(labels={"endpoint": "s3", "http_method": "put"}),
)

@mock_lambda_deprecated
def test_unpatch(self):
Expand Down Expand Up @@ -200,7 +221,10 @@ def test_lambda_client(self):
self.assertEqual(len(spans), 2)
span = spans[0]
assert_span_http_status_code(span, 200)
self.assertEqual(span.resource, "lambda.get")
self.assertEqual(
span.resource,
Resource(labels={"endpoint": "lambda", "http_method": "get"}),
)
self.assertEqual(span.attributes["http.method"], "GET")
self.assertEqual(span.attributes["aws.region"], "us-east-2")
self.assertEqual(span.attributes["aws.operation"], "list_functions")
Expand All @@ -214,7 +238,12 @@ def test_sts_client(self):
spans = self.memory_exporter.get_finished_spans()
assert spans
span = spans[0]
self.assertEqual(span.resource, "sts.getfederationtoken")
self.assertEqual(
span.resource,
Resource(
labels={"endpoint": "sts", "http_method": "getfederationtoken"}
),
)
self.assertEqual(span.attributes["aws.region"], "us-west-2")
self.assertEqual(
span.attributes["aws.operation"], "GetFederationToken"
Expand All @@ -238,5 +267,7 @@ def test_elasticache_client(self):
spans = self.memory_exporter.get_finished_spans()
assert spans
span = spans[0]
self.assertEqual(span.resource, "elasticache")
self.assertEqual(
span.resource, Resource(labels={"endpoint": "elasticcache"})
)
self.assertEqual(span.attributes["aws.region"], "us-west-2")
3 changes: 3 additions & 0 deletions ext/opentelemetry-ext-botocore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- ext/boto and ext/botocore: fails to export spans via jaeger
([#866](https://github.com/open-telemetry/opentelemetry-python/pull/866))

## 0.9b0

Released 2020-06-10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

from opentelemetry.ext.botocore.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.sdk.trace import Resource
from opentelemetry.trace import SpanKind, get_tracer

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -98,10 +99,15 @@ def _patched_api_call(self, original_func, instance, args, kwargs):
operation = None
if args:
operation = args[0]
span.resource = "%s.%s" % (endpoint_name, operation.lower())
span.resource = Resource(
labels={
"endpoint": endpoint_name,
"operation": operation.lower(),
}
)

else:
span.resource = endpoint_name
span.resource = Resource(labels={"endpoint": endpoint_name})

add_span_arg_tags(
span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)

from opentelemetry.ext.botocore import BotocoreInstrumentor
from opentelemetry.sdk.resources import Resource
from opentelemetry.test.test_base import TestBase


Expand Down Expand Up @@ -49,7 +50,12 @@ def test_traced_client(self):
self.assertEqual(span.attributes["aws.region"], "us-west-2")
self.assertEqual(span.attributes["aws.operation"], "DescribeInstances")
assert_span_http_status_code(span, 200)
self.assertEqual(span.resource, "ec2.describeinstances")
self.assertEqual(
span.resource,
Resource(
labels={"endpoint": "ec2", "operation": "describeinstances"}
),
)
self.assertEqual(span.name, "ec2.command")

@mock_ec2
Expand All @@ -73,7 +79,10 @@ def test_s3_client(self):
self.assertEqual(len(spans), 2)
self.assertEqual(span.attributes["aws.operation"], "ListBuckets")
assert_span_http_status_code(span, 200)
self.assertEqual(span.resource, "s3.listbuckets")
self.assertEqual(
span.resource,
Resource(labels={"endpoint": "s3", "operation": "listbuckets"}),
)

# testing for span error
self.memory_exporter.get_finished_spans()
Expand All @@ -82,7 +91,10 @@ def test_s3_client(self):
spans = self.memory_exporter.get_finished_spans()
assert spans
span = spans[2]
self.assertEqual(span.resource, "s3.listobjects")
self.assertEqual(
span.resource,
Resource(labels={"endpoint": "s3", "operation": "listobjects"}),
)

@mock_s3
def test_s3_put(self):
Expand All @@ -97,9 +109,15 @@ def test_s3_put(self):
self.assertEqual(len(spans), 2)
self.assertEqual(span.attributes["aws.operation"], "CreateBucket")
assert_span_http_status_code(span, 200)
self.assertEqual(span.resource, "s3.createbucket")
self.assertEqual(
span.resource,
Resource(labels={"endpoint": "s3", "operation": "createbucket"}),
)
self.assertEqual(spans[1].attributes["aws.operation"], "PutObject")
self.assertEqual(spans[1].resource, "s3.putobject")
self.assertEqual(
spans[1].resource,
Resource(labels={"endpoint": "s3", "operation": "putobject"}),
)
self.assertEqual(spans[1].attributes["params.Key"], str(params["Key"]))
self.assertEqual(
spans[1].attributes["params.Bucket"], str(params["Bucket"])
Expand All @@ -119,7 +137,10 @@ def test_sqs_client(self):
self.assertEqual(span.attributes["aws.region"], "us-east-1")
self.assertEqual(span.attributes["aws.operation"], "ListQueues")
assert_span_http_status_code(span, 200)
self.assertEqual(span.resource, "sqs.listqueues")
self.assertEqual(
span.resource,
Resource(labels={"endpoint": "sqs", "operation": "listqueues"}),
)

@mock_kinesis
def test_kinesis_client(self):
Expand All @@ -136,7 +157,12 @@ def test_kinesis_client(self):
self.assertEqual(span.attributes["aws.region"], "us-east-1")
self.assertEqual(span.attributes["aws.operation"], "ListStreams")
assert_span_http_status_code(span, 200)
self.assertEqual(span.resource, "kinesis.liststreams")
self.assertEqual(
span.resource,
Resource(
labels={"endpoint": "kinesis", "operation": "liststreams"}
),
)

@mock_kinesis
def test_unpatch(self):
Expand Down Expand Up @@ -176,7 +202,12 @@ def test_lambda_client(self):
self.assertEqual(span.attributes["aws.region"], "us-east-1")
self.assertEqual(span.attributes["aws.operation"], "ListFunctions")
assert_span_http_status_code(span, 200)
self.assertEqual(span.resource, "lambda.listfunctions")
self.assertEqual(
span.resource,
Resource(
labels={"endpoint": "lambda", "operation": "listfunctions"}
),
)

@mock_kms
def test_kms_client(self):
Expand All @@ -191,7 +222,10 @@ def test_kms_client(self):
self.assertEqual(span.attributes["aws.region"], "us-east-1")
self.assertEqual(span.attributes["aws.operation"], "ListKeys")
assert_span_http_status_code(span, 200)
self.assertEqual(span.resource, "kms.listkeys")
self.assertEqual(
span.resource,
Resource(labels={"endpoint": "kms", "operation": "listkeys"}),
)

# checking for protection on sts against security leak
self.assertTrue("params" not in span.attributes.keys())
4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-datadog/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ package_dir=
packages=find_namespace:
install_requires =
ddtrace>=0.34.0
opentelemetry-api==0.11.dev0
opentelemetry-sdk==0.11.dev0
opentelemetry-api == 0.11.dev0
opentelemetry-sdk == 0.11.dev0

[options.packages.find]
where = src
Expand Down
3 changes: 3 additions & 0 deletions ext/opentelemetry-ext-mysql/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- bugfix: Fix auto-instrumentation entry point for mysql
([#858](https://github.com/open-telemetry/opentelemetry-python/pull/858))

## 0.7b1

Released 2020-05-12
Expand Down
2 changes: 1 addition & 1 deletion ext/opentelemetry-ext-mysql/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ where = src

[options.entry_points]
opentelemetry_instrumentor =
mysql = opentelemetry.ext.pymysql:MySQLInstrumentor
mysql = opentelemetry.ext.mysql:MySQLInstrumentor
2 changes: 2 additions & 0 deletions opentelemetry-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Released 2020-06-10
([#764](https://github.com/open-telemetry/opentelemetry-python/pull/764))
- Add SumObserver and UpDownSumObserver in metrics
([#789](https://github.com/open-telemetry/opentelemetry-python/pull/789))
- Log a warning when replacing the global Tracer/Meter provider
([#856](https://github.com/open-telemetry/opentelemetry-python/pull/856))

## 0.8b0

Expand Down
11 changes: 5 additions & 6 deletions opentelemetry-api/src/opentelemetry/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,18 @@ def __new__(cls) -> "Configuration":
def __getattr__(self, name: str) -> Optional[ConfigValue]:
return self._config_map.get(name)

def __setattr__(self, key: str, val: ConfigValue) -> None:
if key == "_config_map":
super().__setattr__(key, val)
def __setattr__(self, name: str, value: ConfigValue) -> None:
if name not in self._config_map.keys():
self._config_map[name] = value
else:
raise AttributeError(key)
raise AttributeError(name)

def get(self, name: str, default: _T) -> _T:
"""Use this typed method for dynamic access instead of `getattr`
:rtype: str or bool or int or float or None
"""
val = self._config_map.get(name, default)
return val
return self._config_map.get(name, default)

@classmethod
def _reset(cls) -> None:
Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-api/src/opentelemetry/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ def get_meter(
def set_meter_provider(meter_provider: MeterProvider) -> None:
"""Sets the current global :class:`~.MeterProvider` object."""
global _METER_PROVIDER # pylint: disable=global-statement

if _METER_PROVIDER is not None:
logger.warning("Overriding current MeterProvider")

_METER_PROVIDER = meter_provider


Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-api/src/opentelemetry/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ def get_tracer(
def set_tracer_provider(tracer_provider: TracerProvider) -> None:
"""Sets the current global :class:`~.TracerProvider` object."""
global _TRACER_PROVIDER # pylint: disable=global-statement

if _TRACER_PROVIDER is not None:
logger.warning("Overriding current TracerProvider")

_TRACER_PROVIDER = tracer_provider


Expand Down
Loading

0 comments on commit 61e753f

Please sign in to comment.