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

Rename IdsGenerator to IdGenerator #350

Merged
merged 7 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
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: a434be5f450fdd329bcefb41e84406a001f9534c
CORE_REPO_SHA: 62180508ead13c5c507eab704a03c2be692dc047

jobs:
build:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/nitpick-exceptions.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ anys=
opentelemetry.trace.propagation.textmap.TextMapPropagator.fields
; - AWSXRayFormat
TraceId
; - AwsXRayIdsGenerator
; - AwsXRayIdGenerator
TraceIdRatioBased
; - AwsXRayIdsGenerator
; - AwsXRayIdGenerator
; SDK
SpanProcessor
; - DatadogExportSpanProcessor
TracerProvider
; - AwsXRayIdsGenerator
; - AwsXRayIdGenerator
; Instrumentation
BaseInstrumentor
; - instrumentation.*
2 changes: 1 addition & 1 deletion docs/sdk-extension/aws/aws.rst
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions sdk-extension/opentelemetry-sdk-extension-aws/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)


Expand Down
4 changes: 2 additions & 2 deletions sdk-extension/opentelemetry-sdk-extension-aws/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,13 +59,13 @@
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
Expand All @@ -75,10 +75,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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down