Skip to content

Commit ad0c105

Browse files
committed
remove use of Optional, restore README of the package
1 parent 95f42c2 commit ad0c105

File tree

6 files changed

+54
-73
lines changed

6 files changed

+54
-73
lines changed

sdk-extension/opentelemetry-sdk-extension-aws/README.rst

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,6 @@ populate `resource` attributes by creating a `TraceProvider` using the `AwsEc2Re
7474
Refer to each detectors' docstring to determine any possible requirements for that
7575
detector.
7676

77-
78-
[WORK IN PROGRESS] Usage (AWS X-Ray Remote Sampler)
79-
---------------------------------------------------
80-
81-
82-
Use the provided AWS X-Ray Remote Sampler by setting this sampler in your instrumented application:
83-
84-
.. code-block:: python
85-
86-
from opentelemetry.sdk.extension.aws.trace.sampler import AwsXRayRemoteSampler
87-
from opentelemetry import trace
88-
from opentelemetry.sdk.resources import Resource
89-
from opentelemetry.sdk.trace import TracerProvider
90-
from opentelemetry.semconv.resource import ResourceAttributes
91-
from opentelemetry.util.types import Attributes
92-
93-
resource = Resource.create(attributes={
94-
ResourceAttributes.SERVICE_NAME: "myService",
95-
ResourceAttributes.CLOUD_PLATFORM: "aws_ec2",
96-
})
97-
xraySampler = AwsXRayRemoteSampler(resource=resource, polling_interval=300)
98-
trace.set_tracer_provider(TracerProvider(sampler=xraySampler))
99-
100-
10177
References
10278
----------
10379

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/sampler/_aws_xray_sampling_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1717
# SPDX-License-Identifier: Apache-2.0
1818

19+
from __future__ import annotations
20+
1921
import json
2022
from logging import getLogger
21-
from typing import List, Optional
23+
from typing import List
2224

2325
import requests
2426

@@ -39,7 +41,7 @@ class _AwsXRaySamplingClient:
3941
def __init__(
4042
self,
4143
endpoint: str = DEFAULT_SAMPLING_PROXY_ENDPOINT,
42-
log_level: Optional[str] = None,
44+
log_level: str | None = None,
4345
):
4446
# Override default log level
4547
if log_level is not None:

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/sampler/_sampling_rule.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,26 @@
1616
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1717
# SPDX-License-Identifier: Apache-2.0
1818

19-
from typing import Optional
20-
19+
from __future__ import annotations
2120

2221
# Disable snake_case naming style so this class can match the sampling rules response from X-Ray
2322
# pylint: disable=invalid-name
2423
class _SamplingRule:
2524
def __init__(
2625
self,
27-
Attributes: Optional["dict[str, str]"] = None,
28-
FixedRate: Optional[float] = None,
29-
HTTPMethod: Optional[str] = None,
30-
Host: Optional[str] = None,
31-
Priority: Optional[int] = None,
32-
ReservoirSize: Optional[int] = None,
33-
ResourceARN: Optional[str] = None,
34-
RuleARN: Optional[str] = None,
35-
RuleName: Optional[str] = None,
36-
ServiceName: Optional[str] = None,
37-
ServiceType: Optional[str] = None,
38-
URLPath: Optional[str] = None,
39-
Version: Optional[int] = None,
26+
Attributes: dict[str, str] | None = None,
27+
FixedRate: float | None = None,
28+
HTTPMethod: str | None = None,
29+
Host: str | None = None,
30+
Priority: int | None = None,
31+
ReservoirSize: int | None = None,
32+
ResourceARN: str | None = None,
33+
RuleARN: str | None = None,
34+
RuleName: str | None = None,
35+
ServiceName: str | None = None,
36+
ServiceType: str | None = None,
37+
URLPath: str | None = None,
38+
Version: int | None = None,
4039
):
4140
self.Attributes = Attributes if Attributes is not None else {}
4241
self.FixedRate = FixedRate if FixedRate is not None else 0.0

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/sampler/_sampling_rule_applier.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1717
# SPDX-License-Identifier: Apache-2.0
1818

19-
from typing import Optional
19+
from __future__ import annotations
2020

2121
# pylint: disable=no-name-in-module
2222
from opentelemetry.sdk.extension.aws.trace.sampler._clock import _Clock
@@ -37,8 +37,8 @@ def __init__(
3737
sampling_rule: _SamplingRule,
3838
client_id: str,
3939
clock: _Clock,
40-
statistics: Optional[_SamplingStatisticsDocument] = None,
41-
target: Optional[_SamplingTarget] = None,
40+
statistics: _SamplingStatisticsDocument | None = None,
41+
target: _SamplingTarget | None = None,
4242
):
4343
self.__client_id = client_id # pylint: disable=W0238
4444
self._clock = clock

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/sampler/_sampling_target.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1717
# SPDX-License-Identifier: Apache-2.0
1818

19+
from __future__ import annotations
20+
1921
from logging import getLogger
20-
from typing import List, Optional
22+
from typing import List
2123

2224
_logger = getLogger(__name__)
2325

@@ -27,11 +29,11 @@
2729
class _SamplingTarget:
2830
def __init__(
2931
self,
30-
FixedRate: Optional[float] = None,
31-
Interval: Optional[int] = None,
32-
ReservoirQuota: Optional[int] = None,
33-
ReservoirQuotaTTL: Optional[float] = None,
34-
RuleName: Optional[str] = None,
32+
FixedRate: float | None = None,
33+
Interval: int | None = None,
34+
ReservoirQuota: int | None = None,
35+
ReservoirQuotaTTL: float | None = None,
36+
RuleName: str | None = None,
3537
):
3638
self.FixedRate = FixedRate if FixedRate is not None else 0.0
3739
self.Interval = Interval # can be None
@@ -43,9 +45,9 @@ def __init__(
4345
class _UnprocessedStatistics:
4446
def __init__(
4547
self,
46-
ErrorCode: Optional[str] = None,
47-
Message: Optional[str] = None,
48-
RuleName: Optional[str] = None,
48+
ErrorCode: str | None = None,
49+
Message: str | None = None,
50+
RuleName: str | None = None,
4951
):
5052
self.ErrorCode = ErrorCode if ErrorCode is not None else ""
5153
self.Message = Message if ErrorCode is not None else ""
@@ -55,9 +57,9 @@ def __init__(
5557
class _SamplingTargetResponse:
5658
def __init__(
5759
self,
58-
LastRuleModification: Optional[float],
59-
SamplingTargetDocuments: Optional[List[_SamplingTarget]] = None,
60-
UnprocessedStatistics: Optional[List[_UnprocessedStatistics]] = None,
60+
LastRuleModification: float | None,
61+
SamplingTargetDocuments: List[_SamplingTarget] | None = None,
62+
UnprocessedStatistics: List[_UnprocessedStatistics] | None = None,
6163
):
6264
self.LastRuleModification: float = (
6365
LastRuleModification if LastRuleModification is not None else 0.0

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/sampler/aws_xray_remote_sampler.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1717
# SPDX-License-Identifier: Apache-2.0
1818

19+
from __future__ import annotations
20+
1921
import random
2022
from logging import getLogger
2123
from threading import Timer
22-
from typing import Optional, Sequence
24+
from typing import Sequence
2325

2426
from typing_extensions import override
2527

@@ -55,9 +57,9 @@ class _AwsXRayRemoteSampler(Sampler):
5557
def __init__(
5658
self,
5759
resource: Resource,
58-
endpoint: Optional[str] = None,
59-
polling_interval: Optional[int] = None,
60-
log_level: Optional[str] = None,
60+
endpoint: str | None = None,
61+
polling_interval: int | None = None,
62+
log_level: str | None = None,
6163
):
6264
self._root = ParentBased(
6365
_InternalAwsXRayRemoteSampler(
@@ -71,13 +73,13 @@ def __init__(
7173
@override
7274
def should_sample(
7375
self,
74-
parent_context: Optional["Context"],
76+
parent_context: Context | None,
7577
trace_id: int,
7678
name: str,
77-
kind: Optional[SpanKind] = None,
78-
attributes: Optional[Attributes] = None,
79-
links: Optional[Sequence["Link"]] = None,
80-
trace_state: Optional["TraceState"] = None,
79+
kind: SpanKind | None = None,
80+
attributes: Attributes | None = None,
81+
links: Sequence["Link"] | None = None,
82+
trace_state: TraceState | None = None,
8183
) -> "SamplingResult":
8284
return self._root.should_sample(
8385
parent_context,
@@ -114,9 +116,9 @@ class _InternalAwsXRayRemoteSampler(Sampler):
114116
def __init__(
115117
self,
116118
resource: Resource,
117-
endpoint: Optional[str] = None,
118-
polling_interval: Optional[int] = None,
119-
log_level: Optional[str] = None,
119+
endpoint: str | None = None,
120+
polling_interval: int | None = None,
121+
log_level: str | None = None,
120122
):
121123
# Override default log level
122124
if log_level is not None:
@@ -164,13 +166,13 @@ def __init__(
164166
@override
165167
def should_sample(
166168
self,
167-
parent_context: Optional["Context"],
169+
parent_context: Context | None,
168170
trace_id: int,
169171
name: str,
170-
kind: Optional[SpanKind] = None,
171-
attributes: Optional[Attributes] = None,
172-
links: Optional[Sequence["Link"]] = None,
173-
trace_state: Optional["TraceState"] = None,
172+
kind: SpanKind | None = None,
173+
attributes: Attributes | None = None,
174+
links: Sequence["Link"] | None = None,
175+
trace_state: TraceState | None = None,
174176
) -> "SamplingResult":
175177
return SamplingResult(
176178
decision=Decision.DROP,

0 commit comments

Comments
 (0)