From 1c8852f99ecfdead522de0dad35a41013fc7c2d0 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Fri, 26 Feb 2021 14:56:30 -0800 Subject: [PATCH] Rename IdsGenerator to IdGenerator (#350) --- .github/workflows/test.yml | 2 +- CHANGELOG.md | 4 ++++ docs/nitpick-exceptions.ini | 8 +++++--- docs/sdk-extension/aws/aws.rst | 2 +- .../tests/test_datadog_format.py | 12 ++++++------ .../opentelemetry-sdk-extension-aws/README.rst | 6 +++--- .../opentelemetry-sdk-extension-aws/setup.cfg | 4 ++-- .../sdk/extension/aws/trace/__init__.py | 6 +++--- ...ds_generator.py => aws_xray_id_generator.py} | 17 +++++++---------- .../test_benchmark_aws_xray_ids_generator.py | 8 ++++---- .../tests/trace/test_aws_xray_ids_generator.py | 14 +++++++------- 11 files changed, 43 insertions(+), 40 deletions(-) rename sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/{aws_xray_ids_generator.py => aws_xray_id_generator.py} (82%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f49123e9e..679d26caa1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: a434be5f450fdd329bcefb41e84406a001f9534c + CORE_REPO_SHA: dbb1f72775a424086b7a1eefbb11cfcbf31d9534 jobs: build: diff --git a/CHANGELOG.md b/CHANGELOG.md index 11e553b147..587fea3cd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ 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.18b0...HEAD) +### Changed +- Rename `IdsGenerator` to `IdGenerator` + ([#350])(https://github.com/open-telemetry/opentelemetry-python/pull/350) + ## [0.18b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.18b0) - 2021-02-16 ### Added diff --git a/docs/nitpick-exceptions.ini b/docs/nitpick-exceptions.ini index f322eb1dd2..87d90a5d9e 100644 --- a/docs/nitpick-exceptions.ini +++ b/docs/nitpick-exceptions.ini @@ -8,6 +8,8 @@ class_references= opentelemetry.trace.propagation.textmap.Getter ; - DatadogFormat ; - AWSXRayFormat + opentelemetry.sdk.trace.id_generator.IdGenerator + ; - AwsXRayIdGenerator TextMapPropagatorT ; - AwsXRayFormat.extract @@ -16,14 +18,14 @@ anys= opentelemetry.trace.propagation.textmap.TextMapPropagator.fields ; - AWSXRayFormat TraceId - ; - AwsXRayIdsGenerator + ; - AwsXRayIdGenerator TraceIdRatioBased - ; - AwsXRayIdsGenerator + ; - AwsXRayIdGenerator ; SDK SpanProcessor ; - DatadogExportSpanProcessor TracerProvider - ; - AwsXRayIdsGenerator + ; - AwsXRayIdGenerator ; Instrumentation BaseInstrumentor ; - instrumentation.* diff --git a/docs/sdk-extension/aws/aws.rst b/docs/sdk-extension/aws/aws.rst index 1306e45665..568f7f70e9 100644 --- a/docs/sdk-extension/aws/aws.rst +++ b/docs/sdk-extension/aws/aws.rst @@ -1,7 +1,7 @@ OpenTelemetry Python - AWS SDK Extension ======================================== -.. automodule:: opentelemetry.sdk.extension.aws.trace.aws_xray_ids_generator +.. automodule:: opentelemetry.sdk.extension.aws.trace.aws_xray_id_generator :members: :undoc-members: :show-inheritance: diff --git a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py index 4f5b4c07e2..3eb1667036 100644 --- a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py +++ b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py @@ -18,7 +18,7 @@ from opentelemetry import trace as trace_api from opentelemetry.exporter.datadog import constants, propagator from opentelemetry.sdk import trace -from opentelemetry.sdk.trace.ids_generator import RandomIdsGenerator +from opentelemetry.sdk.trace.id_generator import RandomIdGenerator from opentelemetry.trace import get_current_span, set_span_in_context from opentelemetry.trace.propagation.textmap import DictGetter @@ -30,12 +30,12 @@ class TestDatadogFormat(unittest.TestCase): @classmethod def setUpClass(cls): - ids_generator = RandomIdsGenerator() + id_generator = RandomIdGenerator() cls.serialized_trace_id = propagator.format_trace_id( - ids_generator.generate_trace_id() + id_generator.generate_trace_id() ) cls.serialized_parent_id = propagator.format_span_id( - ids_generator.generate_span_id() + id_generator.generate_span_id() ) cls.serialized_origin = "origin-service" @@ -108,7 +108,7 @@ def test_context_propagation(self): "child", trace_api.SpanContext( parent_span_context.trace_id, - RandomIdsGenerator().generate_span_id(), + RandomIdGenerator().generate_span_id(), is_remote=False, trace_flags=parent_span_context.trace_flags, trace_state=parent_span_context.trace_state, @@ -155,7 +155,7 @@ def test_sampling_priority_auto_reject(self): "child", trace_api.SpanContext( parent_span_context.trace_id, - RandomIdsGenerator().generate_span_id(), + RandomIdGenerator().generate_span_id(), is_remote=False, trace_flags=parent_span_context.trace_flags, trace_state=parent_span_context.trace_state, diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/README.rst b/sdk-extension/opentelemetry-sdk-extension-aws/README.rst index 42c837ae14..790f6cb1dc 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/README.rst +++ b/sdk-extension/opentelemetry-sdk-extension-aws/README.rst @@ -30,16 +30,16 @@ Install the OpenTelemetry SDK package. pip install opentelemetry-sdk -Next, use the provided `AwsXRayIdsGenerator` to initialize the `TracerProvider`. +Next, use the provided `AwsXRayIdGenerator` to initialize the `TracerProvider`. .. code-block:: python import opentelemetry.trace as trace - from opentelemetry.sdk.extension.aws.trace import AwsXRayIdsGenerator + from opentelemetry.sdk.extension.aws.trace import AwsXRayIdGenerator from opentelemetry.sdk.trace import TracerProvider trace.set_tracer_provider( - TracerProvider(ids_generator=AwsXRayIdsGenerator()) + TracerProvider(id_generator=AwsXRayIdGenerator()) ) diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/setup.cfg b/sdk-extension/opentelemetry-sdk-extension-aws/setup.cfg index c3fe600cb5..26ea9aeee3 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/setup.cfg +++ b/sdk-extension/opentelemetry-sdk-extension-aws/setup.cfg @@ -44,8 +44,8 @@ install_requires = [options.entry_points] opentelemetry_propagator = aws_xray = opentelemetry.sdk.extension.aws.trace.propagation.aws_xray_format:AwsXRayFormat -opentelemetry_ids_generator = - aws_xray = opentelemetry.sdk.extension.aws.trace.aws_xray_ids_generator:AwsXRayIdsGenerator +opentelemetry_id_generator = + aws_xray = opentelemetry.sdk.extension.aws.trace.aws_xray_id_generator:AwsXRayIdGenerator [options.extras_require] test = diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/__init__.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/__init__.py index f33a095c01..bb36ae45d5 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/__init__.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/__init__.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opentelemetry.sdk.extension.aws.trace.aws_xray_ids_generator import ( - AwsXRayIdsGenerator, +from opentelemetry.sdk.extension.aws.trace.aws_xray_id_generator import ( + AwsXRayIdGenerator, ) -__all__ = ["AwsXRayIdsGenerator"] +__all__ = ["AwsXRayIdGenerator"] diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_ids_generator.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_id_generator.py similarity index 82% rename from sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_ids_generator.py rename to sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_id_generator.py index bf908e03ff..562ec3ff55 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_ids_generator.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_id_generator.py @@ -39,16 +39,16 @@ pip install opentelemetry-sdk -Next, use the provided `AwsXRayIdsGenerator` to initialize the `TracerProvider`. +Next, use the provided `AwsXRayIdGenerator` to initialize the `TracerProvider`. .. code-block:: python import opentelemetry.trace as trace - from opentelemetry.sdk.extension.aws.trace import AwsXRayIdsGenerator + from opentelemetry.sdk.extension.aws.trace import AwsXRayIdGenerator from opentelemetry.sdk.trace import TracerProvider trace.set_tracer_provider( - TracerProvider(ids_generator=AwsXRayIdsGenerator()) + TracerProvider(id_generator=AwsXRayIdGenerator()) ) API @@ -59,13 +59,10 @@ import random import time -from opentelemetry.sdk.trace.ids_generator import ( - IdsGenerator, - RandomIdsGenerator, -) +from opentelemetry.sdk.trace.id_generator import IdGenerator, RandomIdGenerator -class AwsXRayIdsGenerator(IdsGenerator): +class AwsXRayIdGenerator(IdGenerator): """Generates tracing IDs compatible with the AWS X-Ray tracing service. In the X-Ray system, the first 32 bits of the `TraceId` are the Unix epoch time in seconds. Since spans (AWS calls them segments) with an embedded timestamp @@ -75,10 +72,10 @@ class AwsXRayIdsGenerator(IdsGenerator): See: https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids """ - random_ids_generator = RandomIdsGenerator() + random_id_generator = RandomIdGenerator() def generate_span_id(self) -> int: - return self.random_ids_generator.generate_span_id() + return self.random_id_generator.generate_span_id() @staticmethod def generate_trace_id() -> int: diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/tests/performance/benchmarks/trace/test_benchmark_aws_xray_ids_generator.py b/sdk-extension/opentelemetry-sdk-extension-aws/tests/performance/benchmarks/trace/test_benchmark_aws_xray_ids_generator.py index 3ac091facc..c518755c60 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/tests/performance/benchmarks/trace/test_benchmark_aws_xray_ids_generator.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/tests/performance/benchmarks/trace/test_benchmark_aws_xray_ids_generator.py @@ -12,14 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opentelemetry.sdk.extension.aws.trace import AwsXRayIdsGenerator +from opentelemetry.sdk.extension.aws.trace import AwsXRayIdGenerator -ids_generator = AwsXRayIdsGenerator() +id_generator = AwsXRayIdGenerator() def test_generate_xray_trace_id(benchmark): - benchmark(ids_generator.generate_trace_id) + benchmark(id_generator.generate_trace_id) def test_generate_xray_span_id(benchmark): - benchmark(ids_generator.generate_span_id) + benchmark(id_generator.generate_span_id) diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/test_aws_xray_ids_generator.py b/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/test_aws_xray_ids_generator.py index d914a5f241..ed78c8f0e7 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/test_aws_xray_ids_generator.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/test_aws_xray_ids_generator.py @@ -16,23 +16,23 @@ import time import unittest -from opentelemetry.sdk.extension.aws.trace import AwsXRayIdsGenerator +from opentelemetry.sdk.extension.aws.trace import AwsXRayIdGenerator from opentelemetry.trace.span import INVALID_TRACE_ID -class AwsXRayIdsGeneratorTest(unittest.TestCase): +class AwsXRayIdGeneratorTest(unittest.TestCase): def test_ids_are_valid(self): - ids_generator = AwsXRayIdsGenerator() + id_generator = AwsXRayIdGenerator() for _ in range(1000): - trace_id = ids_generator.generate_trace_id() + trace_id = id_generator.generate_trace_id() self.assertTrue(trace_id != INVALID_TRACE_ID) - span_id = ids_generator.generate_span_id() + span_id = id_generator.generate_span_id() self.assertTrue(span_id != INVALID_TRACE_ID) def test_id_timestamps_are_acceptable_for_xray(self): - ids_generator = AwsXRayIdsGenerator() + id_generator = AwsXRayIdGenerator() for _ in range(1000): - trace_id = ids_generator.generate_trace_id() + trace_id = id_generator.generate_trace_id() trace_id_time = trace_id >> 96 current_time = int(time.time()) self.assertLessEqual(trace_id_time, current_time)